Fix handling of token rules directly inside of alias, prec, or field.

Fixes #483
This commit is contained in:
Max Brunsfeld 2019-11-14 13:34:21 -08:00
parent b4a2f4ed60
commit 660efd8c0f
4 changed files with 72 additions and 1 deletions

View file

@ -366,7 +366,7 @@ impl FromIterator<Symbol> for TokenSet {
fn add_metadata<T: FnOnce(&mut MetadataParams)>(input: Rule, f: T) -> Rule {
match input {
Rule::Metadata { rule, mut params } => {
Rule::Metadata { rule, mut params } if !params.is_token => {
f(&mut params);
Rule::Metadata { rule, params }
}

View file

@ -0,0 +1,9 @@
======================
Aliased token rules
======================
abcde
---
(expression (X) (Y))

View file

@ -0,0 +1,61 @@
{
"name": "aliased_token_rules",
"extras": [
{"type": "PATTERN", "value": "\\s"}
],
"rules": {
"expression": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "a"
},
{
"type": "ALIAS",
"value": "X",
"named": true,
"content": {
"type": "TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "b"
},
{
"type": "STRING",
"value": "c"
}
]
}
}
},
{
"type": "ALIAS",
"value": "Y",
"named": true,
"content": {
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "d"
},
{
"type": "STRING",
"value": "e"
}
]
}
}
}
]
}
}
}

View file

@ -0,0 +1 @@
This grammar shows that `ALIAS` rules can be applied directly to `TOKEN` and `IMMEDIATE_TOKEN` rules.