So erstellen Sie eine rekursive Regel in Boost Spirit x3 in VS2017

Lesezeit: 2 Minuten

Ich habe die folgende rekursive Regel in boost::spirit::x3 geschrieben, aber sie scheint nur in g++/clang zu kompilieren, nicht in 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++

Wie mache ich das in VS2017 (wenn möglich)?

PS: Platform Toolset ist auf v141 eingestellt, ISO-Standard ist auf C++17 eingestellt, Boost-Version ist 1.66.0

PPS: Die Kompilierungsfehler sind wie folgt

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'

  • Es ist ein Bug in Spirit. Hier ist die Lösung: github.com/boostorg/spirit/commit/…

    – Henri Menke

    23. Januar 2018 um 2:42 Uhr

  • Das scheint der Fall zu sein. Wenn Sie das zu einer Antwort machen, werde ich morgen früh positiv abstimmen / akzeptieren.

    – Borgführer

    23. Januar 2018 um 2:59 Uhr

Ich habe das Boost.Spirit-Repository auf GitHub ausgecheckt, weil meine lokale Version zu alt war, und festgestellt, dass Ihr Beispiel mit der neuesten Version gut kompiliert werden kann develop Zweig, aber nicht mit der Version 1.66.0 (auch auf Clang und GCC). Die Halbierung des Commit-Verlaufs ergab, dass dieser Fehler behoben wurde

ee4943d5891bdae0706fb616b908e3bf528e0dfa

Sie können entweder den Patch von diesem Commit auf Ihre Installation anwenden oder auf die nächste Version warten.

1012450cookie-checkSo erstellen Sie eine rekursive Regel in Boost Spirit x3 in VS2017

This website is using cookies to improve the user-friendliness. You agree by using the website further.

Privacy policy