我一直在阅读语义动作,我有一个如下所示的规则:
property_rule %=
identifier_rule % ','
>> lit(L":")
>> type_specification_rule
>> -(lit(L":=") >> +(alnum - ';'))
>> lit(L";");
The property_rule
定义为
qi::rule<Iterator, property(), space_type> property_rule;
现在我也想支持运营商≡
所以我想要的是将规则更改为类似的内容
...
>> -(( lit(L":=") || lit(L"≡")[SEMANTIC_ACTION_HERE]) >> +(alnum - ';'))
...
在语义动作中,我想改变property
正在解析,具体设置其字段is_constant
to true
。该属性适用于 Fusion。我该怎么做?
我会一如既往地避免语义动作(Boost Spirit:“语义行为是邪恶的”? https://stackoverflow.com/questions/8259440/boost-spirit-semantic-actions-are-evil ).
我只是简单地综合一下价值is_constant
在替代方案的两个分支上:
>> -(( lit(L":=") || lit(L"≡")[SEMANTIC_ACTION_HERE]) >> +(alnum - ';'))
会变成:
>> -(
(L":=" >> attr(false) | L"≡" >> ::attr(true)) >> +(alnum - ';')
)
Notes:
- the
lit
是暗示的
- 你可能不想要
||
解析器运算符
- 这假设
is_constant
字段在融合序列中进行调整
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)