相关疑难解决方法(0)

Spirit X3,语义操作使编译失败:属性没有预期的大小

此代码不编译(gcc 5.3.1 + boost 1.60):

#include <boost/spirit/home/x3.hpp>

namespace x3 = boost::spirit::x3;

template <typename T>
void parse(T begin, T end) {
    auto dest = x3::lit('[') >> x3::int_ >> ';' >> x3::int_ >> ']';

    auto on_portal = [&](auto& ctx) {};
    auto portal    = (x3::char_('P') >> -dest)[on_portal];

    auto tiles = +portal;
    x3::phrase_parse(begin, end, tiles, x3::eol);
}

int main() {
    std::string x;
    parse(x.begin(), x.end());
}
Run Code Online (Sandbox Code Playgroud)

它失败并带有静态断言:

error: static assertion failed: Attribute does not have the expected size.
Run Code Online (Sandbox Code Playgroud)

感谢wandbox我也尝试了boost 1.61和clang,两者都产生了相同的结果.

如果我删除附加的语义动作portal,它编译得很好; 如果我dest …

c++ boost-spirit boost-spirit-x3

8
推荐指数
1
解决办法
255
查看次数

提升精神X3:"属性没有预期的大小",但它为什么关心?

我正在尝试用Spirit X3编写一个解析器,但我还没有走得太远,因为我遇到了一个我无法弄清楚的编译错误.我想我知道编译器在抱怨什么,但我不明白为什么它会关心.以下代码编译(clang 3.9,Boost 1.62.0)并且有效.(我意识到它的结构很差,并且有常量的内置解析器;我只是试图证明这个问题.)

#define BOOST_SPIRIT_X3_DEBUG

#include <iostream>
#include <boost/spirit/home/x3.hpp>

using namespace std;
namespace x3 = boost::spirit::x3;

namespace lang {

    using namespace x3;

    struct Constant {
    };

    rule<class constant_id, Constant> const constant = "constant";

    auto const integer_literal = -char_('-') >> +digit;
    auto const float_literal = -char_('-') >> +digit >> -(char_('.') >> *digit);

    auto const constant_def = (integer_literal)[([](auto &ctx) { _val(ctx) = Constant(); })];

    BOOST_SPIRIT_DEFINE(constant);
}

int main(int argc, char *argv[]) {

    string s("3.14159");
    if (x3::phrase_parse(s.begin(), s.end(), lang::constant, x3::space)) {
        cout …
Run Code Online (Sandbox Code Playgroud)

c++ boost-spirit boost-spirit-x3

5
推荐指数
0
解决办法
273
查看次数

如何在VS2017中的boost spirit x3中制作递归规则

我在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(); …
Run Code Online (Sandbox Code Playgroud)

c++ boost-spirit-x3 visual-studio-2017

5
推荐指数
1
解决办法
331
查看次数