Commit 8609d13a authored by Igor Dejanovic's avatar Igor Dejanovic

Change the way non-terminals are created in the parse method

parent 16a0e2e5
...@@ -245,17 +245,18 @@ class ParsingExpression(object): ...@@ -245,17 +245,18 @@ class ParsingExpression(object):
if parser.debug: if parser.debug:
print("<< Leaving rule {}".format(self.name)) print("<< Leaving rule {}".format(self.name))
# Create terminal or non-terminal if result is not # For root rules flatten non-terminal/list
# already a Terminal.
if self.root and result and not isinstance(result, Terminal): if self.root and result and not isinstance(result, Terminal):
if parser.reduce_tree: if not isinstance(result, NonTerminal):
if isinstance(result, list): result = flatten(result)
result = flatten(result)
if len(result) == 1: # Tree reduction will eliminate Non-terminal with single child.
result = result[0] if parser.reduce_tree and len(result) == 1:
else: result = result[0]
result = NonTerminal(self, c_pos, result)
else: # If the result is not parse tree node it must be a plain list
# so create a new NonTerminal.
if not isinstance(result, ParseTreeNode):
result = NonTerminal(self, c_pos, result) result = NonTerminal(self, c_pos, result)
# Result caching for use by memoization. # Result caching for use by memoization.
......
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