[Haskell-cafe] Parselib sample

Stephen Tetley stephen.tetley at gmail.com
Wed Jun 2 13:10:32 EDT 2010


Hi Kashyap

They are very close - Parsec has most of the parsers in ParseLib in
either the Parsec.Char or Parsec.Combinator modules, if you import the
Parsec top level, you will get them, e.g:

> import Text.ParserCombinators.Parsec

ParseLib has - ident, nat, int - which have analogues in Parsec but
are in the Parsec.Token module and need the qualified import trick:

> import Text.ParserCombinators.Parsec.Language
> import qualified Text.ParserCombinators.Parsec.Token as P

> myLex     :: P.TokenParser st
> myLex     = P.makeTokenParser emptyDef

> integer   :: Parser Integer
> integer   = P.integer myLex

> ident     :: Parser String
> ident     = P.identifier myLex


Handling trailing white-space is probably another difference that I
haven't looked at yet (the variations - identifier, integer, natural -
in ParseLib). Type signatures are slightly different, of course, as
Parsec has more powerful "internal machinery".

Best wishes

Stephen


More information about the Haskell-Cafe mailing list