File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -259,17 +259,46 @@ same broad range to every synthetic descendant. A transform that simply
259259returns a translated capture does not widen that capture to the wrapper's
260260range.
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
275304For input fields whose leading or trailing syntax should never belong to rule
You can’t perform that action at this time.
0 commit comments