Commit 6304da60 authored by Igor Dejanovic's avatar Igor Dejanovic

Small optimization

parent 4392c896
...@@ -186,17 +186,15 @@ class ParsingExpression(object): ...@@ -186,17 +186,15 @@ class ParsingExpression(object):
# Create terminal or non-terminal if result is not # Create terminal or non-terminal if result is not
# already a Terminal. # already a Terminal.
if result and not isinstance(result, Terminal): if self.root and result and not isinstance(result, Terminal):
if parser.reduce_tree: if parser.reduce_tree:
if isinstance(result, list): if isinstance(result, list):
if self.root:
result = flatten(result) result = flatten(result)
if len(result) > 1: if len(result) == 1:
result = NonTerminal(self.rule, c_pos, result)
else:
result = result[0] result = result[0]
else: else:
if self.root: result = NonTerminal(self.rule, c_pos, result)
else:
result = NonTerminal(self.rule, c_pos, result) result = NonTerminal(self.rule, 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