我有一个非常简单的语法,尝试使用Boost Spirit x3实现,但没有成功。
它不会编译,并且由于库中使用了所有模板和复杂的概念(我知道,它是一个“ header ”),因此编译错误消息太长了,无法理解。
我试图注释部分代码,以便缩小罪魁祸首,但没有成功,因为它归结为几个部分,无论如何我都看不到任何错误。
Edit2 :第一个错误消息确实在push_front_impl.hpp中,突出显示:::REQUESTED_PUSH_FRONT_SPECIALISATION_FOR_SEQUENCE_DOES_NOT_EXIST::*我怀疑关键字auto或带有p2ulong_long语句...,但没有信心。
需要你们的帮助...精神精英!
在最小的代码片段下面,再现了编译错误。
编辑:使用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;
}

最佳答案

这是已知的MPL限制(Issue with X3 and MS VS2017https://github.com/boostorg/spirit/issues/515)+ MSVC / ICC编译器(https://github.com/boostorg/mpl/issues/43)的实现错误/差异。
我改写了不使用MPL(https://github.com/boostorg/spirit/pull/607)的有问题的部分,它将在Boost 1.74中发布,直到那时您应该可以解决:

#define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
#define BOOST_MPL_LIMIT_VECTOR_SIZE 50
或者,您可以将语法的不同部分包装成规则,这将减少序列分析器链。

注意q >> lit("x") >> q >> lit(':') >> ...可能不是您真正想要的,它(带有一个船长)将允许解析" x ":。如果您不希望这样,只需使用lit("\"x\"") >> lit(':') >> ...

关于c++ - 简单X3语法的难以理解的编译错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/63080719/

10-13 06:31