【问题标题】:How to make a recursive rule in boost spirit x3 in VS2017如何在VS2017的boost Spirit x3中制定递归规则
【发布时间】:2018-01-23 01:49:50
【问题描述】:

我在 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 link, clang++

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

P.S:Platform Toolset 设置为 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'

【问题讨论】:

标签: c++ visual-studio-2017 boost-spirit-x3


【解决方案1】:

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

ee4943d5891bdae0706fb616b908e3bf528e0dfa

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多