Browse Source

Correct behaviour of aliases for templates

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.8.6
MegaIng1 5 years ago
parent
commit
3861ee7e07
1 changed files with 7 additions and 3 deletions
  1. +7
    -3
      lark/load_grammar.py

+ 7
- 3
lark/load_grammar.py View File

@@ -385,9 +385,13 @@ class ApplyTemplates(Transformer_InPlace):
self.replacer.transform(result_tree)
if name[0] != '_':
if result_tree.data == 'expansions':
for i, c in enumerate(result_tree.children):
if not (isinstance(c, Tree) and c.data == 'alias'):
result_tree.children[i] = ST('alias', [c, name])
t = result_tree
while len(t.children) == 2:
if t.children[-1].data != 'alias':
t.children[-1] = ST('alias', [t.children[-1], name])
t = t.children[0]
if t.children[-1].data != 'alias':
t.children[-1] = ST('alias', [t.children[-1], name])
elif result_tree.data != 'alias':
result_tree = ST('alias', [result_tree, name])
self.rule_defs.append((result_name, [], result_tree, deepcopy(options)))


Loading…
Cancel
Save