Commit c265ccda authored by di68kap's avatar di68kap

- Logik für Fehlermeldungen bei Grammatik-Einheiten-Tests angepasst

parent edb48e86
......@@ -974,7 +974,9 @@ class Grammar:
result, 'Parser "%s" did not match empty document.' % str(parser),
Error.PARSER_DID_NOT_MATCH)
while rest and len(stitches) < self.max_parser_dropouts__:
# copy to local variable, so break condition can be triggered manually
max_parser_dropouts = self.max_parser_dropouts__
while rest and len(stitches) < max_parser_dropouts:
result, rest = parser(rest)
if rest:
fwd = rest.find("\n") + 1 or len(rest)
......@@ -1000,6 +1002,7 @@ class Grammar:
# TODO: this case still needs unit-tests and support in testing.py
error_msg = "Parser stopped before end, but matched with lookahead."
error_code = Error.PARSER_STOPPED_EXCEPT_FOR_LOOKAHEAD
max_parser_dropouts = -1 # no further retries!
else:
error_msg = "Parser stopped before end" \
+ (("! trying to recover"
......
......@@ -351,14 +351,15 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve
operator at the end. See test_testing.TestLookahead.
"""
raw_errors = syntax_tree.errors_sorted
is_artifact = ((2 <= len(raw_errors) <= 3 # case 1: superfluous data for lookahead
is_artifact = ((2 <= len(raw_errors) == 3 # case 1: superfluous data for lookahead
and {e.code for e in raw_errors} <=
{Error.PARSER_LOOKAHEAD_MATCH_ONLY,
Error.PARSER_STOPPED_BEFORE_END,
# Error.PARSER_STOPPED_BEFORE_END,
Error.PARSER_STOPPED_EXCEPT_FOR_LOOKAHEAD})
# case 3: mandatory lookahead failure at end of text
or (len(raw_errors) == 1
and raw_errors[-1].code == Error.MANDATORY_CONTINUATION_AT_EOF))
and (raw_errors[-1].code == Error.PARSER_STOPPED_EXCEPT_FOR_LOOKAHEAD
# case 2: mandatory lookahead failure at end of text
or raw_errors[-1].code == Error.MANDATORY_CONTINUATION_AT_EOF)))
if is_artifact:
# don't remove zombie node with error message at the end
# but change it's tag_name to indicate that it is an artifact!
......
......@@ -312,7 +312,9 @@ class TestLookahead:
gr = self.grammar_fac()
# Case 1: Lookahead string is part of the test case; parser fails but for the lookahead
result = gr(self.cases['category']['match'][1], 'category', True)
assert any(e.code == Error.PARSER_LOOKAHEAD_MATCH_ONLY for e in result.errors)
assert any(e.code in (Error.PARSER_LOOKAHEAD_MATCH_ONLY,
Error.PARSER_STOPPED_EXCEPT_FOR_LOOKAHEAD)
for e in result.errors)
# Case 2: Lookahead string is not part of the test case; parser matches but for the mandatory continuation
result = gr(self.cases['category']['match'][2], 'category', True)
assert any(e.code == Error.MANDATORY_CONTINUATION_AT_EOF for e in result.errors)
......
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