Handling whitespace with parser combinator parsers
Thu, 22 Nov 2001 08:20:03 +0100
I'm using the combinator library Parsec for quite a while. This library has many token functions: they parse specific entities and
then consume any white space behind them, e.g. natural, parens etc. Therefore, you almost don't have any explicit calls to consume
white space in your parser. And you can build such a parser from an arbitrary parser by applying the function "lexeme" to it. Look
at the documentation for Parsec (see haskell.org/libraries). An example to parse two integers followed by a '/' and many naturals,
with optional white space between them, may be written in Parsec as follows:
exampleParser = do integer; integer; lexeme (char '/'); many natural
Herman Graal schrieb:
> I'm new to this list so may have missed previous discussions relating to this. Anyway:
> Is there any good alternatives to having to "sprinkle" whitespace parsers all over a parser implemented with parser combinators?
> It kind of decreases the readability... ;-)
> I'm interested in any ideas. Would like a full picture of the different solutions out there?
> Are people actually doing both lexing and parsing in the same framework? If so, how do you handle whitespace?
> Best Regards,
> Herman Graal
> Sign-up for your own FREE Personalized E-mail at Mail.com
> 1 cent a minute calls anywhere in the U.S.!
> Haskell mailing list