4

あらすじ

Boost Spirit のストリーム パーサー APIを利用して、段階的に解析したいと思いstd::istreamます。ただし、反復子ベースの文法で使用する方法の良い例を見つけることができませんでした。概念的には、私の目標は type のオブジェクトの無限ストリームを解析することですT

詳細

Ttypeと skipperの属性を持つ Qi の文法は、S通常、次の形式を持ちます。

template <typename Iterator>
struct grammar : qi::grammar<Iterator, T(), S>;

ストリームベースの API でこのような文法を使用するにはどうすればよいですか? 具体的には、ストリーム API に関する私のメンタル モデルは、次のようなことができるというものです。

// Callback invoked for each successfully parsed instance of T.
void f(T const& x)
{
}


// What iterator type?
grammar<???> parser;
skipper<???> skipper;

T x;

std::ifstream ifs("/path/to/file");
ifs.unsetf(std::ios::skipws)
while (! ifs.eof())
{
    ifs >> phrase_match(parser, skipper, x);
    if (ifs.good() || ifs.eof())
        f(x);
}

イテレータを必要とする従来の文法をまとめるのに苦労しています。それはストリーム API とどのように適合しますか?

4

1 に答える 1

3

You're missing the Spirit multi-pass iterator. Note, however, that parsing of the stream will not be done incrementally unless you go out of your way to make sure your grammar has minimal backtracking.

于 2012-04-27T20:56:49.493 に答える