Commit b25f87b6 authored by di68kap's avatar di68kap
Browse files

- DHParser.testing Lookahead checking bug fixed

parent 98fc3fa7
......@@ -308,33 +308,31 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve
parser = parser_factory()
transform = transformer_factory()
is_lookahead = set() # type: Dict[str] # Dictionary of parser names
is_lookahead = set() # type: Set[str] # Dictionary of parser names
with_lookahead = set() # type: Set[Parser]
visited = set() # type: Set[Parser]
lookahead_flag = False # type: bool
def find_lookahead(p: Parser):
"""Raises a StopIterationError if parser `p` is or contains
a Lookahead-parser."""
nonlocal is_lookahead, with_lookahead, visited
if p in visited:
raise StopIteration
nonlocal is_lookahead, with_lookahead, lookahead_flag
if p in with_lookahead:
lookahead_flag = True
if isinstance(p, Lookahead):
lookahead_flag = True
def has_lookahead(parser_name: str):
"""Returns `True`, if given parser is or contains a Lookahead-parser."""
nonlocal is_lookahead, with_lookahead, visited, parser
nonlocal is_lookahead, with_lookahead, lookahead_flag, parser
p = parser[parser_name]
num_lookaheads = len(is_lookahead)
if p in with_lookahead:
return True
lookahead_flag = False
except StopIteration:
if len(is_lookahead) > num_lookaheads:
if lookahead_flag:
return True
return False
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