Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,38 @@ Options:

## Configuration

`c3fmt` will try to find a `.c3fmt` format inside the working directory. You can also
pass your own path to `c3fmt`, or force the default configuration.
`c3fmt` will try to find a `.c3fmt` configuration file inside the working directory. You can also pass your own path to `c3fmt` using the `--config` flag, or force the default configuration with `--default`.

You can look at [.c3fmt](.c3fmt) for the default configuration.

### Available Options

| Key | Description | Default |
| --- | --- | --- |
| `use_tabs` | Use tabs for indentation. | `true` |
| `tab_size` | The width of a tab character. | `4` |
| `indent_width` | The number of spaces to use for indentation (if `use_tabs` is false). | `4` |
| `max_blank_line_between_statements` | Maximum number of blank lines to preserve between statements. | `2` |
| `max_line_length` | Maximum line length before wrapping. | `120` |
| `brace_style` | The brace style to use: `ALLMAN` or `K&R`. | `ALLMAN` |
| `else_on_newline` | Whether to put `else` on a new line. | `true` |
| `align_assignments` | Align `=` and `=>` in consecutive declarations/assignments. | `true` |
| `align_comments` | Align trailing comments in consecutive lines. | `true` |
## Building

Building requires the [C3 compiler](https://c3-lang.org/) and the [tree-sitter](https://github.com/tree-sitter/tree-sitter) SDK library.
Building requires the [C3 compiler](https://c3-lang.org/) and the [tree-sitter](https://github.com/tree-sitter/tree-sitter) SDK library. For instructions on how to build and install the tree-sitter library, refer to the [tree-sitter getting started guide](https://tree-sitter.github.io/tree-sitter/using-parsers/1-getting-started.html).

To build the executable:
```bash
c3c build
```

If the `tree-sitter` library is not in your system's default search path, you can specify the path using the `-L` flag:

```bash
c3c build -L /path/to/tree-sitter/lib
```

The binary will be located in `build/c3fmt`.

### Updating Sources
Expand All @@ -66,6 +86,11 @@ Run all tests using the C3 compiler:
c3c test
```

Just like with the build command, if `tree-sitter` is not in your search path, use the `-L` flag:
```bash
c3c test -L /path/to/tree-sitter/lib
```

The test suite includes:
- **Corpus**: Compares formatted output against expected `_f.c3` files.
- **Stability**: Ensures that formatting already-formatted code produces no changes (idempotency).
Expand Down
Binary file modified lib/tree_sitter_c3.c3l
Binary file not shown.
6 changes: 5 additions & 1 deletion scripts/update_tree_sitter_c3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

set -euo pipefail

REF="${1:-main}"
REF="${1:-c3-0.8}"
REPO="https://github.com/c3lang/tree-sitter-c3"

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
Expand Down Expand Up @@ -82,4 +82,8 @@ echo "Packing .c3l ..."

# install
cp "$STAGING/c3l/tree_sitter_c3.c3l" "$LIB_DIR/tree_sitter_c3.c3l"

echo "Clearing compiler caches to ensure library reload ..."
rm -rf "$SCRIPT_DIR/../build" "$HOME/.c3"

echo "Done. lib/tree_sitter_c3.c3l updated from $REPO @ $REF"
1 change: 1 addition & 0 deletions src/config.c3
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ fn Config? parse_from_file(String file_path) => @pool()
else if (val == "K&R")
{
conf.brace_style = K_AND_R;
conf.else_on_newline = false;
}
else
{
Expand Down
Loading
Loading