Commit e8025e8c authored by di68kap's avatar di68kap
Browse files

- Problem der Lookahead-Parser-Bestimmung!!!

parent 6eb43c46
......@@ -155,7 +155,6 @@ def reentry_point(rest: StringView, rules: ResumeList) -> int:
if i == upper_limit:
i = -1
return i
# return Node(ZOMBIE_TAG, rest[:i]), rest[i:]
ApplyFunc = Callable[['Parser'], None]
......@@ -325,7 +324,11 @@ class Parser:
raise ParserError(error.node, error.rest, first_throw=False)
else:
result = (Node(ZOMBIE_TAG, text[:gap]), error.node) if gap else error.node # type: ResultType
raise ParserError(Node(self.tag_name, result), text, first_throw=False)
if grammar.tree__.errors[-1].code == Error.MANDATORY_CONTINUATION_AT_EOF: # EXPERIMENTAL!!
node = error.node
else:
raise ParserError(Node(self.tag_name, result), text, first_throw=False)
if grammar.left_recursion_handling__:
self.recursion_counter[location] -= 1
......@@ -1554,7 +1557,7 @@ def mandatory_violation(grammar: Grammar,
else:
msg = '%s expected, "%s" found!' % (expected, found)
error = Error(msg, location, Error.MANDATORY_CONTINUATION if text_
else Error.MANDATORY_CONTINUATION_AT_EOF)
else Error.MANDATORY_CONTINUATION_AT_EOF)
grammar.tree__.add_error(err_node, error)
return error, err_node, text_[i:]
......
......@@ -322,9 +322,9 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve
parser = parser_factory()
transform = transformer_factory()
is_lookahead = set() # type: Set[str] # Dictionary of parser names
# is_lookahead = set() # type: Set[str] # Dictionary of parser names
with_lookahead = set() # type: Set[Optional[Parser]]
lookahead_flag = False # type: bool
# lookahead_flag = False # type: bool
def find_lookahead(p: Parser):
"""Raises a StopIterationError if parser `p` is or contains
......@@ -339,8 +339,9 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve
lookahead_flag = True
else:
if any(child for child in (getattr(p, 'parsers', [])
or [getattr(p, 'parser', None)]) if child in with_lookahead):
or [getattr(p, 'parser', None)]) if isinstance(child, Lookahead)):
with_lookahead.add(p)
lookahead_flag = True
def has_lookahead(parser_name: str):
"""Returns `True`, if given parser is or contains a Lookahead-parser."""
......@@ -370,7 +371,7 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve
# case 2: mandatory lookahead failure at end of text
or (len(raw_errors) == 1
and raw_errors[-1].code == Error.MANDATORY_CONTINUATION_AT_EOF)
and any(tn in is_lookahead for tn in parser.history__[-1].call_stack))
and any(tn in with_lookahead for tn in parser.history__[-1].call_stack))
for parser_name, tests in test_unit.items():
assert parser_name, "Missing parser name in test %s!" % unit_name
......
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