Boost logo

Proto :

Subject: Re: [proto] Thoughts on traversing proto expressions and reusing grammar
From: Thomas Heller (thom.heller_at_[hidden])
Date: 2010-10-13 01:41:43


On Tuesday 12 October 2010 22:24:25 Eric Niebler wrote:
> On 10/4/2010 10:57 PM, Thomas Heller wrote:
> > Eric Niebler wrote:
> >> On 10/4/2010 12:20 PM, Thomas Heller wrote:
> >>> the new thing i added is transform_expr, which works like
> >>> fusion::transform: It creates the expression again, with transformed
> >>> child nodes (the child nodes get transformed according to the
> >>> transform you specify as template parameter
> >>
> >> How is that different than what the pass_through transform does?
> >
> > It works slightly different than pass_through:
> >
> > transform_expr calls
> > when<_, Fun>::template impl<typename result_of::child_c<Expr, N>::type,
> > State, Data>
> > while pass_through calls
> > Grammar::proto_childN::template impl<typename result_of::child_c<Expr,
> > N>::type, State, Data>
> >
> > Truth is, I could not see how I could use pass_through to do what I
> > wanted, and still fail to see what pass_through really does. Another
> > truth is, that i initially wanted to call transform_expr pass_through
> > until I realized that it is already there.
> > Perhaps you can sched some light on why pass_through is implemented
> > that way.
>
> Getting caught up on this discussion and realized I never responded to
> this.
>
> It seems to me that:
>
> transform_expr< Fun >
>
> is equivalent to:
>
> nary_expr< _, vararg< when<_,Fun> > >
>
> with some extra handling for terminals. (The default transform of the
> nary_expr grammar is implemented in terms of pass_through.)
> Transform_expr applies the Fun transform to terminals also, but
> pass_through doesn't do anything to terminals. That's because, in my
> experience, transforms that work for non-terminals rarely work as-is for
> terminals. Is your experience different?

IMHO, transforms should handle every part of the expression, including
terminals. Terminals are often neglected and not handled correctly, that is
true, but they should. When evaluating proto expression you usually are not
interested in the terminal (as in terminal<_>) itself, but in the value (as
in _value(terminal<_>). That is why i decided to include application to
terminals.
It is however interesting that some pre built transforms handle terminals
(like _default) and others not (like pass_through).

<snip>


Proto list run by eric at boostpro.com