Boost logo

Proto :

Subject: Re: [proto] Thoughts on traversing proto expressions and reusing grammar
From: Eric Niebler (eric_at_[hidden])
Date: 2010-10-07 17:06:24


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.

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com

Proto list run by eric at boostpro.com