Commit 43897f82 authored by Eckhart Arnold's avatar Eckhart Arnold
Browse files

ebnf.py: new EBNF-parser and -compiler tested :-)

parent e9e607be
......@@ -2666,11 +2666,22 @@ class Retrieve(Parser):
return duplicate
def _parse(self, text: StringView) -> Tuple[Optional[Node], StringView]:
# auto-capture on first use if symbol was not captured before
if len(self.grammar.variables__[self.symbol.pname]) == 0:
_ = self.symbol(text) # auto-capture value
# the following indirection allows the call() method to be called
# from subclass without triggering the parser guard a second time
return self.retrieve_and_match(text)
node, text_ = self.retrieve_and_match(text)
# in case the symbol allows for different values, generate an
# error, if the wrong value has been used
# if node is None:
# node, text__ = self.symbol(text)
# if node is not None:
# tn = self.tag_name if self.pname else self.symbol.tag_name
# node = Node(tn, '').with_pos(self.grammar.document_length__ - text.__len__())
# self.grammar.tree__.new_error(
# node, 'Inconsistent use of symbol %s: "%s" expected, "%s" found!'
# % (self.symbol.pname, self.grammar.variables__[self.symbol.pname], text__))
# return node, text__
return node, text_
def __repr__(self):
return ':' + self.symbol.repr
......
......@@ -552,10 +552,6 @@ class TestInterleave:
assert st.errors
class TestErrorRecovery:
def test_series_skip(self):
lang = """
......@@ -651,6 +647,7 @@ class TestPopRetrieve:
assert self.minilang_parser
assert self.minilang_parser2
assert self.minilang_parser3
assert self.minilang_parser4
def test_stackhandling(self):
ambigous_opening = "<ABCnormal> normal tag <ABCnormal*>"
......@@ -700,7 +697,6 @@ class TestPopRetrieve:
assert not self.minilang_parser4.variables__['name']
assert st.error_flag
def test_cache_neutrality(self):
"""Test that packrat-caching does not interfere with the variable-
changing parsers: Capture and Retrieve."""
......@@ -721,7 +717,8 @@ class TestPopRetrieve:
def test_single_line(self):
teststr = "Anfang ```code block `` <- keine Ende-Zeichen ! ``` Ende"
syntax_tree = self.minilang_parser(teststr)
assert not syntax_tree.errors_sorted
assert not syntax_tree.errors_sorted, \
''.join(str(error) for error in syntax_tree.errors_sorted)
matchf = partial(self.has_tag_name, name="delimiter")
delim = str(next(syntax_tree.select_if(matchf)))
pop = str(next(syntax_tree.select_if(matchf, reverse=True)))
......
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