File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -566,6 +566,36 @@ between the words.
566566This assumes you are already familiar with the [ Tree-sitter query
567567language] [ tree-sitter-query ] .
568568
569+ ### A note on anchors
570+ The behaviour of "anchors" can be counterintuitive. Consider, for instance, the
571+ following query:
572+ ``` scheme
573+ (
574+ (list_entry) @append_space
575+ .
576+ )
577+ ```
578+ One might assume that this query only matches the final element in the list but
579+ this is not true. Since we did not explicitly march a parent node, the engine
580+ will match on every ` list_entry ` . After all, the when looking only at the nodes
581+ in the query, the ` list_entry ` is indeed the last node.
582+
583+ To resolve this issue, match explicitly on the parent node:
584+ ``` scheme
585+ (list
586+ (list_entry) @append_space
587+ .
588+ )
589+ ```
590+
591+ Or even implicitly:
592+ ``` scheme
593+ (_
594+ (list_entry) @append_space
595+ .
596+ )
597+ ```
598+
569599Note that a capture is put after the node it is associated with. If you
570600want to put a space in front of a node, you do it like this:
571601
You can’t perform that action at this time.
0 commit comments