Commit c7a5568b authored by eckhart's avatar eckhart

- ebnf.py: Refactoring of compiler directives

parent 005647c1
This diff is collapsed.
......@@ -1415,7 +1415,7 @@ class Series(NaryOperator):
found = text_[:10].replace('\n', '\\n ')
for search, message in self.err_msgs:
rxs = not isinstance(search, str)
if rxs and text_.match(search) or not rxs and text_.startswith(search):
if rxs and text_.match(search) or (not rxs and text_.startswith(search)):
try:
msg = message.format(parser.repr, found)
break
......
......@@ -453,19 +453,6 @@ class TestCuratedErrors:
Cureted Errors replace existing errors with alternative
error codes and messages that are more helptful to the user.
"""
# def test_user_error_declaration(self):
# lang = """
# document = series | /.*/
# series = "X" | head §"C" "D"
# head = "A" "B"
# @series_error = "a user defined error message"
# """
# try:
# parser = grammar_provider(lang)()
# assert False, "Error definition after symbol definition should fail!"
# except CompilationError as e:
# pass
def test_curated_mandatory_continuation(self):
lang = """
document = series | /.*/
......@@ -497,6 +484,21 @@ class TestCuratedErrors:
assert st.collect_errors()[0].code == Error.MANDATORY_CONTINUATION
assert st.collect_errors()[0].message == "a user defined error message"
def test_error_cusomization_mistakes(self):
lang = """
document = series | other
@other_error = "a user defined error message"
series = "A" § "B" "C"
other = "X" | "Y" | "Z"
"""
parser = grammar_provider(lang)()
st = parser("ABC")
assert not st.error_flag
st = parser("Y")
assert not st.error_flag
st = parser("ADC")
assert st.error_flag
print(st.collect_errors())
class TestCustomizedResumeParsing:
def setup(self):
......
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