Imagine the following types of strings:
if ((a1 and b) or (a2 and c)) or (c and d) or (e and f)
Now, I\'d like to get the expressions in pa
If you only want to return each outermost factor, return early and do not descend into its children.
def walk(node, level = 0):
if node.expr.name == "factor":
print(level * "-", node.text)
return
for child in node.children:
walk(child, level + 1)
Output:
----- ((a1 and b) or (a2 and c))
----- (c and d)
------ (e and f)