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 ...@@ -28,7 +28,6 @@ DevScripts/DHParser.py
DHParser/cstringview.c DHParser/cstringview.c
*.so *.so
.mypy_cache .mypy_cache
.vscode/
DHParser.egg-info DHParser.egg-info
.noseids/ .noseids/
*.build *.build
...@@ -42,7 +41,6 @@ _build ...@@ -42,7 +41,6 @@ _build
_build _build
_static _static
_templates _templates
.vs
OLDSTUFF OLDSTUFF
.pytest_cache .pytest_cache
*.c *.c
......
...@@ -994,9 +994,10 @@ class Grammar: ...@@ -994,9 +994,10 @@ class Grammar:
error_code = Error.PARSER_DID_NOT_MATCH error_code = Error.PARSER_DID_NOT_MATCH
else: else:
stitches.append(result) 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__)): 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_msg = "Parser stopped before end, but matched with lookahead."
error_code = Error.PARSER_STOPPED_EXCEPT_FOR_LOOKAHEAD error_code = Error.PARSER_STOPPED_EXCEPT_FOR_LOOKAHEAD
else: else:
......
This diff is collapsed.
...@@ -351,10 +351,12 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve ...@@ -351,10 +351,12 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve
operator at the end. See test_testing.TestLookahead. operator at the end. See test_testing.TestLookahead.
""" """
raw_errors = syntax_tree.errors_sorted raw_errors = syntax_tree.errors_sorted
is_artifact = ((len(raw_errors) == 2 # case 1: superfluous data for lookahead is_artifact = ((2 <= len(raw_errors) <= 3 # case 1: superfluous data for lookahead
and raw_errors[-1].code == Error.PARSER_LOOKAHEAD_MATCH_ONLY and {e.code for e in raw_errors} <=
and raw_errors[-2].code == Error.PARSER_STOPPED_BEFORE_END) {Error.PARSER_LOOKAHEAD_MATCH_ONLY,
# case 2: mandatory lookahead failure at end of text 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 or (len(raw_errors) == 1
and raw_errors[-1].code == Error.MANDATORY_CONTINUATION_AT_EOF)) and raw_errors[-1].code == Error.MANDATORY_CONTINUATION_AT_EOF))
if is_artifact: if is_artifact:
......
...@@ -317,6 +317,8 @@ class TestLookahead: ...@@ -317,6 +317,8 @@ class TestLookahead:
result = gr(self.cases['category']['match'][2], 'category', True) result = gr(self.cases['category']['match'][2], 'category', True)
assert any(e.code == Error.MANDATORY_CONTINUATION_AT_EOF for e in result.errors) 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) errata = grammar_unit(self.cases, self.grammar_fac, self.trans_fac)
for e in errata:
print (e)
assert not errata, str(errata) assert not errata, str(errata)
errata = grammar_unit(self.fail_cases, self.grammar_fac, self.trans_fac) errata = grammar_unit(self.fail_cases, self.grammar_fac, self.trans_fac)
assert errata 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