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

Antoine Latter aslatter at gmail.com
Sun Jun 13 17:47:28 EDT 2010

On Sun, Jun 13, 2010 at 4:17 PM, Roman Cheplyaka <roma at ro-che.info> wrote:
> Suppose I have some parser 'p'. I want to parse it as well as get its
> span in the text. So I could write
> \begin{code]
> pWithLocation = do
>  loc_start <- getPosition
>  pval <- p
>  loc_end <- getPosition
>  return (pval,loc_start,loc_end)
> \end{code}
> 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.

Can you use a parser which doesn't consume leading/trailing whitespace?

Or somehow layer the parsers so that the whitepsace munching happens
outside of parseWithLocation.


More information about the Haskell-Cafe mailing list