Skip to content

Commit fdc7026

Browse files
committed
yeast: Update documentation
1 parent 865fc07 commit fdc7026

2 files changed

Lines changed: 38 additions & 3 deletions

File tree

‎shared/yeast-macros/src/lib.rs‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mod parse;
77
mod rule_parse;
88
mod template_parse;
99

10-
/// Proc macro for constructing a tree-sitter-inspired query `Pattern`.
10+
/// Proc macro for constructing a tree-sitter-inspired `yeast::query::QueryNode`.
1111
///
1212
/// # Syntax
1313
///
@@ -23,11 +23,23 @@ mod template_parse;
2323
/// (pattern) @capture - capture the matched node
2424
/// "literal" @capture - capture an unnamed token
2525
/// _ @capture - capture any node
26-
/// (pattern)* @capture - capture each repeated match
27-
/// (pattern)? - zero or one
26+
/// (kind)* @capture - capture each repeated named-node match
27+
/// "literal"* @capture - capture each repeated unnamed-token match
28+
/// (kind)? - zero or one named node
2829
/// ```
2930
///
3031
/// Named fields and bare child patterns may be intermixed in any order.
32+
///
33+
/// Parentheses do not provide general-purpose grouping. A parenthesized query
34+
/// group contains at least two sibling patterns and may be repeated, but the
35+
/// group itself cannot be captured because it does not represent one node:
36+
///
37+
/// ```text
38+
/// ((identifier) @items (integer) @items)* // valid: explicit node captures
39+
/// ((identifier) (integer))* @items // invalid: sequence capture
40+
/// ("+")* // invalid: redundant grouping
41+
/// "+"* // valid: repeated unnamed token
42+
/// ```
3143
#[proc_macro]
3244
pub fn query(input: TokenStream) -> TokenStream {
3345
let input2: TokenStream2 = input.into();

‎shared/yeast/doc/yeast.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,31 @@ queries, are not supported.
152152
(_)+ // one or more
153153
(_)? // zero or one
154154
(identifier)* @names // capture each repeated match
155+
"+"* @operators // repeat and capture an unnamed token
155156
```
156157

158+
Parentheses are not general-purpose grouping syntax. A parenthesized query
159+
group represents a sequence of at least two sibling patterns. It may be
160+
repeated, but it cannot itself be captured because the sequence does not
161+
correspond to one AST node:
162+
163+
```rust
164+
((identifier) @items (integer) @items)* // explicit flattened captures
165+
((identifier) (integer))* @items // error: sequence capture
166+
```
167+
168+
Use the bare literal form when quantifying an unnamed token. The parenthesized
169+
form is valid as a standalone token pattern, but not as a redundant
170+
single-pattern group:
171+
172+
```rust
173+
"+"* // valid
174+
("+")* // error: remove the redundant parentheses
175+
```
176+
177+
Empty query groups are also rejected. This does not affect the empty output
178+
template `()`, which intentionally means “emit no replacement nodes.”
179+
157180
## Template language
158181

159182
Templates construct new AST nodes using the `tree!` and `trees!` macros.

0 commit comments

Comments
 (0)