Re: [proto] Manipulating an expression tree

2011-05-01 Thread Eric Niebler
On 4/15/2011 10:45 PM, Karsten Ahnert wrote:
 @All: Are somewhere more examples and docs for proto transforms. They
 are quite complicated and maybe a bit underrepresented in the official
 users guide.

(Funny, I *know* I replied to this, but I don't see it in the archive.
Sorry if y'all get this twice.)

Have you read the Expressive C++ article series on C++Next? It covers
grammars and transforms step-by-step. Here's the first one in the series:

http://cpp-next.com/archive/2010/08/expressive-c-introduction/

HTH,

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com
___
proto mailing list
proto@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/proto


Re: [proto] Using Phoenix inside eUML: mixing grammars

2011-05-01 Thread Thomas Heller
On Monday, April 25, 2011 06:39:14 PM Christophe Henry wrote:
 Hi Thomas,
 
 Sorry to come back to the subject so late, I didn't manage before :(
 
  If you want to use it as a transform you need the evaluator with an
  appropriate action that does the desired transform... here is an
  example:
 
  struct BuildEventPlusGuard
   : proto::when
   proto::subscriptproto::terminalevent_tag,
  phoenix::meta_grammar ,
   TempRownone,proto::_left,none,none,
  phoenix::evaluator(proto::_right, some_cool_action())()
   
  {};
 
  Now, some_cool_action can do the transform that BuildGuards was doing.
 
 Hmmm, I get a compiler error, which was expected (would be too easy
 otherwise ;- ) ), but the error is surprising. The error is that
 phoenix::evaluator seems to believe some_cool_action should be a
 random access fusion sequence (expects an environment?).

You are right ... slippery on my side ... evaluator expects a context, which is 
a tuple containing the environment and the actions: http://goo.gl/24fU9

 Anyway, I am hoping not to write any cool transform but simply save
 the type of the phoenix expression so that I can re-create an actor
 later. If I need to rewrite differently what BuildGuards was doing, I
 gain little. I would like phoenix to do the grammar parsing and
 building of actor.

It does ... just pass on proto::_right and it should be good:

struct BuildEventPlusGuard
  : proto::when
proto::subscript
proto::terminalevent_tag
  , phoenix::meta_grammar  // match the phoenix actor

  , TempRow
none
  , proto::_left
  , none
  , none
  , proto::_right // Pass the type along. which is a phoenix actor.
(proto::_right)  // Pass the object along. Which is the actor (1)

{};

(1): Here you can work around the thing with the possibly uninitialized stuff. 
Just copy the phoenix actor (should be cheap, if not optimized away completely).

 Thanks,
 Christophe
___
proto mailing list
proto@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/proto