[英]Using Boost Spirit's stream parser with custom grammar
我想利用Boost Spirit的流解析器API來逐步解析std::istream
。 但是,我找不到一個如何將它與基於迭代器的語法一起使用的好例子。 從概念上講,我的目標是解析T
類型的無限對象流。
Qi中具有T
類屬性和船長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如何契合?
你錯過了Spirit多次迭代迭代器 。 但請注意,除非您不遺余力地確保您的語法具有最小的回溯,否則將不會逐步完成對流的解析。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.