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!
ida_star
calixteman 2021-03-27 17:50:22 +07:00 committed by GitHub
parent a3e6768b67
commit a360da0a29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 88177 additions and 86596 deletions

@ -1384,3 +1384,21 @@ crate const X: u32 = 0;
(visibility_modifier (crate)) (identifier) (parameters) (block)) (visibility_modifier (crate)) (identifier) (parameters) (block))
(const_item (const_item
(visibility_modifier (crate)) (identifier) (primitive_type) (integer_literal))) (visibility_modifier (crate)) (identifier) (primitive_type) (integer_literal)))
===================================
Reserved keywords in path
===================================
struct A {
a: default::B,
b: union::C,
}
---
(source_file
(struct_item
(type_identifier)
(field_declaration_list
(field_declaration (field_identifier) (scoped_type_identifier (identifier) (type_identifier)))
(field_declaration (field_identifier) (scoped_type_identifier (identifier) (type_identifier))))))

@ -28,6 +28,8 @@ a!(b + c + +);
a!('a'..='z'); a!('a'..='z');
a!('\u{0}'..='\u{2}'); a!('\u{0}'..='\u{2}');
a!('lifetime) a!('lifetime)
default!(a);
union!(a);
---- ----
@ -50,6 +52,12 @@ a!('lifetime)
(macro_invocation (macro_invocation
(identifier) (identifier)
(token_tree (char_literal) (char_literal))) (token_tree (char_literal) (char_literal)))
(macro_invocation
(identifier)
(token_tree (identifier)))
(macro_invocation
(identifier)
(token_tree (identifier)))
(macro_invocation (macro_invocation
(identifier) (identifier)
(token_tree (identifier)))) (token_tree (identifier))))

@ -129,7 +129,10 @@ module.exports = grammar({
return seq( return seq(
'macro_rules!', 'macro_rules!',
field('name', $.identifier), field('name', choice(
$.identifier,
$._reserved_identifier,
)),
choice( choice(
seq('(', rules, ')', ';'), seq('(', rules, ')', ';'),
seq('{', rules, '}') seq('{', rules, '}')
@ -877,7 +880,8 @@ module.exports = grammar({
macro_invocation: $ => seq( macro_invocation: $ => seq(
field('macro', choice( field('macro', choice(
$.scoped_identifier, $.scoped_identifier,
$.identifier $.identifier,
$._reserved_identifier,
)), )),
'!', '!',
$.token_tree $.token_tree
@ -1429,7 +1433,8 @@ module.exports = grammar({
$.super, $.super,
$.crate, $.crate,
$.identifier, $.identifier,
$.scoped_identifier $.scoped_identifier,
$._reserved_identifier,
), ),
identifier: $ => /(r#)?[_\p{XID_Start}][_\p{XID_Continue}]*/, identifier: $ => /(r#)?[_\p{XID_Start}][_\p{XID_Continue}]*/,
@ -1445,7 +1450,7 @@ module.exports = grammar({
self: $ => 'self', self: $ => 'self',
super: $ => 'super', super: $ => 'super',
crate: $ => 'crate', crate: $ => 'crate',
metavariable: $ => /\$[a-zA-Z_]\w*/ metavariable: $ => /\$[a-zA-Z_]\w*/
} }
}) })

21
src/grammar.json vendored

@ -152,8 +152,17 @@
"type": "FIELD", "type": "FIELD",
"name": "name", "name": "name",
"content": { "content": {
"type": "SYMBOL", "type": "CHOICE",
"name": "identifier" "members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "_reserved_identifier"
}
]
} }
}, },
{ {
@ -4852,6 +4861,10 @@
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "identifier" "name": "identifier"
},
{
"type": "SYMBOL",
"name": "_reserved_identifier"
} }
] ]
} }
@ -8213,6 +8226,10 @@
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "scoped_identifier" "name": "scoped_identifier"
},
{
"type": "SYMBOL",
"name": "_reserved_identifier"
} }
] ]
}, },

174713
src/parser.c vendored

File diff suppressed because it is too large Load Diff