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

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to