spirit boost : force an attribute on a no-attribute parser

标签 boost boost-spirit

我目前有:

start_ %= listrule_ | primrule_ ;

start_ 的属性是 boost::variant, T>,primrule_ 的属性是 T,listrule_ 的属性是 std::vector。

我相信这是因为 spirit 的“属性传播规则”。

我想添加第三种可能性:

start_ %= listrule_ | primrule_ | '*';

我希望“*”也有 std::vector,并且我会找到一种方法用枚举 T 的所有可能值填充该向量。

归属“*”的语法是什么?

这是 spirit 2,使用 c++11,boost 1.58

最佳答案

使用qi::attr指令

enum MyEnum { A, B, C, D, E };

start_ %= listrule_ 
        | primrule_ 
        | ('*' >> qi::attr(std::vector<MyEnum> { A, B, C, D, E })
        ;

关于 spirit boost : force an attribute on a no-attribute parser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36774312/

相关文章:

c++ - 无法使用 packaged_task 在 thread_group 中创建线程

c++ - C++ 的文件系统迭代器

c++ - 从MAP中的C++文件中读取键值对(Json格式)

c++ - 使用 boost spirit x3 解析为递归变体的问题

c++ - (C++) 为什么 boost 作者在这里使用结构而不是类?

c++ - boost spirit skipper - 编译时错误

c++ - boost::spirit::karma 语义 Action 分配错误

c++ - 如何为用户提供给定boost::spirit语法的自动完成建议?

c++ - 精神振奋 : parsing number char and string

c++ - 位集到动态位集