【发布时间】:2013-11-27 13:18:06
【问题描述】:
我想创建一个解析字符串和浮点数的提升精神规则。我要解析的字符串格式如下:
(str astring)(n 123)
或者也可以是另一个顺序:
(n 123)(str astring)
我想创建一个具有以下类型属性的规则:
qi::rule<Iter, boost::fusion::vector<std::string, float>, ascii::space_type> hj;
到目前为止,这是我的代码:
qi::rule<Iter, std::string(), ascii::space_type> attr;
attr = lexeme[*alnum];
qi::rule<Iter, boost::fusion::vector<std::string, float>, ascii::space_type> hj;
hj = (
'(' >> lit("str") >> attr(/*put this at position 0*/) >> ')'
|
'(' >> lit("n") >> float_[/*put this at position 1*/] >> ')'
);
显然,这不会编译(boost 扣除了另一种属性类型)。我该如何实现这一点,尤其是我会在注释代码中添加什么?
【问题讨论】:
标签: c++ boost-spirit rule