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 11:15:44


On 09/24/2010 04:52 PM, Thomas Heller wrote:
> Roland Bock wrote:
>
>
>> On 09/24/2010 02:33 PM, Roland Bock wrote:
>>
>>> Hi,
>>>
>>> ist there a way to access the grammar that was used to construct an
>>> expression?
>>>
>>> I have defined a metafunction
>>>
>>> template<class Left, class Right>
>>> struct grammar_less: mpl::false_ {};
>>>
>>> which has specialization for some grammar combinations.
>>>
>>> Now I want to define a function that can take two arguments so that
>>>
>>> child0.grammar< child1.grammar
>>>
>>>
>>> Any idea how to do that? My test-code is attached.
>>>
>>>
>>> Regards,
>>>
>>> Roland
>>>
>>>
>> Hi,
>>
>> since I know the structure of the types in question, I can circumvent
>> the problem as shown in the attached code. Not nice, but I could
>> probably use it.
>>
>> Regards,
>>
>> Roland
>>
>
> 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...

> btw: there is a proto specific list: proto_at_[hidden]
>

Thanks for the hint. I guess I'll join when the next question pops up :-)

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