Joel FALCOU | 3 Jul 20:44
Gravatar

Creating new operators & function under proto

Hi,

I tried follwoing the tutorial to create new functions to use in Proto 
but it failed.
Let's say I want to have a new unary function called worker that create 
an expression
that ought to be matched by the following grammar :

struct worker_grammar : or_< terminal< user_func<_> >, function< 
worker_tag, terminal< user_func<_> > > {};
I keep getting a 'no type named proto_expr_base in worker_tag' error.

Related question, how can I make a new function which tag is a tempalte 
class whose tempalte parameter is used to change how the associated 
transform is performed, I tried :

struct worker_grammar : or_< terminal< user_func<_> >, function< 
worker_tag<_>, terminal< user_func<_> > > {};
but it failed too.

Thanks in advance

--

-- 
Joel FALCOU
Research Engineer @ Institut d'Electronique Fondamentale
Université PARIS SUD XI
France 
Eric Niebler | 3 Jul 20:59

Re: Creating new operators & function under proto

Joel FALCOU wrote:
> Hi,
> 
> I tried follwoing the tutorial to create new functions to use in Proto 
> but it failed.
> Let's say I want to have a new unary function called worker that create 
> an expression
> that ought to be matched by the following grammar :
> 
> struct worker_grammar : or_< terminal< user_func<_> >, function< 
> worker_tag, terminal< user_func<_> > > {};
> I keep getting a 'no type named proto_expr_base in worker_tag' error.

Right, because unless "worker_tag" is a proto expression or a proto 
grammar, it cannot be a parameter to proto::function<>. The grammar 
function<A,B> will match a binary expression with tag::function and 
where the first child matches A and the second child matches B.

You might get a little farther with something like this:

   terminal<worker_tag>::type const worker = {{}};

Now you can say:

   worker('a')

and it will generate an expression that matches the grammar:

   function<terminal<worker_tag>, _>

(Continue reading)

Joel FALCOU | 3 Jul 22:06
Gravatar

Re: Creating new operators & function under proto

Eric Niebler a écrit :
> <snipped useful tips>
>
Ah OK, I thought function<> was able to match any kind of tag as its 
first argument, so my confusion.
I got it working thanks a lot.

--

-- 
Joel FALCOU
Research Engineer @ Institut d'Electronique Fondamentale
Université PARIS SUD XI
France 

Gmane