在qi :: rule上增强精神语义动作 [英] Boost spirit semantic actions on qi::rule
问题描述
我一直在阅读语义动作,并且有一条规则如下:
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";");
property_rule
定义为
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 - ';'))
...
在语义动作中,我想更改正在解析的property
,特别是将其字段is_constant
设置为true
.该属性适用于Fusion.我该怎么办?
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?
推荐答案
我将一如既往地避免语义动作().
I would - as ever - avoid the semantic action (Boost Spirit: "Semantic actions are evil"? ).
我只需在替代方案的两个分支上合成is_constant
的值:
I'd simply synthesize the value for is_constant
on both branches of the alternative:
>> -(( lit(L":=") || lit(L"≡")[SEMANTIC_ACTION_HERE]) >> +(alnum - ';'))
将变为:
>> -(
(L":=" >> attr(false) | L"≡" >> ::attr(true)) >> +(alnum - ';')
)
注意:
- 暗含
lit
- 您可能不希望使用
||
解析器运算符 - 这假定
is_constant
字段在融合序列中已适应
- the
lit
is implied - you probably do not want
||
parser operator - this assumes that the
is_constant
field is adapted in the fusion sequence
这篇关于在qi :: rule上增强精神语义动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!