Skip to content

Commit a360da0

Browse files
authored
Allow 'default' and 'union' in paths (#77)
* Allow 'default' and 'union' in paths * And allow them as macro identifiers * Add a test for macros default! and union!
1 parent a3e6768 commit a360da0

File tree

5 files changed

+88177
-86596
lines changed

5 files changed

+88177
-86596
lines changed

corpus/declarations.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,3 +1384,21 @@ crate const X: u32 = 0;
13841384
(visibility_modifier (crate)) (identifier) (parameters) (block))
13851385
(const_item
13861386
(visibility_modifier (crate)) (identifier) (primitive_type) (integer_literal)))
1387+
1388+
===================================
1389+
Reserved keywords in path
1390+
===================================
1391+
1392+
struct A {
1393+
a: default::B,
1394+
b: union::C,
1395+
}
1396+
1397+
---
1398+
1399+
(source_file
1400+
(struct_item
1401+
(type_identifier)
1402+
(field_declaration_list
1403+
(field_declaration (field_identifier) (scoped_type_identifier (identifier) (type_identifier)))
1404+
(field_declaration (field_identifier) (scoped_type_identifier (identifier) (type_identifier))))))

corpus/macros.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ a!(b + c + +);
2828
a!('a'..='z');
2929
a!('\u{0}'..='\u{2}');
3030
a!('lifetime)
31+
default!(a);
32+
union!(a);
3133

3234
----
3335

@@ -50,6 +52,12 @@ a!('lifetime)
5052
(macro_invocation
5153
(identifier)
5254
(token_tree (char_literal) (char_literal)))
55+
(macro_invocation
56+
(identifier)
57+
(token_tree (identifier)))
58+
(macro_invocation
59+
(identifier)
60+
(token_tree (identifier)))
5361
(macro_invocation
5462
(identifier)
5563
(token_tree (identifier))))

grammar.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,10 @@ module.exports = grammar({
129129

130130
return seq(
131131
'macro_rules!',
132-
field('name', $.identifier),
132+
field('name', choice(
133+
$.identifier,
134+
$._reserved_identifier,
135+
)),
133136
choice(
134137
seq('(', rules, ')', ';'),
135138
seq('{', rules, '}')
@@ -877,7 +880,8 @@ module.exports = grammar({
877880
macro_invocation: $ => seq(
878881
field('macro', choice(
879882
$.scoped_identifier,
880-
$.identifier
883+
$.identifier,
884+
$._reserved_identifier,
881885
)),
882886
'!',
883887
$.token_tree
@@ -1429,7 +1433,8 @@ module.exports = grammar({
14291433
$.super,
14301434
$.crate,
14311435
$.identifier,
1432-
$.scoped_identifier
1436+
$.scoped_identifier,
1437+
$._reserved_identifier,
14331438
),
14341439

14351440
identifier: $ => /(r#)?[_\p{XID_Start}][_\p{XID_Continue}]*/,
@@ -1445,7 +1450,7 @@ module.exports = grammar({
14451450
self: $ => 'self',
14461451
super: $ => 'super',
14471452
crate: $ => 'crate',
1448-
1453+
14491454
metavariable: $ => /\$[a-zA-Z_]\w*/
14501455
}
14511456
})

src/grammar.json

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,17 @@
152152
"type": "FIELD",
153153
"name": "name",
154154
"content": {
155-
"type": "SYMBOL",
156-
"name": "identifier"
155+
"type": "CHOICE",
156+
"members": [
157+
{
158+
"type": "SYMBOL",
159+
"name": "identifier"
160+
},
161+
{
162+
"type": "SYMBOL",
163+
"name": "_reserved_identifier"
164+
}
165+
]
157166
}
158167
},
159168
{
@@ -4852,6 +4861,10 @@
48524861
{
48534862
"type": "SYMBOL",
48544863
"name": "identifier"
4864+
},
4865+
{
4866+
"type": "SYMBOL",
4867+
"name": "_reserved_identifier"
48554868
}
48564869
]
48574870
}
@@ -8213,6 +8226,10 @@
82138226
{
82148227
"type": "SYMBOL",
82158228
"name": "scoped_identifier"
8229+
},
8230+
{
8231+
"type": "SYMBOL",
8232+
"name": "_reserved_identifier"
82168233
}
82178234
]
82188235
},

0 commit comments

Comments
 (0)