Re: parsing a stream
Patrick Welche <[email protected]> Thu, 5 Jul 2018 15:32:30 +0100
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <20180705143230.GC7937@quartz> |
On Wed, Jul 04, 2018 at 08:30:11PM +0200, Seth wrote:
> On 04-07-18 15:59, Patrick Welche wrote:
> > Rather than read a huge document, and then parse it, is there a way of
> > reading chunks and pushing them through the parser,
> Yes.
Great - any clue on how?
> > even though no one chunk on its own will be valid?
>
> I'm not sure what you mean here.
>
> Perhaps you can supply an example.
Simply, this works:
========================================================================
#include <iostream>
#include <string>
#include <boost/spirit/home/x3.hpp>
namespace x3 = boost::spirit::x3;
int main()
{
std::string in("1 a 1.2 b");
std::string::const_iterator iter = in.begin(), end = in.end();
bool ok = x3::phrase_parse(
iter, end,
x3::int_ >> x3::char_ >> x3::double_ >> x3::char_,
x3::ascii::space
);
if (!ok)
std::cout << "Parsing failed\n";
else if (iter != end)
std::cout << "Bit left over at the end: "
<< std::string(iter, end) << std::endl;
else
std::cout << "Success!\n";
return 0;
}
========================================================================
but if I say, "iter, iter+3" then parsing will fail, and I can't carry
on with iter (now pointing to iter+3), end, i.e., try to split the tiny
string into 2 and do 2 batches.
Cheers,
Patrick
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot