【问题标题】:Pass symbol table as inherited attribute to boost spirit rule传递符号表作为继承属性来提升精神规则
【发布时间】:2016-03-14 06:39:58
【问题描述】:

我有几个要禁止部分匹配的符号表。

阅读了一些问题,我认为可以使用distinct directive 来完成。

但是,每次在语法中引用符号表时添加distinct(char_("a-zAZ09_"))[no_case[my_symb_1]]; 会降低可读性。所以我尝试制定一个接受符号表并返回其匹配值的规则:

qi::rule<Iterator, Operation(const qi::symbols<char, Operation>&)> no_partial_match;

no_partial_match %= distinct(char_("a-zAZ09_"))[no_case[lazy(_r1)]];

并在后面的语法中使用:

some_rule = no_partial_match(my_symb_1) >> int_;

但它失败了:

    const boost::spirit::qi::symbols<char,Operation,boost::spirit::qi::tst<Char,T>,boost::spirit::qi::tst_pass_through>::adder
 &boost::spirit::qi::symbols<Char,T,boost::spirit::qi::tst<Char,T>,boost::spirit::qi::tst_pass_through>::adder::operator
 ()(const Iterator &,const Iterator &,const T &) const': expects 3 arguments - 1 provided

如何做到这一点?

(PS:我知道 cmets here 中提供的通用解决方案,但我正在为这个特定的符号表签名寻找一种更简单的方法,而不是通用的。 )

【问题讨论】:

    标签: c++ boost-spirit


    【解决方案1】:

    知道了,必须将符号表包装在phx::ref(...)中

    喜欢这个

    some_rule = no_partial_match(phx::ref(my_symb_1)) >> int_;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多