聚合Boost.灵气解析为规则间接产生错误
aggregating Boost.Spirit Qi parsers into rule indirectly gives error
我有这个语法
template<typename Iterator>
struct brainDSL : qi::grammar<Iterator, _problem(), ascii::space_type>
{
brainDSL() : base_type(p_rule)
{
p_rule = problem_;
}
qi::rule<Iterator, _problem(), ascii::space_type> p_rule;
};
这些是解析器:
struct type_ : qi::symbols<char, _problem::_type>
{
type_()
{
add
("single_stage", _problem::_type::single_stage)
("two_stage", _problem::_type::two_stage)
("multi_stage", _problem::_type::multi_stage)
;
}
} type_;
struct command_ : qi::symbols<char, _problem::_command>
{
command_()
{
add
("maximize", _problem::_command::maximize)
("minimize", _problem::_command::minimize)
;
}
} command_;
auto name_ = qi::lexeme[*(qi::char_ - ':')];
auto problem_ =
type_
>> command_
>> name_ >> ':'
;
我会添加structs和fusion宏,但我认为没有必要。对测试字符串执行此操作,此代码可以正确编译,但在boost内部引发异常。
如果我删除name_
解析器并将problem_
保留为这样:
auto problem_ =
type_
>> command_
;
它匹配正确。但如果我添加任何内容,即使是qi::eps
,我也会再次得到异常:
auto problem_ =
type_
>> command_
>> qi::eps
;
我在这里违反了Boost Spirit的基本规则是什么?
为了不让问题得到解答,我还将添加一些关于解决后条件的注释。
最好的解决方案是改用Spirit X3,它完全支持使用auto
和lambdas,正如@sehe所建议的那样。
我必须做出的几个重大改变:
symbols
现在只接受一个模板参数,即它映射的类型- X3没有语法,只有规则
- 下面的教程建议使用宏来定义规则。这在MSVC上是个坏主意,最好只使用构造然后定义
示例:
auto r = rule<...> { "Name" }
= definition;
相关文章:
- 使用 bazel 从源代码构建张量流服务遇到错误:C++规则'@org_tensorflow//…'编译失败(出口 4)
- 错误“没有规则实现目标……”
- 将规则生产绑定到我的结构成员时出现编译错误
- 一般规则:C/C++中错误代码的负值或正值
- 生成文件失败,错误没有规则来设定目标
- 仅当我提供类型检查规则时才"No type checking rule"错误
- make:没有规则来设定目标.日食错误
- 在给定一组规则的情况下检查罗马数字的错误
- 错误:"混合的隐式和静态模式规则"在我的生成文件中
- 一般生成文件显示没有规则来生成目标错误
- 升灵气:轻微规则变化的编译错误
- C++年复合辛普森规则中的错误
- C++生成文件错误:没有要设为目标的规则
- 提升::精神::QI规则减少解析错误
- LNK2005错误,已定义:可能有一个定义规则违反
- boost::spirit::qi具有相同的简单自适应结构属性的规则会导致编译错误
- 没有规则来使目标"类.cpp,"构建/..."需要x86/class.o' 停止。乌班图中的错误
- 聚合Boost.灵气解析为规则间接产生错误
- Android Ndk错误没有规则使目标
- c++如何设置更严格的异常(错误)规则