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.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to