Spirit: a skip parser that counts newlines?

Hi, 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?) 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? I'm guessing I'd have to supply this as a custom skip parser to the parse method? Thanks for any clues. -- Regards, Steve.

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
participants (2)
-
hartmutkaiser@t-online.de
-
Steve Folly