Skip to content

Commit

Permalink
Document leaf on empty types in README
Browse files Browse the repository at this point in the history
  • Loading branch information
shadaj committed Nov 5, 2023
1 parent c5c78ef commit aaaa0da
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,20 @@ The `#[rust_sitter::leaf(...)]` annotation can be used to define a leaf node in
- the `text` parameter takes a string that is used to match the text of the leaf node. This parameter is mutually exclusive with `pattern`.
- the `transform` parameter takes a function that is used to transform the matched text (an `&str`) into the desired type. This parameter is optional if the target type is `()`.

`leaf` can either be applied to a field in a struct / enum variant (as seen above), or directly on a type with no fields:

```rust
#[rust_sitter::leaf(text = "9")]
struct BigDigit;

enum SmallDigit {
#[rust_sitter::leaf(text = "0")]
Zero,
#[rust_sitter::leaf(text = "1")]
One,
}
```

### `#[rust_sitter::prec(...)]` / `#[rust_sitter::prec_left(...)]` / `#[rust_sitter::prec_right(...)]`
This annotation can be used to define a non/left/right-associative operator. This annotation takes a single parameter, which is the precedence level of the operator (higher binds more tightly).

Expand Down

0 comments on commit aaaa0da

Please sign in to comment.