[Haskell-cafe] Parsec - separating Parsing from Lexing

Sean Leather leather at cs.uu.nl
Tue Nov 10 15:07:00 EST 2009

> I've sucessfully implemented the lexer using Parsec. It has the type String
> -> Parser [MJVal], where MJVal are all the possible tokens.

Great! You're partway there.

> How should I implement the parser separated from the lexer? That is, how
> should I parse Tokens instead of Strings in the "Haskell way"?

AFAIK, the difference is between having an input stream of type [Char] vs.
having a stream of tokens, e.g. [MJVal]. I haven't used Parsec myself, but
perhaps you want something of type 'GenParser MJVal s r' for some state s
and return type r?

There's an excellent set of lecture notes from a class we have at Utrecht,
formerly called Grammars and Parsing and now Languages and Compilers, in
which we use parser combinators in Haskell .


It's not Parsec, but there's plenty of useful general information in there,
cf. 4.5.1, 4.5.2.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20091110/37abb30b/attachment.html

More information about the Haskell-Cafe mailing list