Fix unit reduction elimination bugs
* Handle 'chains' of unit reductions starting in a single state * Avoid eliminating rules which will later receive aliases
This commit is contained in:
parent
72849787b1
commit
7183f8d3e7
4 changed files with 112 additions and 35 deletions
12
test/fixtures/test_grammars/aliased_unit_reductions/corpus.txt
vendored
Normal file
12
test/fixtures/test_grammars/aliased_unit_reductions/corpus.txt
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
==========================================
|
||||
Aliases on rules that are unit reductions
|
||||
==========================================
|
||||
|
||||
one two three;
|
||||
|
||||
---
|
||||
|
||||
(statement
|
||||
(identifier)
|
||||
(b_prime (identifier))
|
||||
(c_prime (identifier)))
|
||||
70
test/fixtures/test_grammars/aliased_unit_reductions/grammar.json
vendored
Normal file
70
test/fixtures/test_grammars/aliased_unit_reductions/grammar.json
vendored
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
{
|
||||
"name": "aliased_unit_reductions",
|
||||
|
||||
"extras": [
|
||||
{"type": "PATTERN", "value": "\\s"}
|
||||
],
|
||||
|
||||
"rules": {
|
||||
"statement": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{"type": "SYMBOL", "name": "_a"},
|
||||
{
|
||||
"type": "ALIAS",
|
||||
"named": true,
|
||||
"value": "b_prime",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_b"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ALIAS",
|
||||
"named": true,
|
||||
"value": "c_prime",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_c"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ";"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
"_a": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_A"
|
||||
},
|
||||
|
||||
"_A": {
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
},
|
||||
|
||||
"_b": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_B"
|
||||
},
|
||||
|
||||
"_B": {
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
},
|
||||
|
||||
"_c": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_B"
|
||||
},
|
||||
|
||||
"_C": {
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
},
|
||||
|
||||
"identifier": {"type": "PATTERN", "value": "[a-z]+"}
|
||||
}
|
||||
}
|
||||
5
test/fixtures/test_grammars/aliased_unit_reductions/readme.md
vendored
Normal file
5
test/fixtures/test_grammars/aliased_unit_reductions/readme.md
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
Normally, when there are invisible rules (rules whose names start with an `_`) that simply
|
||||
wrap another rule, there is an optimization at parser-generation time called *Unit Reduction Elimination* that avoids creating nodes for those rules at runtime. One case where this
|
||||
optimization must *not* be applied is when those invisible rules are going to be aliased
|
||||
within their parent rule. In that situation, eliminating the invisible node could cause
|
||||
the alias to be incorrectly applied to its child.
|
||||
Loading…
Add table
Add a link
Reference in a new issue