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))
(const_item
(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!('\u{0}'..='\u{2}');
a!('lifetime)
default!(a);
union!(a);
----
@ -50,6 +52,12 @@ a!('lifetime)
(macro_invocation
(identifier)
(token_tree (char_literal) (char_literal)))
(macro_invocation
(identifier)
(token_tree (identifier)))
(macro_invocation
(identifier)
(token_tree (identifier)))
(macro_invocation
(identifier)
(token_tree (identifier))))

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

21
src/grammar.json vendored

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

174713
src/parser.c vendored

File diff suppressed because it is too large Load Diff