Boost logo

Boost Users :

Subject: Re: [Boost-users] [Proto] How to access the grammar of an expression?
From: Roland Bock (rbock_at_[hidden])
Date: 2010-09-24 13:49:36


On 09/24/2010 07:35 PM, Eric Niebler wrote:
> On 9/24/2010 11:15 AM, Roland Bock wrote:
>
>> On 09/24/2010 04:52 PM, Thomas Heller wrote:
>>
>>> you can compute that type information directly in your proto transform:
>>>
>>> struct sorted_argument_function:
>>> proto::and_
>>> <
>>> proto::function<fun_terminal, proto::_, proto::_>,
>>> proto::if_
>>> <
>>> grammar_less<
>>> proto::_value(proto::_child0(proto::_child1))
>>> , proto::_value(proto::_child0(proto::_child2))>()
>>> >
>>> >
>>> {};
>>>
>> OK, admittedly, that looks a lot nicer, but in case I call something like
>>
>> fun(b(0), 42));
>>
>> the error messages are just horrible in both solutions...
>>
> The proto::and_ has two branches: proto::function and proto::if_.
>
> The proto::if_ is assuming:
>
> 1. That there are at least three child nodes
> 2. That child1 and child2 themselves have a child
> 3. That the child nodes of child1 and child2 are terminals
>
> The proto::function has only verified the first of these assumptions.
> You need to change it to validate the other two as well:
>
>
> struct function_argument
> : proto::function<proto::terminal<proto::_>, proto::_>
> {};
>
> struct sorted_argument_function
> : proto::and_
> <
> proto::function
> <
> fun_terminal,
> function_argument,
> function_argument
> >,
> proto::if_
> <
> grammar_less
> <
> proto::_value(proto::_child0(proto::_child1))
> , proto::_value(proto::_child0(proto::_child2))
> >()
> >
> >
> {};
>
> HTH,
>
Yes, that helps a lot! Very cool.

Sigh, seeing it, it suddenly seems so obvious, at least after Thomas
showed the

proto::_value(proto::_child0(proto::_child1))

Thanks and regards,

Roland


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net