Commit 19c83afc authored by di68kap's avatar di68kap
Browse files

- DHParser/parse.py: bugfix reentry_point()

parent 707b1cf9
......@@ -171,8 +171,9 @@ def reentry_point(rest: StringView, rules: ResumeList, comment_regex) -> int:
k, length = search_func(search_rule)
while a < b <= k:
a, b = next_comment()
while a <= k + length < b:
k, length = search_func(search_rule, k + max(length, 1))
# find next as long as start or end point of resume regex are inside a comment
while (a < k < b) or (a < k + length < b):
k, length = search_func(search_rule, b)
while a < b <= k:
a, b = next_comment()
return k + length if k >= 0 else upper_limit
......@@ -1985,7 +1986,7 @@ class Alternative(NaryParser):
# the order of the sub-expression matters!
>>> number = RE(r'\d+') | RE(r'\d+') + RE(r'\.') + RE(r'\d+')
>>> str(Grammar(number)("3.1416"))
'3 <<< Error on ".1416" | Parser stopped before end! trying to recover... >>> '
'3 <<< Error on ".1416" | Parser stopped before end! Terminating parser. >>> '
# the most selective expression should be put first:
>>> number = RE(r'\d+') + RE(r'\.') + RE(r'\d+') | RE(r'\d+')
......
......@@ -651,14 +651,19 @@ class TestCustomizedResumeParsing:
EOF = !/./
"""
grammar = grammar_provider(grammar_specification)()
doc0 = """word no*word word"""
st = grammar(doc0)
assert st.children and st.children[-1].tag_name == 'word'
doc1 = """word no*word /* comment */ word"""
st = grammar(doc1)
assert st.children and st.children[-1].tag_name == 'word'
# TODO: provide test case
doc2 = """word no*word/* comment */word"""
st = grammar(doc2)
assert st.children and st.children[-1].tag_name == 'word'
# print(st.as_sxpr())
doc3 = """word no*word/* comment1 */
/* comment2 */word"""
st = grammar(doc3)
assert st.children and st.children[-1].tag_name == 'word'
class TestInSeriesResume:
......
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