Commit 6c20ccf3 authored by Eckhart Arnold's avatar Eckhart Arnold
Browse files

better tests for left recursion

parent 5bf393d0
...@@ -198,7 +198,7 @@ def add_parser_guard(parser_func): ...@@ -198,7 +198,7 @@ def add_parser_guard(parser_func):
# because caching would interfere with changes of variable state # because caching would interfere with changes of variable state
if not (grammar.rollback__ and grammar.rollback__[-1][0] <= location): if not (grammar.rollback__ and grammar.rollback__[-1][0] <= location):
parser.visited[location] = (node, rest) parser.visited[location] = (node, rest)
grammar.last_node__ = node # store last node for Lookbehind operator grammar.last_node__ = node # store last node for Lookbehind parser
elif location in parser.visited: elif location in parser.visited:
# if parser did non match but a saved result exits, assume # if parser did non match but a saved result exits, assume
# left recursion and use the saved result # left recursion and use the saved result
...@@ -1293,7 +1293,7 @@ def compile_source(source: str, ...@@ -1293,7 +1293,7 @@ def compile_source(source: str,
transformer (function): A transformation function that takes transformer (function): A transformation function that takes
the root-node of the concrete syntax tree as an argument and the root-node of the concrete syntax tree as an argument and
transforms it (in place) into an abstract syntax tree. transforms it (in place) into an abstract syntax tree.
compiler (function): A compiler function or compiler class compiler (function): A compiler function or compiler class
instance instance
Returns (tuple): Returns (tuple):
......
...@@ -79,11 +79,11 @@ ARITHMETIC2_EBNF = """ ...@@ -79,11 +79,11 @@ ARITHMETIC2_EBNF = """
class TestInfiLoopsAndRecursion: class TestInfiLoopsAndRecursion:
def test_direct_left_recursion(self): def test_direct_left_recursion(self):
minilang = ARITHMETIC_EBNF minilang = ARITHMETIC_EBNF
snippet = "5 + 3 * 4" snippet = "9 + 8 + 7 + 6 + 5 + 3 * 4"
parser = parser_factory(minilang)() parser = parser_factory(minilang)()
assert parser assert parser
syntax_tree = parser(snippet) syntax_tree = parser(snippet)
assert not syntax_tree.collect_errors() assert not syntax_tree.error_flag, str(syntax_tree.collect_errors())
assert snippet == str(syntax_tree) assert snippet == str(syntax_tree)
if is_logging(): if is_logging():
syntax_tree.log("test_LeftRecursion_direct.cst") syntax_tree.log("test_LeftRecursion_direct.cst")
...@@ -91,7 +91,7 @@ class TestInfiLoopsAndRecursion: ...@@ -91,7 +91,7 @@ class TestInfiLoopsAndRecursion:
def test_indirect_left_recursion(self): def test_indirect_left_recursion(self):
minilang = ARITHMETIC2_EBNF minilang = ARITHMETIC2_EBNF
snippet = "5 + 3 * 4" snippet = "9 + 8 + 7 + 6 + 5 + 3 * 4"
parser = parser_factory(minilang)() parser = parser_factory(minilang)()
assert parser assert parser
syntax_tree = parser(snippet) syntax_tree = parser(snippet)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment