[Haskell-cafe] Parsec: non-greedy 'between'

Daniel Fischer daniel.is.fischer at googlemail.com
Sun Sep 11 22:57:09 CEST 2011


On Sunday 11 September 2011, 22:38:30, Scott Lawrence wrote:
> Hey all,
> 
> Trying to match C-style comments, I have:
> 
>   between (string "/*") (string "*/") $ many anyChar
> 
> Which doesn't work, because it is equivalent (ignoring returned values)
> to
> 
>   do {string "/*"; many anyChar; string "*/"}
> 
> If the termination criterion was a single character, then I could use
> noneOf or (satisfy . not), but that doesn't help here.
> 
> So... what am I missing?

manyTill

A quick example:

Prelude Text.Parsec> parse (do {spaces; string "/*"; com <- manyTill 
anyChar (string "*/"); rmd <- getInput; return (com, rmd);}) "" "/* a 
comment */ and code /* and another comment */"
Right (" a comment "," and code /* and another comment */")

> 
> Thanks in advance.




More information about the Haskell-Cafe mailing list