6

我试图找出从istream使用 x3 解析的正确方法。较旧的文档引用了multi_pass一些东西,我还可以使用它吗?或者是否有其他方法可以为 X3 缓冲流以便它可以回溯?

4

1 回答 1

7

你仍然可以使用这个。只包括

#include <boost/spirit/include/support_istream_iterator.hpp>

例子Live On Coliru

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

int main() {
    std::istringstream iss("{ 123, 234, 345, 456, 567, 678, 789, 900, 1011 }");
    boost::spirit::istream_iterator f(iss), l;

    std::vector<int> values;

    namespace x3 = boost::spirit::x3;

    if (x3::phrase_parse(f, l, '{' >> (x3::int_ % ',') >> '}', x3::space, values)) {
        std::cout << "Parse results:\n";
        for (auto v : values) std::cout << v << " ";
    } else
        std::cout << "Parse failed\n";
}

印刷

Parse results:
123 234 345 456 567 678 789 900 1011 
于 2016-05-06T20:36:09.773 回答