这也让我感到惊讶,我会在邮件列表(或错误跟踪器)中将其报告为潜在错误。
同时,您可以通过提供属性类型来“修复”它dest
:
Live On Coliru http://coliru.stacked-crooked.com/a/a3cd74712555bfdb
#include <boost/fusion/adapted/std_tuple.hpp>
#include <boost/spirit/home/x3.hpp>
#include <iostream>
namespace x3 = boost::spirit::x3;
template <typename T>
void parse(T begin, T end) {
auto dest = x3::rule<struct dest_type, std::tuple<int, int> > {} = '[' >> x3::int_ >> ';' >> x3::int_ >> ']';
auto on_portal = [&](auto& ctx) {
int a, b;
if (auto tup = x3::_attr(ctx)) {
std::tie(a, b) = *tup;
std::cout << "Parsed [" << a << ", " << b << "]\n";
}
};
auto portal = ('P' >> -dest)[on_portal];
auto tiles = +portal;
x3::phrase_parse(begin, end, tiles, x3::eol);
}
int main() {
std::string x = "P[1;2]P[3;4]P[5;6]";
parse(x.begin(), x.end());
}
Prints:
Parsed [1, 2]
Parsed [3, 4]
Parsed [5, 6]
NOTE我变了char_('P')
进入刚刚lit('P')
因为我不想使处理属性中的字符的示例变得复杂。无论如何,也许您并不打算将其包含在公开属性中。