Re: newbie here ask about qi::_val and semantic action

Yi Leong <[email protected]> Mon, 9 Jul 2018 23:11:11 +0800
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <CAMFq=pZ-K83M8TJE4sJjo+ts_pNkKQ50aUPSw0Y79hnk9LEgZA@mail.gmail.com>
>
>
>
> On Mon, Jul 9, 2018 at 10:44 PM, Seth <[email protected]> wrote:
>
>> On 09-07-18 07:38, Yi Leong wrote:
>> > yeah, in the qi::double_[qi::_val = qi::_1] , the semantic action is a
>> > lambda expression
>>
>> no, that is not a lambda expression
>
>
From this doc,
https://www.boost.org/doc/libs/1_67_0/libs/spirit/doc/html/spirit/qi/quick_reference/phoenix.html
 ,
i thought the placeholder _val is only usable in the lambda expression.🤔


On Mon, Jul 9, 2018 at 10:49 PM, Seth <[email protected]> wrote:

> On 09-07-18 09:17, Yi Leong wrote:
>
> Thanks! I made a mistake about the placeholder,  so the return value in
> the following:
>
>
> double print_action(double f)
> {
>     return f;  // this value will be assigned to the rule r's attribute d?
> }
>
> rule<std::string::const_iterator,  double() > r =
> qi::double_[&print_action];
>
> will be assigned to the rule  r's attribute d?
>
> The confusions are too many.
>
> If the name is `print_action` why does it return a value?
>

Sorry, the function name 'print_action' makes u confused... 😂

And no, you need to assign:
>
>         qi::double_[qi::_val = boost::phoenix::bind(&print_action,
> qi::_1)];
>
> even if you did
>
>
> double modify(double& f)
> {
>     return f *= 2;
> }
>
> rule<std::string::const_iterator,  double() > r = qi::double_[
> boost::phoenix::bind(&modify, qi::_1)];
>
> It would not propagate because automatic propagation is inhibited in the
> presence of semantic actions. The `operator%=` is there to force that:
>
> rule<std::string::const_iterator,  double() > r;
> r %= qi::double_[boost::phoenix::bind(&modify, qi::_1)];
>
>
Thanks! I think i get a little understanding about qi::_val , i need do
further read about it~~😁

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

_______________________________________________
Spirit-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spirit-general