Handling whitespace with parser combinator parsers
Hi, 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 http://www.mail.com/?sr=signup 1 cent a minute calls anywhere in the U.S.! http://www.getpennytalk.com/cgi-bin/adforward.cgi?p_key=RG9853KJ&url=http://...
Hi Herman, 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 Regards, Bernd Herman Graal schrieb:
Hi,
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 http://www.mail.com/?sr=signup
1 cent a minute calls anywhere in the U.S.!
http://www.getpennytalk.com/cgi-bin/adforward.cgi?p_key=RG9853KJ&url=http://...
_______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
"Herman Graal" <herman_graal@europe.com> wrote,
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?
http://www.cse.unsw.edu.au/~chak/haskell/ctk/index.html#CTKlight includes both lexer and parser combinators. Cheers, Manuel
participants (3)
-
Bernd Holzmüller -
Herman Graal -
Manuel M. T. Chakravarty