Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
359 views
in Technique[技术] by (71.8m points)

c++ - How to make a recursive rule in boost spirit x3 in VS2017

I've written the following recursive rule in boost::spirit::x3 but it only seems to compile in g++/clang, not 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.
";
    else
        std::cout << "Parse failure (remainder: " << std::string(f, l) << ").
";

    return 0;
}

Coliru link, g++

Coliru link, clang++

How do I make this work in VS2017 (if possible)?

P.S: Platform Toolset is set to v141, ISO standard is set to C++17, boost version is 1.66.0

P.P.S: The compilation errors are as follows

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'
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I checked out the Boost.Spirit repository on GitHub because my local version was too old and noticed that your example compiles fine with the latest develop branch but not with the 1.66.0 release (also on Clang and GCC). Bisecting the commit history revealed that this bug was fixed in

ee4943d5891bdae0706fb616b908e3bf528e0dfa

You could either apply the patch from this commit to your installation or wait for the next release.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...