From 32b78b8ee5c9e26af85b6119d083035e1af9c1b7 Mon Sep 17 00:00:00 2001 From: Erez Shinan Date: Mon, 30 Jul 2018 17:54:12 +0300 Subject: [PATCH] BUGFIX: Repeated use of optional rules tripped up the simplifier, manifesting when aliases were used (Issue #197) --- lark/load_grammar.py | 1 + tests/test_parser.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/lark/load_grammar.py b/lark/load_grammar.py index 6da2df0..8f924c5 100644 --- a/lark/load_grammar.py +++ b/lark/load_grammar.py @@ -235,6 +235,7 @@ class SimplifyRule_Visitor(Visitor): tree.children = [self.visit(ST('expansion', [option if i==j else other for j, other in enumerate(tree.children)])) for option in set(child.children)] + self._flatten(tree) break def alias(self, tree): diff --git a/tests/test_parser.py b/tests/test_parser.py index c4d7147..a029abe 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -148,6 +148,9 @@ class TestParsers(unittest.TestCase): self.assertEqual( r.children, [""] ) + def test_alias(self): + Lark("""start: ["a"] "b" ["c"] "e" ["f"] ["g"] ["h"] "x" -> d """) + def _make_full_earley_test(LEXER):