Commit 9e71a764 authored by di68kap's avatar di68kap

- Fehler in DHParser/parser.py : yet another testing artifact error case; supported in testing.py

parent d1297425
......@@ -28,7 +28,6 @@ DevScripts/DHParser.py
DHParser/cstringview.c
*.so
.mypy_cache
.vscode/
DHParser.egg-info
.noseids/
*.build
......@@ -42,7 +41,6 @@ _build
_build
_static
_templates
.vs
OLDSTUFF
.pytest_cache
*.c
......
......@@ -994,9 +994,10 @@ class Grammar:
error_code = Error.PARSER_DID_NOT_MATCH
else:
stitches.append(result)
h = self.history__[-1]
h = self.history__[-1] if self.history__ else \
HistoryRecord([], None, StringView(''), (0, 0))
if h.status == h.MATCH and (h.node.pos + len(h.node) == len(self.document__)):
# TODO: this case still needs unit-test and support in testing.py
# 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
else:
......
This diff is collapsed.
......@@ -351,10 +351,12 @@ 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 = ((len(raw_errors) == 2 # case 1: superfluous data for lookahead
and raw_errors[-1].code == Error.PARSER_LOOKAHEAD_MATCH_ONLY
and raw_errors[-2].code == Error.PARSER_STOPPED_BEFORE_END)
# case 2: mandatory lookahead failure at end of text
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_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))
if is_artifact:
......
......@@ -317,6 +317,8 @@ class TestLookahead:
result = gr(self.cases['category']['match'][2], 'category', True)
assert any(e.code == Error.MANDATORY_CONTINUATION_AT_EOF for e in result.errors)
errata = grammar_unit(self.cases, self.grammar_fac, self.trans_fac)
for e in errata:
print (e)
assert not errata, str(errata)
errata = grammar_unit(self.fail_cases, self.grammar_fac, self.trans_fac)
assert errata
......
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