Parsing Indentation-based syntaxes in Haskell's Parsec

Posted by pavpanchekha on Stack Overflow See other posts from Stack Overflow or by pavpanchekha
Published on 2010-06-11T14:10:15Z Indexed on 2010/06/11 14:12 UTC
Read the original article Hit count: 331

Filed under:
|
|
|

I'm trying to parse an indentation-based language (think Python, Haskell itself, Boo, YAML) in Haskell using Parsec. I've seen the IndentParser library, and it looks like it's the perfect match, but what I can't figure out is how to make my TokenParser into an indentation parser. Here's the code I have so far:

import qualified Text.ParserCombinators.Parsec.Token as T
import qualified Text.ParserCombinators.Parsec.IndentParser.Token as IT

lexer = T.makeTokenParser mylangDef
ident = IT.identifier    lexer

This throws the error:

parser2.hs:29:28:
    Couldn't match expected type `IT.TokenParser st'
             against inferred type `T.GenTokenParser s u m'
    In the first argument of `IT.identifier', namely `lexer'
    In the expression: IT.identifier lexer
    In the definition of `ident': ident = IT.identifier lexer

What am I doing wrong? How should I create an IT.TokenParser? Or is IndentParser broken and to be avoided?

© Stack Overflow or respective owner

Related posts about parsing

Related posts about haskell