Skip to content

Commit b3621f5

Browse files
committed
feat: predicates can begin with "."
This commit restricts identifiers to not start with "." and also allows predicates to be denoted with "." as well as "#", as specified by `query.c`. See https://github.com/tree-sitter/tree-sitter/blob/9c8055765849eee39f69a8eda7d2a5aede2b2e60/lib/src/query.c#L2308 and https://github.com/emacs-tree-sitter/tree-sitter-langs/blob/b955ffbe26b3a7e931f116720efa7dee9de35174/queries/hcl/highlights.terraform-mode.scm#L13
1 parent a6674e2 commit b3621f5

File tree

5 files changed

+3108
-5412
lines changed

5 files changed

+3108
-5412
lines changed

grammar.js

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

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

1516
module.exports = grammar({
1617
name: "query",
@@ -124,7 +125,7 @@ module.exports = grammar({
124125
predicate: $ =>
125126
seq(
126127
"(",
127-
field("name", seq("#", $._immediate_identifier, field("type", $.predicate_type))),
128+
field("name", seq(choice("#", "."), $._immediate_identifier, field("type", $.predicate_type))),
128129
field("parameters", $.parameters),
129130
")"
130131
),

src/grammar.json

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

src/node-types.json

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

0 commit comments

Comments
 (0)