Boost logo

Boost Users :

From: Hartmut Kaiser (hartmutkaiser_at_[hidden])
Date: 2004-02-09 14:28:51


Steve Folly wrote:

> Before I launch into it, does anybody have an example of a
> parser that can count newlines. I would have thought this
> would be quite common, so I'm surprised to see it's not
> standard within Spirit? (Or maybe I didn't look hard enough?)

Spirit _has_ a feature, which allows to track the current position in the
input stream: the position_iterator. It's a wrapper around any other (at
least input-) iterator. It keeps track not only of the line number but also
of the current column number (when used as configured by default).

> I'm writing a parser which will parse multi-line files. I'd
> like to report an error along with a line number. I realise
> the error can't be detailed - e.g. what the parser expected,
> rather, just 'an error' - which why I'd like the line number
> to at least give the user a fighting chance. I assume the
> parser simply stops at the point where parsing failed, and
> thus I'd know the line number?

You may use the Spirit error parsers to control error handling in more
detail, so it is possible to detect, what's actually goes wrong. Please see
the docs for more details.

> I'm guessing I'd have to supply this as a custom skip parser
> to the parse method?

Yes, in the simplest case you may use a skip parser, which counts the
newlines skipped.

Regards Hartmut


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net