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

Roman Cheplyaka roma at ro-che.info
Sun Jun 13 17:17:00 EDT 2010

Suppose I have some parser 'p'. I want to parse it as well as get its
span in the text. So I could write

pWithLocation = do
  loc_start <- getPosition
  pval <- p
  loc_end <- getPosition
  return (pval,loc_start,loc_end)

except that loc_end gives me the location _after_ 'p'. In case when 'p'
has consumed trailing newline I see no way to recover the end location
of 'p' (it is the last column of the previous line).

So, can I do anything with this without patching parsec?

I use parsec3 if it matters.

Roman I. Cheplyaka :: http://ro-che.info/
"Don't let school get in the way of your education." - Mark Twain

More information about the Haskell-Cafe mailing list