Improve the spirit of semantic action on qi :: rule

I read semantic actions, and I have a rule that looks like this:

  property_rule %=
    identifier_rule % ','
    >> lit(L":")
    >> type_specification_rule
    >> -(lit(L":=") >> +(alnum - ';'))
    >> lit(L";");

property_rule defined as

qi::rule<Iterator, property(), space_type> property_rule;

Now I also want to support the operator , so I want to change the rule to something like

...
>> -(( lit(L":=") || lit(L"≡")[SEMANTIC_ACTION_HERE]) >> +(alnum - ';'))
...

In semantic action, I want to change the analyzed property, in particular, setting its field is_constantto true. The property is adapted to Fusion. How to do it?

+2
source share
1 answer

I would - as always - avoid semantic action ( Boost Spirit: "Semantic actions are evil," ).

is_constant :

>> -(( lit(L":=") || lit(L"≡")[SEMANTIC_ACTION_HERE]) >> +(alnum - ';'))

:

>> -(
        (L":=" >> attr(false) | L"≡" >> ::attr(true)) >> +(alnum - ';')
    )

:

  • lit
  • , , , ||
  • , is_constant
+2

Source: https://habr.com/ru/post/1677374/


All Articles