Skip to content

Commit 9124f1f

Browse files
committed
fix: align identifiers to query.c parser logic
Namely, they cannot have `$`, but they can contain `?` or `!` https://github.com/tree-sitter/tree-sitter/blob/4339b0fe05b264082bd159a77b21fc5d586c3a29/lib/src/query.c#L403C1-L418C2
1 parent 8bf3112 commit 9124f1f

File tree

5 files changed

+1653
-3692
lines changed

5 files changed

+1653
-3692
lines changed

grammar.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ const PREC = {
1010
WILDCARD_NODE: 1,
1111
};
1212

13-
// Identifiers cannot start with `.`
14-
const IDENTIFIER = /[a-zA-Z0-9\-_\$][a-zA-Z0-9.\-_\$]*/;
13+
// Identifiers cannot start with `.`, `?`, or `!`
14+
const IDENTIFIER = /[a-zA-Z0-9\-_][a-zA-Z0-9.\-_?!]*/;
1515

1616
module.exports = grammar({
1717
name: "query",
@@ -25,6 +25,13 @@ module.exports = grammar({
2525
$.definition,
2626
],
2727

28+
externals: $ => [
29+
// A regular identifier which will NOT consume the final `?` or `!` that it
30+
// sees, in order to capture it as a separate (predicate_type) node
31+
$._predicate_name,
32+
$._error_sentinel,
33+
],
34+
2835
rules: {
2936
program: $ => repeat($.definition),
3037

@@ -126,7 +133,7 @@ module.exports = grammar({
126133
predicate: $ =>
127134
seq(
128135
"(",
129-
field("name", seq(choice("#", "."), $._immediate_identifier, field("type", $.predicate_type))),
136+
field("name", seq(choice("#", "."), alias($._predicate_name, $.identifier), field("type", $.predicate_type))),
130137
field("parameters", $.parameters),
131138
")"
132139
),

src/grammar.json

Lines changed: 19 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)