Commit ade1ec7c authored by eckhart's avatar eckhart
Browse files

some adjustments

parent d0475388
......@@ -1834,7 +1834,7 @@ class EBNFCompiler(Compiler):
symbol = key[:-5]
if symbol in self.rules:
self.tree.new_error(node, 'Skip list for resuming in series for symbol "{}"'
'must be defined before the symbol!'.format(symbol))
' must be defined before the symbol!'.format(symbol))
self.directives.skip[symbol] = self.gen_search_list(node.children[1:])
elif key.endswith('_resume'):
......@@ -2080,12 +2080,14 @@ class EBNFCompiler(Compiler):
self.deferred_tasks.append(lambda :verify(node))
return result
def on_difference(self, node: Node) -> str:
assert len(node.children) == 2, str(node.as_sxpr())
left = self.compile(node.children[0])
right = self.compile(node.children[1])
return "Series(NegativeLookahead(%s), %s)" % (right, left)
def on_element(self, node: Node) -> str:
assert node.children
assert len(node.children) == 2
......
......@@ -2372,7 +2372,7 @@ class MandatoryNary(NaryParser):
:return: a tuple of an error object, a zombie node at the position
where the mandatory violation occurred and to which the error
object is attached and a string view for continuing the
object is attached and a string view for the continuation the
parsing process
"""
grammar = self._grammar
......
......@@ -753,7 +753,6 @@ class TestErrorCustomizationErrors:
assert cst.errors
assert 'alles' in cst and 'ZOMBIE__' in cst['alles'] and 'ende' in cst['alles']
def test_multiple_resume_definitions(self):
lang = """
document = series
......@@ -793,9 +792,11 @@ class TestErrorCustomizationErrors:
'several strings'
series = "A" § "B" "C"
"""
parser = grammar_provider(lang)()
provider = grammar_provider(lang)
# print(provider.python_src__)
parser = provider()
result = parser('ADX')
assert "several strings" in str(result.errors)
assert "several strings" in str(result.errors), str(result.errors)
class TestCustomizedResumeParsing:
......@@ -1262,6 +1263,29 @@ class TestHeuristics:
# assert s != "array = `[` [_element {`,` _element}] `]`"
# Reordering of rules in order to minimize the number of Forwad-Declarations
# has not yet been implemented in class ebnf.EBNFCompiler !!!
#
# class TestRuleOrder:
# def test_rule_specification_order_does_not_matter(self):
# normal_order = """
# A = B
# B = C
# C = "Hallo Welt"
# """
# parser = create_parser(normal_order)
# assert parser.B.__class__.__name__ != "Forward"
#
# # Now B, should not be a Forward-Parser
# reverse_order = """
# C = "Hallo Welt"
# B = C
# A = B
# """
# parser = create_parser(reverse_order)
# # If order of rule specification did not matter,
# # B should not be a Forward-parser:
# assert parser.B.__class__.__name__ != "Forward"
if __name__ == "__main__":
......
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