3
votes

I've been reading up on 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";");

The property_rule is defined as

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

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

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

In the semantic action, I want to change the property that is being parsed, specifically setting its field is_constant to true. The property is Fusion-adapted. How do I do it?

1

1 Answers

3
votes

I would - as ever - avoid the semantic action (Boost Spirit: "Semantic actions are evil"? ).

I'd simply synthesize the value for is_constant on both branches of the alternative:

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

would become instead:

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

Notes:

  1. the lit is implied
  2. you probably do not want || parser operator
  3. this assumes that the is_constant field is adapted in the fusion sequence