
17 Apr
2009
17 Apr
'09
4:43 p.m.
Michael Mossey wrote:
Here's what I have so far. It works, but it's a bit weird to consume the // as part of the text rather than the keyword. That happens because the try( string "//" ), which is part of the end arg to manyTill, consumes the // when it succeeds. But maybe it is the most natural way to express the problem.
use lookAhead!
parseKeyword :: Parser String parseKeyword = many1 (alphaNum <|> char '_')
parseKeyword = string "//" >> many1 (alphaNum <|> char '_')
parseText :: Parser String parseText = manyTill anyChar ((try (string "//") >> return ()) <|> eof)
parseText = manyTill anyChar $ (lookAhead (try $ string "//") >> return ()) <|> eof (untested) C.