Hi again,
I have a problem I'm not quite able to solve on myself, pruning Nodes that only contain other, single Nodes in the AST, so that the innermost single Node gets "promoted" to the top. Let's take the Nodes example on the webpage (bottom):
http://www.acooke.org/lepl/nodes.htmlThere we see the following AST from the expression "1 + 2 * (3 + 4 - 5)", modified with dropped spaces and parenthesis:
Expression
+- Factor
| +- Term
| | `- number '1'
+- operator '+'
`- Factor
+- Term
| `- number '2'
+- operator '*'
`- Term
+- Expression
+- Factor
| +- Term
| | `- number '3'
+- operator '+'
+- Factor
| +- Term
| | `- number '4'
+- operator '-'
`- Factor
+- Term
| `- number '5'
Now, this is rather verbose... I'd like to get rid of all Nodes that contain only single child nodes, to arrive at the following tree:
Expression
+- Term
| `- number '1'
+- operator '+'
`- Factor
+- Term
| `- number '2'
+- operator '*'
`- Term
+- Expression
+- Term
| `- number '3'
+- operator '+'
+- Term
| `- number '4'
+- operator '-'
`- Term
| `- number '5'
This doesn't seem like something very sophisticated, but I don't see a way this is simply done with LEPL, or at least am not able to deduce it from the API and manual. Any hints? Maybe I need to walk the tree and prune it manually?I'm a bit lost ATM, so any help would be much appreciated! Thanks!
--Florian