[Haskell-cafe] Parsec question

Michael P Mossey mpm at alumni.caltech.edu
Fri Apr 17 19:33:44 EDT 2009


I've just about got this parser working, but wondering about something. Turns 
out I need "try" inside the "lookahead" here.

parseText :: Parser String
parseText = manyTill anyChar $ lookAhead (try (string "//"))

Without try, if I give it an input with a single slash, like

"some/text"

It stops with the error "unexpected t; expecting //"


I'm curious why that happens when lookAhead is used with manyTill like this. I 
was under the impression that if the end parser given to manyTill failed, then 
manyTill would just continue with the main parser. Apparently there are two ways 
to fail: in some contexts, failing means that manyTill will just continue. In 
other contexts, such as the one above, there is some sense in which 'string' 
demands the entire string to be present. Can anyone explain?

Thanks,
Mike



More information about the Haskell-Cafe mailing list