[Haskell-cafe] parsec: how to get end location

David Virebayre dav.vire+haskell at gmail.com
Sun Jun 13 19:08:33 EDT 2010

On Mon, Jun 14, 2010 at 12:10 AM, Roman Cheplyaka <roma at ro-che.info> wrote:
> Of course most parsers don't consume trailing newlines. But I was
> writing general function to use in many places in the code which would
> recover the end location. In most cases it just subtracts 1 from the
> column number, but what if it just happened so that column number is 1?

Parsec can handle state, right ? You could modify the parsers for
white space so they record the beginning position in some state. ( In
a maybe )
Then, modify parseWithLocation to set the state position to nothing,
parse p then if no position has been recorded in the state , use the
current position, else use the position in the state.

Excuse me if this is unclear or confused, it's late :)


More information about the Haskell-Cafe mailing list