Thanks for the precisions.

As I wanted to implement multiple variable scopes levels in the grammar, the 
deepest leaves cannot be processed before knowing the scope set in it higher 
branch.

For example considering the following ruby code:
===
data = [ [1,2], [3,4], [5,6] ]
data.each do |array_values|
  array_values.each do |value|
    p value + 1
  end
end
===

The deepest leave, and then the one transformed first should be "p value + 5" 
but its result is dependent to the binding of "value" that is dependent to the 
binding of "array_data" that is dependent to the binding of "data".

So for this case I chose the AST solution, as hinted by Nigel, as it seemed 
the easiest way to achieve multiple scopes handling.

Thanks again for all the valuable informations!

Cheers,
Eric

On 2013年7月1日 月曜日 11:16:45 Kaspar Schiess wrote:
> > 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
-- 
Eric Sagnes
サニエ エリック

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to