Boost logo

Proto :

Subject: Re: [proto] Thoughts on traversing proto expressions and reusing grammar
From: joel falcou (joel.falcou_at_[hidden])
Date: 2010-10-07 17:08:44

On 07/10/10 23:06, Eric Niebler wrote:
> On 10/4/2010 1:55 PM, Eric Niebler wrote:
>> The idea of being able to specify the transforms separately from the
>> grammar is conceptually very appealing. The grammar is the control flow,
>> the transform the action. Passing in the transforms to a grammar would
>> be like passing a function object to a standard algorithm: a very
>> reasonable thing to do. I don't think we've yet found the right
>> formulation for it, though. Visitors and tag dispatching are too
>> ugly/hard to use.
>> I have some ideas. Let me think some.
> Really quickly, what I have been thinking of is something like this:
> template<class Transforms>
> struct MyGrammar
> : proto::or_<
> proto::when< rule1, typename Transforms::tran1>
> , proto::when< rule2, typename Transforms::tran2>
> , proto::when< rule3, typename Transforms::tran3>
> >
> {};
> That is, you parameterize the grammar on the transforms, just the way
> you parameterize a std algorithm by passing it a function object. Each
> grammar (I'm thinking of starting to call Proto grammars+transforms
> "Proto algorithms", because really that's what they are) must document
> the concept that must be satisfied by its Transforms template parameter
> (what nested typedefs must be present).
> This is extremely simple and terse. It gives a simple way to extend
> behaviors (by deriving from an existing Transforms model and hiding some
> typedefs with your own).
> I know this is not general enough to meet the needs of Phoenix, and
> possibly not general enough for NT2, but I just thought I'd share the
> direction of my thinking on this problem.
I've decided that th ebest way to advance this issue is to use curren
tthomas stuff in the
current nT2 development and see what use case arise from my twisted code
base and see
how it can go.

Proto list run by eric at