mirror of https://github.com/lark-parser/lark.git
Fixed issue #3 (infinite recursion in grammar)
This commit is contained in:
parent
d40ddff5c0
commit
24f86569da
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue