Skip to content

Commit

Permalink
Update documentation and changeset
Browse files Browse the repository at this point in the history
  • Loading branch information
ggiraldez committed Jul 24, 2024
1 parent ab1951b commit 13648d7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .changeset/gentle-shirts-deliver.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"@nomicfoundation/slang": minor
---

Remove the ellipsis query operator making it implicit, and add an anchor operator
Remove the ellipsis query operator making it implicit, add an adjacency operator and make queries ignore trivia nodes.
18 changes: 10 additions & 8 deletions documentation/public/user-guide/tree-query-language.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ is associated with each of the `StringExpression` children:
--8<-- "crates/solidity/outputs/cargo/tests/src/doc_examples/tree_query_language.rs:query-syntax-5"
```

Trivia nodes (whitespace, comments, etc.) will be skipped over when running a
query. Furthermore, trivia nodes cannot be explicitly (or implicitly with `_`)
matched by queries.

### Capturing Nodes

When matching patterns, you may want to process specific nodes within the
Expand Down Expand Up @@ -108,10 +112,10 @@ This pattern would match a set of possible keyword terminals, capturing them as
--8<-- "crates/solidity/outputs/cargo/tests/src/doc_examples/tree_query_language.rs:alternations-2"
```

### Anchoring
### Adjacency

By using anchors `.`, you can constrain a pattern to only match the first or the
last child nodes.
By using the adjacency operator `.` you can constrain a pattern to only match
the first or the last child nodes.

For example, the following pattern would match only the first parameter
declaration in a function definition:
Expand All @@ -126,12 +130,10 @@ And conversely the following will match only the last parameter:
--8<-- "crates/solidity/outputs/cargo/tests/src/doc_examples/tree_query_language.rs:anchoring-2"
```

If the anchor is used in between two patterns it constrains matches on both
patterns to occur consecutively, ie. without any other sibling node in between.
For example, this pattern matches pairs of consecutive statements:
If the adjacency operator is used in between two patterns it constrains matches
on both patterns to occur consecutively, ie. without any other sibling node in
between. For example, this pattern matches pairs of consecutive statements:

```{ .scheme }
--8<-- "crates/solidity/outputs/cargo/tests/src/doc_examples/tree_query_language.rs:anchoring-3"
```

Anchors will skip over trivia nodes.

0 comments on commit 13648d7

Please sign in to comment.