如何在VS2017中在提升精神x3中制定递归规则

How to make a recursive rule in boost spirit x3 in VS2017

本文关键字:x3 递归 规则 VS2017      更新时间:2023-10-16

我在boost::spirit::x3中编写了以下递归规则,但它似乎只在g ++/clang中编译,而不是VS2017(15.5.3(:

#include <iostream>
#include <boost/spirit/home/x3.hpp>
namespace lex3
{
    namespace x3 = boost::spirit::x3;
    x3::rule<struct foo_class> const foo = "foo";
    x3::rule<struct bar_class> const bar = "bar";
    auto bar_def = *((x3::char_ - "/*") - "*/") >> *(foo > *((x3::char_ - "/*") - "*/"));
    auto foo_def = "/*" > bar > "*/";
    BOOST_SPIRIT_DEFINE(foo)
    BOOST_SPIRIT_DEFINE(bar)
}
int main(int argc, char** argv)
{
    std::string input = "/* a /* nested */ comment */";
    auto f = input.begin();
    auto l = input.end();
    if (parse(f, l, lex3::foo) && (f == l))
        std::cout << "Parse success.n";
    else
        std::cout << "Parse failure (remainder: " << std::string(f, l) << ").n";
    return 0;
}

Coliru link, g++

Coliru 链接,叮当++

如何在VS2017中完成这项工作(如果可能(?

P.S:平台工具集设置为v141,ISO标准设置为C++17,boost版本设置为1.66.0

P.P.S:编译错误如下

error C2039: 'insert': is not a member of 'boost::spirit::x3::unused_type'
note: see declaration of 'boost::spirit::x3::unused_type'
error C2039: 'end': is not a member of 'boost::spirit::x3::unused_type'
note: see declaration of 'boost::spirit::x3::unused_type'
error C2039: 'begin': is not a member of 'boost::spirit::x3::unused_type'
note: see declaration of 'boost::spirit::x3::unused_type'

我查看了GitHub上的Boost.Spirit存储库,因为我的本地版本太旧了,并注意到您的示例在最新的develop分支上编译良好,但在1.66.0版本(也在Clang和GCC上(上编译不行。 将提交历史记录一分为二显示此错误已在

ee4943d5891bdae0706fb616b908e3bf528e0dfa

您可以将此提交的修补程序应用到安装中,也可以等待下一个版本。