Commit 2dcb24f5 authored by Igor Dejanovic's avatar Igor Dejanovic

Making NonTerminal iterable over its child (Non)Terminals.

parent 5a0e8416
......@@ -63,7 +63,7 @@ def flatten(_iterable):
'''Flattening of python iterables.'''
result = []
for e in _iterable:
if hasattr(e, "__iter__") and not type(e) is str:
if hasattr(e, "__iter__") and not type(e) in [str, NonTerminal]:
result.extend(flatten(e))
else:
result.append(e)
......@@ -565,6 +565,12 @@ class NonTerminal(ParseTreeNode):
def desc(self):
return self.name
def __iter__(self):
return iter(self.nodes)
def __str__(self):
return "[ %s ]" % ", ".join([str(x) for x in self.nodes])
# ----------------------------------------------------
# Semantic Actions
......
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