Skip to content

Commit 152bf4b

Browse files
tausbnCopilot
andcommitted
yeast: Clarify explicit location documentation
Explain how explicit location macros affect template roots and provide complete rule examples for tree_at! and tree_spanning!. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 9f59b2c commit 152bf4b

1 file changed

Lines changed: 34 additions & 5 deletions

File tree

‎shared/yeast/doc/yeast.md‎

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,17 +259,46 @@ same broad range to every synthetic descendant. A transform that simply
259259
returns a translated capture does not widen that capture to the wrapper's
260260
range.
261261

262-
When the desired range belongs to another node, `tree_at!` assigns that range
263-
to the template's root. Nested nodes still derive their own locations normally:
262+
The following macros can be used to explicitly set the location associated
263+
with a newly-created node. They assign a location only to the root of their
264+
template; nested nodes still derive their locations normally.
265+
266+
`tree_at!` assigns the range of one captured input node to the template root:
264267

265268
```rust
266-
let synthetic = tree_at!(ctx, source, (synthetic_node child: (nested value: {child})));
269+
rule!(
270+
(wrapper
271+
source: (_) @source_node
272+
child: (_) @child)
273+
=>
274+
synthetic_node {
275+
tree_at!(
276+
ctx,
277+
source_node,
278+
(synthetic_node child: (nested value: {child}))
279+
)
280+
}
281+
)
267282
```
268283

269-
`tree_spanning!` similarly assigns the union of several node ranges:
284+
`tree_spanning!` assigns the smallest range containing several captured input
285+
nodes:
270286

271287
```rust
272-
let synthetic = tree_spanning!(ctx, nodes, (synthetic_node child: {child}));
288+
rule!(
289+
(wrapper
290+
first: (_) @first
291+
second: (_) @second
292+
child: (_) @child)
293+
=>
294+
synthetic_node {
295+
tree_spanning!(
296+
ctx,
297+
[first, second],
298+
(synthetic_node child: {child})
299+
)
300+
}
301+
)
273302
```
274303

275304
For input fields whose leading or trailing syntax should never belong to rule

0 commit comments

Comments
 (0)