Fixed issue #3 (infinite recursion in grammar)

This commit is contained in:
Erez Shinan 2017-03-09 09:45:56 +02:00
parent d40ddff5c0
commit 24f86569da
2 changed files with 12 additions and 0 deletions

View File

@ -105,6 +105,8 @@ class Column:
new_tree = old_tree.copy()
new_tree.rule = old_tree.rule
old_tree.set('ambig', [new_tree])
if item.tree.children[0] is old_tree: # XXX a little hacky!
raise ParseError("Infinite recursion in grammar!")
old_tree.children.append(item.tree)
else:
self.completed[item] = item

View File

@ -39,6 +39,16 @@ class TestParsers(unittest.TestCase):
l2 = g.parse('(a,b,c,*x)')
assert l == l2, '%s != %s' % (l.pretty(), l2.pretty())
def test_infinite_recurse(self):
g = """start: a
a: a | "a"
"""
self.assertRaises(GrammarError, Lark, g, parser='lalr')
l = Lark(g, parser='earley')
self.assertRaises(ParseError, l.parse, 'a')
class TestEarley(unittest.TestCase):
def test_anon_in_scanless(self):