Commit 5c31e8d8 authored by di68kap's avatar di68kap

DHParser/templaytes/DSLServer.pyi: command line arguments now parsed with the argparse-module

parent 02720456
...@@ -436,9 +436,9 @@ class Parser: ...@@ -436,9 +436,9 @@ class Parser:
location = grammar.document_length__ - text._len # faster then len(text)? location = grammar.document_length__ - text._len # faster then len(text)?
try: try:
# rollback variable changing operation if parser backtracks # rollback variable changing operation if parser backtracks to a position
# to a position before the variable changing operation occurred # before or at the location where the variable changing operation occurred
if grammar.last_rb__loc__ > location: if grammar.last_rb__loc__ >= location:
grammar.rollback_to__(location) grammar.rollback_to__(location)
# if location has already been visited by the current parser, return saved result # if location has already been visited by the current parser, return saved result
...@@ -3080,7 +3080,10 @@ class Pop(Retrieve): ...@@ -3080,7 +3080,10 @@ class Pop(Retrieve):
node, txt = self.retrieve_and_match(text) node, txt = self.retrieve_and_match(text)
if node is not None and not id(node) in self.grammar.tree__.error_nodes: if node is not None and not id(node) in self.grammar.tree__.error_nodes:
self.values.append(self.grammar.variables__[self.symbol_pname].pop()) self.values.append(self.grammar.variables__[self.symbol_pname].pop())
location = self.grammar.document_length__ - text.__len__() location = self.grammar.document_length__ - text.__len__() - 1
# if node is not EMPTY_NODE and len(node) == 0:
# location = self.grammar.document_length__ - txt.__len__() - 1
# print('PUSH:', self.symbol_pname, location, self.values[-1])
self.grammar.push_rollback__(location, self._rollback) # lambda: stack.append(value)) self.grammar.push_rollback__(location, self._rollback) # lambda: stack.append(value))
return node, txt return node, txt
...@@ -3210,7 +3213,7 @@ class Forward(UnaryParser): ...@@ -3210,7 +3213,7 @@ class Forward(UnaryParser):
location = grammar.document_length__ - text._len location = grammar.document_length__ - text._len
# rollback variable changing operation if parser backtracks # rollback variable changing operation if parser backtracks
# to a position before the variable changing operation occurred # to a position before the variable changing operation occurred
if grammar.last_rb__loc__ > location: if grammar.last_rb__loc__ >= location:
grammar.rollback_to__(location) grammar.rollback_to__(location)
# if location has already been visited by the current parser, return saved result # if location has already been visited by the current parser, return saved result
......
...@@ -113,9 +113,9 @@ class TestParserClass: ...@@ -113,9 +113,9 @@ class TestParserClass:
class TestInfiLoopsAndRecursion: class TestInfiLoopsAndRecursion:
def setup(self): def setup(self):
pass pass
set_config_value('history_tracking', True) # set_config_value('history_tracking', True)
# set_config_value('resume_notices', True) # set_config_value('resume_notices', True)
start_logging('LOGS') # start_logging('LOGS')
def test_very_simple(self): def test_very_simple(self):
minilang = """ minilang = """
...@@ -204,7 +204,7 @@ class TestInfiLoopsAndRecursion: ...@@ -204,7 +204,7 @@ class TestInfiLoopsAndRecursion:
# BEWARE: EXPERIMENTAL TEST can be long running # BEWARE: EXPERIMENTAL TEST can be long running
def test_indirect_left_recursion2(self): def test_indirect_left_recursion2(self):
arithmetic_syntax = """@literalws = right arithmetic_syntax = r"""@literalws = right
expression = addition | subtraction # | term expression = addition | subtraction # | term
addition = (expression | term) "+" (expression | term) addition = (expression | term) "+" (expression | term)
subtraction = (expression | term) "-" (expression | term) subtraction = (expression | term) "-" (expression | term)
...@@ -226,7 +226,7 @@ class TestInfiLoopsAndRecursion: ...@@ -226,7 +226,7 @@ class TestInfiLoopsAndRecursion:
log_parsing_history(arithmetic, "test_LeftRecursion_indirect2") log_parsing_history(arithmetic, "test_LeftRecursion_indirect2")
def test_indirect_left_recursion3(self): def test_indirect_left_recursion3(self):
arithmetic_syntax = """@literalws = right arithmetic_syntax = r"""@literalws = right
expression = addition | subtraction | term expression = addition | subtraction | term
addition = (expression | term) "+" (expression | term) addition = (expression | term) "+" (expression | term)
subtraction = (expression | term) "-" (expression | term) subtraction = (expression | term) "-" (expression | term)
...@@ -718,7 +718,7 @@ class TestPopRetrieve: ...@@ -718,7 +718,7 @@ class TestPopRetrieve:
mini_language = r""" mini_language = r"""
document = { text | codeblock } document = { text | codeblock }
codeblock = delimiter { text | (!:delimiter delimiter_sign) } ::delimiter codeblock = delimiter { text | (!:delimiter delimiter_sign) } ::delimiter
delimiter = delimiter_sign # never use delimiter between capture and pop except for retrival! delimiter = delimiter_sign # never use delimiter between capture and pop except for retrieval!
delimiter_sign = /`+/ delimiter_sign = /`+/
text = /[^`]+/ text = /[^`]+/
""" """
...@@ -805,21 +805,31 @@ class TestPopRetrieve: ...@@ -805,21 +805,31 @@ class TestPopRetrieve:
assert not syntax_tree.error_flag, str(syntax_tree.errors_sorted) assert not syntax_tree.error_flag, str(syntax_tree.errors_sorted)
def test_optional_match(self): def test_optional_match(self):
test1 = '<info>Hey, you</info>' # from DHParser.dsl import compileEBNF
st = self.minilang_parser4(test1) # src = compileEBNF(self.mini_lang4)
assert not st.error_flag, str(st.errors_sorted) # print(src)
test12 = '<info>Hey, <emph>you</emph></info>' # return
st = self.minilang_parser4(test1)
assert not st.error_flag # test1 = '<info>Hey, you</info>'
# st = self.minilang_parser4(test1)
# assert not st.error_flag, str(st.errors_sorted)
# test12 = '<info>Hey, <emph>you</emph></info>'
# st = self.minilang_parser4(test1)
# assert not st.error_flag
test2 = '<info>Hey, you</>' test2 = '<info>Hey, you</>'
set_config_value('history_tracking', True)
set_tracer(self.minilang_parser4, trace_history)
start_logging('LOGS')
st = self.minilang_parser4(test2) st = self.minilang_parser4(test2)
log_parsing_history(self.minilang_parser4, "optional_match")
print(st.as_sxpr())
assert not st.error_flag assert not st.error_flag
test3 = '<info>Hey, <emph>you</></>' # test3 = '<info>Hey, <emph>you</></>'
st = self.minilang_parser4(test3) # st = self.minilang_parser4(test3)
assert not st.error_flag # assert not st.error_flag
test4 = '<info>Hey, <emph>you</></info>' # test4 = '<info>Hey, <emph>you</></info>'
st = self.minilang_parser4(test4) # st = self.minilang_parser4(test4)
assert not st.error_flag # assert not st.error_flag
def test_rollback_behaviour_of_optional_match(self): def test_rollback_behaviour_of_optional_match(self):
test1 = '<info>Hey, you</info*>' test1 = '<info>Hey, you</info*>'
...@@ -831,7 +841,7 @@ class TestPopRetrieve: ...@@ -831,7 +841,7 @@ class TestPopRetrieve:
assert not self.minilang_parser4.variables__['name'] assert not self.minilang_parser4.variables__['name']
assert st.error_flag assert st.error_flag
def test_cache_neutrality(self): def test_cache_neutrality_1(self):
"""Test that packrat-caching does not interfere with the variable- """Test that packrat-caching does not interfere with the variable-
changing parsers: Capture and Retrieve.""" changing parsers: Capture and Retrieve."""
lang = r"""@literalws = right lang = r"""@literalws = right
...@@ -848,6 +858,25 @@ class TestPopRetrieve: ...@@ -848,6 +858,25 @@ class TestPopRetrieve:
st = gr(case) st = gr(case)
assert not st.error_flag, str(st.errors_sorted) assert not st.error_flag, str(st.errors_sorted)
def test_cache_neutrality_2(self):
lang = r'''document = variantA | variantB
variantA = delimiter `X` ::delimiter `!`
variantB = `A` delimiter ::delimiter `!`
delimiter = `A` | `X`
'''
gr = grammar_provider(lang)()
case = 'AXA!'
st = gr(case)
assert not st.errors
case = 'AXX!'
set_config_value('history_tracking', True)
start_logging('LOGS')
set_tracer(gr, trace_history)
st = gr(case)
log_parsing_history(gr, 'test_cache_neutrality_2')
print(st.as_sxpr())
def test_single_line(self): def test_single_line(self):
teststr = "Anfang ```code block `` <- keine Ende-Zeichen ! ``` Ende" teststr = "Anfang ```code block `` <- keine Ende-Zeichen ! ``` Ende"
syntax_tree = self.minilang_parser(teststr) syntax_tree = self.minilang_parser(teststr)
...@@ -1502,3 +1531,4 @@ class TestStaticAnalysis: ...@@ -1502,3 +1531,4 @@ class TestStaticAnalysis:
if __name__ == "__main__": if __name__ == "__main__":
from DHParser.testing import runner from DHParser.testing import runner
runner("", globals()) runner("", globals())
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