【发布时间】:2017-02-20 04:52:20
【问题描述】:
正在尝试学习 Boost::Spirit 并希望解决一个 c 样式标识符的简单示例。下面的语法无法编译声明“incompatible_start_rule”。这个语法的目标是返回一个字符串而不是字符串向量,就像默认的属性传播规则那样。
template <typename IT>
struct cppIdentifier : qi::grammar<IT, std::string, space_type()>
{
cppIdentifier() : cppIdentifier::base_type(start)
{
start = char_("a-zA-Z_")[boost::phoenix::push_back(_val, _1)]
>> *(char_("a-zA-Z0-9_")[boost::phoenix::push_back(_val, _1)]);
}
qi::rule<IT, std::string, space_type> start;
};
我必须做什么才能实现这一目标?
另外请注意,我很清楚对于这个特定问题可能有许多替代的、更方便的选择,但我在学术上对如何操作自定义语法的属性类型很感兴趣,所以请将这些留在cmets 而不是答案。
【问题讨论】:
标签: boost boost-spirit-qi