> The transform should act as:
>
> 1/ every rule return a custom Ruby object encapsulating each of it sub-rules 
> as ruby object.
> 2/ all ruby objects should respond to a common "process" function that return 
> the transform result for this object
> 3/ the root rule calls a "process" function on each of its sequence result 
> passing the main scope variable dictionary
> 4/ the B subscope "process" function create the B scope variable dictionary 
> and pass it to the "process" function of each of his encapsulated subtrees 
> object

Sounds to me like you recurse twice. Transformation is already a 
flexible recursion that goes depth first. If you manage to transform 
leaves first and return something that the higher up branches (then 
becoming leaves) can transform, then you're set in one go.

The tutorial (http://kschiess.github.io/parslet/get-started.html) 
includes a graphic of such a tree and a transformation that has the 
interpreted value as a result. Leaf transformation turns strings into 
integers; binary op transformation the computes the result.

Of course you could also just construct an AST that way and then do 
whatever you want with it, including having a recursive #process function.

cheers
k


Reply via email to