【发布时间】:2020-07-24 20:05:04
【问题描述】:
我尝试使用 boost spirit x3 实现一个非常简单的语法,但没有成功。
它无法编译,并且由于库中使用的所有模板和复杂概念(我知道,它是一个“标题”),编译错误消息太长而无法理解。
我试图评论部分代码以缩小罪魁祸首,但没有成功,因为它归结为几个部分,无论如何我没有看到任何错误。
Edit2:第一条错误消息确实在push_front_impl.hpp 中,突出显示:::REQUESTED_PUSH_FRONT_SPECIALISATION_FOR_SEQUENCE_DOES_NOT_EXIST::*
我怀疑关键字auto 或者p2 声明与ulong_long...但没有信心。
需要你们的帮助......精神的精英!
低于重现编译错误的最小代码 sn-p。 编辑:使用 boost 1.70 和 visual studio 2019 v16.1.6
#include <string>
#include <iostream>
#include "boost/spirit/home/x3.hpp"
#include "boost/spirit/include/support_istream_iterator.hpp"
int main(void)
{
std::string input = \
"\"nodes\":{ {\"type\":\"bb\", \"id\" : 123456567, \"label\" : \"0x12023049\"}," \
"{\"type\":\"bb\", \"id\" : 123123123, \"label\" : \"0x01223234\"}," \
"{\"type\":\"ib\", \"id\" : 223092343, \"label\" : \"0x03020343\"}}";
std::istringstream iss(input);
namespace x3 = boost::spirit::x3;
using x3::char_;
using x3::ulong_long;
using x3::lit;
auto q = lit('\"'); /* q => quote */
auto p1 = q >> lit("type") >> q >> lit(':') >> q >> (lit("bb") | lit("ib")) >> q;
auto p2 = q >> lit("id") >> q >> lit(':') >> ulong_long;
auto p3 = q >> lit("label") >> q >> lit(':') >> q >> (+x3::alpha) >> q;
auto node = lit('{') >> p1 >> lit(',') >> p2 >> lit(',') >> p3 >> lit('}');
auto nodes = q >> lit("nodes") >> q >> lit(':') >> lit('{') >> node % lit(',') >> lit('}');
boost::spirit::istream_iterator f(iss >> std::noskipws), l{};
bool b = x3::phrase_parse(f, l, nodes, x3::space);
return 0;
}
【问题讨论】:
-
我无法重现,尝试了多个 Boost 版本,包括开发分支。
-
我看到的第一个错误是this assert in boost::mpl::push_front_impl:“如果你在这里有一个断言,你正在请求一个不存在的'push_front'专业化。”其中 T = boost::mpl::aux::vector_tag。和你看到的一样吗?请至少编辑您遇到的错误的一些指示。
-
@Rup 你在什么平台/版本上看到它?这可能就像特定平台的标头包含遗漏
-
@sehe Windows 10,最近的 VS 2019(16.6.2,比 OP 高几个版本),带有 VS2019 安装的默认 Windows SDK 10.0.18362.0,以及 Boost 1.70.0 以匹配 OP。
标签: c++ visual-c++ boost-spirit boost-spirit-x3