Commit 396cd173 authored by di68kap's avatar di68kap
Browse files

ebnf.py: custom error messages (XXX_error = ...) and skip lists (XXX_skip =...

ebnf.py: custom error messages (XXX_error = ...) and skip lists (XXX_skip = ...) may now be defined after the symbol (the "XXX" above) they refer to.
parent cf6931fe
......@@ -1812,9 +1812,9 @@ class EBNFCompiler(Compiler):
check_argnum(2)
symbol = key[:-6]
error_msgs = self.directives.error.get(symbol, [])
if symbol in self.rules:
self.tree.new_error(node, 'Custom error message for symbol "%s"' % symbol
+ ' must be defined before the symbol!')
# if symbol in self.rules:
# self.tree.new_error(node, 'Custom error message for symbol "%s"' % symbol
# + ' must be defined before the symbol!')
if node.children[1 if len(node.children) == 2 else 2].tag_name != 'literal':
self.tree.new_error(
node, 'Directive "%s" requires message string or a a pair ' % key
......@@ -1831,9 +1831,9 @@ class EBNFCompiler(Compiler):
elif key.endswith('_skip'):
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))
# 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))
self.directives.skip[symbol] = self.gen_search_list(node.children[1:])
elif key.endswith('_resume'):
......
......@@ -688,6 +688,22 @@ class TestErrorRecovery:
assert len(st.errors) == 2 and any(err.code == RESUME_NOTICE for err in st.errors)
assert 'Skipping' in str(st.errors_sorted[1])
def test_irrelevance_of_error_definition_order(self):
lang = """
document = series | /.*/
series = "A" "B" §"C" "D"
@series_skip = /(?=[A-Z])/
@series_error = '', "Unerwartetes Zeichen"
"""
parser = grammar_provider(lang)()
st = parser('AB_D')
assert len(st.errors) == 1 # no additional "stopped before end"-error!
assert st.errors[0].message == "Unerwartetes Zeichen"
resume_notices_on(parser)
st = parser('AB_D')
assert len(st.errors) == 2 and any(err.code == RESUME_NOTICE for err in st.errors)
assert 'Skipping' in str(st.errors_sorted[1])
def test_Interleave_skip(self):
lang = """
document = allof | /.*/
......
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