-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove
...
ellipsis from query syntax and add explicit adjacency op…
…erator (#1030) This PR changes the CST query syntax by: - Removing the `...` ellipsis operator and adding it implicitly at the edges and between elements in a matching sequence. So that `[Foo [A] [B]]` is equivalent to `[Foo ... [A] ... [B] ...]`. - Adding the `.` adjacency (anchor) operator to explicitly indicate that a matched node should be the first (eg. `[Foo . [A]]`) or last child (eg. `[Foo [A] .]`), or that two matched nodes should be consecutive (eg. `[Foo [A] . [B]]`). The adjacency operator is allowed in sub-sequences of alternative options or quantified sequences, but not at the beginning or end of the pattern, where the adjacency is implicit. So: `[Foo ([Bar] | [X] . [Y])]` is allowed, but `[Foo ([Bar] | . [X])]` is not. - Trivia kinds cannot be used in node matchers. The PR also introduces some semantic changes to query execution: - Trivia nodes are skipped over when executing a query and they cannot be matched against. - Only the first implicit ellipsis operator is allowed to match multiple nodes in a sequence of siblings, unless there is an explicit node match in between. This prevents the engine from returning duplicate results when two ellipsis operators are effectively adjacent (for example when they are separated by an optional matcher). For example, given a sequence such as `ABCD`, the query `[_] ["B"]? [_]` will operationally be equivalent to `[_] ... ["B"]? ... [_]`. With the previous semantics, this would have returned 4 results, matching: 1. zero nodes for the first ellipsis, the optional matches the `B` and the second ellipsis takes the `C` 2. zero nodes for the first ellipsis, zero nodes for the optional, and the second ellipsis takes both `BC` 3. first ellipsis takes `B`, optional matches nothing, and second ellipsis takes `C` 4. first ellipsis takes both `BC`, and optional and second ellipsis take no nodes After this PR, only two results are possible, corresponding to the cases i. and iv. above, since the second ellipsis is allowed to match nodes _only_ if the optional succeeds in matching at least some node. The two returned results are distinct though, because the user may want to capture the optional with the query `[_] @x ["B"]? [_]`. By unification semantics the optional can match zero or one nodes, which is consistent with the results obtained without capturing. --------- Co-authored-by: Omar Tawfik <[email protected]>
- Loading branch information
1 parent
fa38d83
commit 7e467ce
Showing
19 changed files
with
1,127 additions
and
500 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@nomicfoundation/slang": minor | ||
--- | ||
|
||
Tree Query Language: queries now ignore trivia nodes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@nomicfoundation/slang": minor | ||
--- | ||
|
||
Tree Query Language: remove the ellipsis query `...` operator making it implicit, add an adjacency operator `.`. |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.