Commit fce69a49 authored by di68kap's avatar di68kap
Browse files

- test/test_pare: Some tests for error recovery

parent 25a88afc
......@@ -36,7 +36,7 @@ from DHParser.parse import ParserError, Parser, Grammar, Forward, TKN, ZeroOrMor
from DHParser import compile_source
from DHParser.ebnf import get_ebnf_grammar, get_ebnf_transformer, get_ebnf_compiler, DHPARSER_IMPORTS
from DHParser.dsl import grammar_provider, CompilationError
from DHParser.syntaxtree import Node
from DHParser.syntaxtree import Node, parse_sxpr
from DHParser.stringview import StringView
......@@ -468,6 +468,42 @@ class TestAllOfSomeOf:
assert Grammar(prefixes)('A B B').error_flag
class TestErrorRecovery:
def test_series_skip(self):
lang = """
document = series | /.*/
@series_skip = /[A-Z]/
series = "A" "B" §"C" "D"
"""
parser = grammar_provider(lang)()
st = parser('AB_D')
assert len(st.errors) == 1 # no additional "stopped before end"-error!
def test_AllOf_skip(self):
lang = """
document = allof | /.*/
@allof_skip = /[A-Z]/
allof = < "A" §"B" "C" "D" >
"""
parser = grammar_provider(lang)()
st = parser('CADB')
assert 'allof' in st and st['allof'].content == "CADB"
st = parser('_BCD')
assert st.equals(parse_sxpr('(document "_BCD")'))
st = parser('_ABC')
assert st.equals(parse_sxpr('(document "_ABC")'))
st = parser('A_CD')
assert st['allof'].content == "A_CD"
st = parser('AB_D')
assert st['allof'].content == "AB_D"
st = parser('A__D')
assert st['allof'].content == "A__D"
st = parser('CA_D')
assert st['allof'].content == "CA_D"
st = parser('BC_A')
assert st['allof'].content == "BC_A"
class TestPopRetrieve:
mini_language = r"""
document = { text | codeblock }
......
......@@ -136,7 +136,7 @@ class TestLoggingAndLoading:
# Maybe: Some other thread has created logdir but not yet info.txt
# Solution: Just return True, cause log_dir() does not guarantee
# existence of 'info.txt', anyway...
return os.path.exists(os.path.join(self.LOGDIR, "info.txt"))
return True
def test_logging_multiprocessing(self):
start_logging(self.LOGDIR)
......
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