在qi :: rule上增强精神语义动作 [英] Boost spirit semantic actions on qi::rule

查看:98
本文介绍了在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 - ';')
    )

注意:

  1. 暗含lit
  2. 您可能不希望使用||解析器运算符
  3. 这假定is_constant字段在融合序列中已适应
  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

这篇关于在qi :: rule上增强精神语义动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆