Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stephenwakely/clformat
Rust format macro inspired by common lisp
https://github.com/stephenwakely/clformat
Last synced: about 2 months ago
JSON representation
Rust format macro inspired by common lisp
- Host: GitHub
- URL: https://github.com/stephenwakely/clformat
- Owner: StephenWakely
- Created: 2023-10-05T17:12:39.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-04-07T16:56:37.000Z (10 months ago)
- Last Synced: 2024-04-12T16:07:59.592Z (10 months ago)
- Language: Rust
- Size: 47.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
At attempt to recreate the Common Lisp [Format function][hyperspec] in a Rust macro.
# Supported directives
| Directive | Description | Supported |
|-----------|------------------------------------------------------------------------------------------------------|---------------|
| `~A` | Prints an argument in a human-readable form. Prints `Display`. | Yes |
| `~S` | Prints an argument in a machine-readable form. Quotes strings. | Yes |
| `~%` | Inserts a newline character. | Yes |
| `~&` | Performs a "fresh-line" operation, moving to a new line if not already at the beginning of one. | No |
| `~~` | Prints a tilde (`~`). | No |
| `~D` | Prints an integer in decimal format. | Yes |
| `~X` | Prints an integer in hexadecimal format. | No |
| `~O` | Prints an integer in octal format. | No |
| `~B` | Prints an integer in binary format. | No |
| `~F` | Prints a floating-point number in fixed-format. | Partial |
| `~E` | Prints a floating-point number in exponential format. | No |
| `~G` | Prints a floating-point number in either fixed-format or exponential format, depending on its value. | No |
| `~C` | Prints a character. | No |
| `~P` | Prints "s" if its argument is plural (i.e., not equal to 1); otherwise, prints nothing. | No |
| `~R` | Prints an integer in English words or as per other specified radix. | No |
| `~T` | Inserts horizontal tabulation (space padding) to align output. | No |
| `~<...~>` | Justifies the enclosed text according to specified parameters. | Yes |
| `~[...~]` | Conditional expression with multiple clauses for case selection. | No |
| `~{...~}` | Iterates over a list, applying formatting directives to each element. | Yes |
| `~^` | Exits the closest enclosing iteration or conditional expression if no more arguments are available. | Yes |
| `~*` | Consumes an argument without printing it. Useful for skipping arguments. | Yes |
| `~I` | Indents to a specified column, potentially creating new lines if required. | No |
| `~_` | Conditional newline: inserts a newline character if not at the beginning of a line. | No |
| `~W` | Prints an argument using "write" semantics, similar to `~S` but with more control over the output. | No |
| `~M` | Prints an integer in Roman numerals. | No |
| `~N` | Alias for `~%`, inserting a newline. Similar in use to `~%` but rare. | No |
| `~;` | Separates clauses in conditional expressions (`~[...~]`). | No |
| `~?` | Embeds a recursive format operation, allowing a nested format string and arguments. | No |[hyperspec]: https://www.lispworks.com/documentation/HyperSpec/Body/22_c.htm