Commit fde45420 authored by di68kap's avatar di68kap
Browse files

- DHParser/parse.py: Keine lookahead only Fehlermeldung ohne Lookahead-Parser im Aufruf-Stapel

parent a3379303
......@@ -312,7 +312,7 @@ class HistoryRecord:
line_col: Tuple[int, int],
errors: List[Error] = []) -> None:
# copy call stack, dropping uninformative Forward-Parsers
self.call_stack = [(tn, pos) for tn, pos in call_stack if tn != ":Forward"] # type: List[str]
self.call_stack = [(tn, pos) for tn, pos in call_stack if tn != ":Forward"] # type: List[Tuple[str, int]]
self.node = node # type: Optional[Node]
self.text = text # type: StringView
self.line_col = line_col # type: Tuple[int, int]
......
......@@ -1091,12 +1091,16 @@ class Grammar:
else:
stitches.append(result)
for h in reversed(self.history__):
if h.node and h.node.tag_name != EMPTY_NODE.tag_name:
if h.node and h.node.tag_name != EMPTY_NODE.tag_name \
and any('Lookahead' in tag for tag, _ in h.call_stack):
break
else:
h = 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-tests and support in testing.py
for j in self.history__:
print(j)
print(h); print()
error_msg = "Parser stopped before end, but matched with lookahead."
error_code = Error.PARSER_LOOKAHEAD_MATCH_ONLY
max_parser_dropouts = -1 # no further retries!
......
......@@ -482,7 +482,7 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report='REPORT'
tests.setdefault('__err__', {})[test_name] = errata[-1]
if not (is_error(cst.error_flag) and not lookahead_artifact(cst)):
errata.append('Fail test "%s" for parser "%s" yields match instead of '
'expected failure!' % (test_name, parser_name))
'expected failure!\n%s' % (test_name, parser_name, cst.serialize()))
tests.setdefault('__err__', {})[test_name] = errata[-1]
# write parsing-history log only in case of test-failure
if is_logging():
......
......@@ -45,6 +45,19 @@ class TestParserError:
pe = ParserError(Node('TAG', 'test').with_pos(0), StringView('Beispiel'), None, True)
assert str(pe).find('Beispiel') >= 0 and str(pe).find('TAG') >= 0
def test_false_lookahead_only_message(self):
"""Error.PARSER_LOOKAHEAD_*_ONLY errors must not be reported if there
no lookahead parser in the history!"""
lang = """
word = letters { letters | `-` letters }
letters = /[A-Za-z]+/
"""
gr = grammar_provider(lang)()
st = gr('hard-time', track_history=True)
assert not st.errors
st = gr('hard-', track_history=True)
assert st.errors and not any(e.code == 1045 for e in st.errors)
class TestParserClass:
def test_apply(self):
......
......@@ -203,6 +203,7 @@ class TestTokenParsing:
result, messages, syntaxtree = compile_source(orig_src, prepr, self.grammar,
lambda i: i, lambda i: i)
for err in messages:
print(err)
if self.code[err.orig_pos] == "#":
break
else:
......
Supports Markdown
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