Search code examples
haskellparsec

Haskell parser combinator for Haskell identifier


I'm writing an anti-quoter in Haskell and I need a Parsec combinator that parses a valid Haskell variable identifier.

Is there one already implemented in the quasiquoting libraries or do I need to write my own?

I'm hoping I don't need to copy/paste the ident implementation found in http://www.haskell.org/haskellwiki/Quasiquotation.


Solution

  • It's unlikely that anything in the implementation of Template Haskell itself contains a Parsec parser for anything, because GHC does not use Parsec for parsing--note that it's not in the list of packages tied to GHC in various ways.

    However, the module Text.Parsec.Token gives a means of describing full token parsers for languages, and the Text.Parsec.Language module includes some predefined token parsers, including one for Haskell tokens.

    Beyond that, you could also look at the haskell-src-exts package, which is a parser for Haskell source files.