Commit 63217a52 authored by di68kap's avatar di68kap
Browse files

- DHParser/parse.py/class Alternative: now uses return value optimization

parent e07e8b97
......@@ -1731,8 +1731,10 @@ class Alternative(NaryParser):
for parser in self.parsers:
node, text_ = parser(text)
if node:
return Node(self.tag_name,
node if node._result or parser.pname else ()), text_
return self._return_value(node), text_
# return self._return_value(node if node._result or parser.pname else None), text_
# return Node(self.tag_name,
# node if node._result or parser.pname else ()), text_
return None, text
def __repr__(self):
......
......@@ -30,13 +30,11 @@ Match-test "nested_braces"
<:Token>{</:Token>
<text>
<CONTENT_STRING>\url</CONTENT_STRING>
<:Series>
<:Token>{</:Token>
<text>
<CONTENT_STRING>https://plato.stanford.edu/archives/fall2013/entries/thomas-kuhn/</CONTENT_STRING>
</text>
<:Token>}</:Token>
</:Series>
<:Token>{</:Token>
<text>
<CONTENT_STRING>https://plato.stanford.edu/archives/fall2013/entries/thomas-kuhn/</CONTENT_STRING>
</text>
<:Token>}</:Token>
</text>
<:Token>}</:Token>
</content>
\ No newline at end of file
......@@ -135,7 +135,7 @@ ARITHMETIC_EBNF = """
ARITHMETIC_EBNF_transformation_table = {
# AST Transformations for the DSL-grammar
"formula": [remove_expendables],
"term, expr": [replace_by_single_child, flatten],
"term, expr": [remove_expendables, replace_by_single_child, flatten],
"factor": [remove_expendables, reduce_single_child],
(TOKEN_PTYPE): [remove_expendables, reduce_single_child],
"*": [remove_expendables, replace_by_single_child]
......
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