Commit 07cf20fd authored by Eckhart Arnold's avatar Eckhart Arnold
Browse files

parse.py: reentry_point() refactored

parent ea695bb6
......@@ -3143,7 +3143,7 @@ class EBNFCompiler(Compiler):
refined = self.gen_search_rule(nd)
except IndexError:
nd = self.tree # TODO: Allow arbitrary parsers, here
refined = ""
refined = '' # refined = rule
except KeyError:
# rule represents a procedure name
nd = self.tree
......
......@@ -888,6 +888,51 @@ class TestCustomizedResumeParsing:
st = grammar(doc3)
assert st.children and st.children[-1].tag_name == 'word'
class TestCustomizedResumeParsing_with_Parsers:
lang = r"""@ literalws = right
@ alpha_resume = ALPHA_RESUME
@ beta_resume = GAMMA_RE
@ bac_resume = /(?=GA\w+)/
document = alpha [beta] gamma "."
alpha = "ALPHA" abc
abc = §"a" "b" "c"
beta = "BETA" (bac | bca)
bac = "b" "a" §"c"
bca = "b" "c" §"a"
gamma = "GAMMA" §(cab | cba)
cab = "c" "a" §"b"
cba = "c" "b" §"a"
GAMMA_RE = /(?=GA\w+)/
ALPHA_RESUME = { !`BETA` !`GAMMA` /./ }
"""
gr = grammar_provider(lang)()
def test_several_resume_rules_innermost_rule_matching(self):
gr = self.gr
content = 'ALPHA abc BETA bad GAMMA cab .'
cst = gr(content)
assert cst.error_flag
assert cst.content == content
assert cst.pick('alpha').content.startswith('ALPHA')
# because of resuming, there should be only on error message
assert len(cst.errors_sorted) == 1
content = 'ALPHA acb BETA bad GAMMA cab .'
cst = gr(content)
assert cst.error_flag
assert cst.content == content
assert cst.pick('alpha').content.startswith('ALPHA')
# because of resuming, there should be only on error message
assert len(cst.errors_sorted) == 2
content = 'ALPHA acb GAMMA cab .'
cst = gr(content)
assert cst.error_flag
assert cst.content == content
assert cst.pick('alpha').content.startswith('ALPHA')
# because of resuming, there should be only on error message
assert len(cst.errors_sorted) == 1
class TestInSeriesResume:
def setup(self):
......
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