Skip to content

Commit ae4bf74

Browse files
committed
Promote metavariable out of _non_special_token
Allows deduplicating _common_token and _non_special_token
1 parent 3ad0430 commit ae4bf74

File tree

3 files changed

+24473
-24545
lines changed

3 files changed

+24473
-24545
lines changed

grammar.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ module.exports = grammar({
150150
$.token_tree_pattern,
151151
$.token_repetition_pattern,
152152
$.token_binding_pattern,
153+
$.metavariable,
153154
$._non_special_token
154155
),
155156

@@ -177,6 +178,7 @@ module.exports = grammar({
177178
_tokens: $ => choice(
178179
$.token_tree,
179180
$.token_repetition,
181+
$.metavariable,
180182
$._non_special_token
181183
),
182184

@@ -190,12 +192,10 @@ module.exports = grammar({
190192
'$', '(', repeat($._tokens), ')', optional(/[^+*?]+/), choice('+', '*', '?')
191193
),
192194

195+
// Matches non-delimiter tokens common to both macro invocations and
196+
// definitions. This is everything except $ and metavariables (which begin
197+
// with $).
193198
_non_special_token: $ => choice(
194-
$._never_special_token,
195-
$.metavariable
196-
),
197-
198-
_never_special_token: $ => choice(
199199
$._literal, $.identifier, $.mutable_specifier, $.self, $.super, $.crate,
200200
alias(choice(...primitive_types), $.primitive_type),
201201
/[/_\-=->,;:::!=?.@*&#%^+<>|~]+/,
@@ -910,8 +910,9 @@ module.exports = grammar({
910910
alias($.delim_token_tree, $.token_tree),
911911
),
912912

913+
// Should match any token other than a delimiter.
913914
_non_delim_token: $ => choice(
914-
$._never_special_token,
915+
$._non_special_token,
915916
'$'
916917
),
917918

src/grammar.json

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@
308308
"type": "SYMBOL",
309309
"name": "token_binding_pattern"
310310
},
311+
{
312+
"type": "SYMBOL",
313+
"name": "metavariable"
314+
},
311315
{
312316
"type": "SYMBOL",
313317
"name": "_non_special_token"
@@ -529,6 +533,10 @@
529533
"type": "SYMBOL",
530534
"name": "token_repetition"
531535
},
536+
{
537+
"type": "SYMBOL",
538+
"name": "metavariable"
539+
},
532540
{
533541
"type": "SYMBOL",
534542
"name": "_non_special_token"
@@ -654,19 +662,6 @@
654662
]
655663
},
656664
"_non_special_token": {
657-
"type": "CHOICE",
658-
"members": [
659-
{
660-
"type": "SYMBOL",
661-
"name": "_never_special_token"
662-
},
663-
{
664-
"type": "SYMBOL",
665-
"name": "metavariable"
666-
}
667-
]
668-
},
669-
"_never_special_token": {
670665
"type": "CHOICE",
671666
"members": [
672667
{
@@ -5035,7 +5030,7 @@
50355030
"members": [
50365031
{
50375032
"type": "SYMBOL",
5038-
"name": "_never_special_token"
5033+
"name": "_non_special_token"
50395034
},
50405035
{
50415036
"type": "STRING",

0 commit comments

Comments
 (0)