此代码不编译(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 …
我正在尝试用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) 我在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)