[Haskell-cafe] Indentation-sensitive Parsec components?

Graham Klyne gk at ninebynine.org
Thu Mar 25 14:08:18 EST 2004


I'm wondering if anyone has implemented any indentation-sensitive parser 
components that can be used with Parsec.

I'm thinking of components along these lines:

[[
blockStart :: Parser () -> Parser Block
blockSep   :: Block -> Parser () -> Parser ()
blockEnd   :: Block -> Parser () -> Parser ()
]]

which might be used (somewhat self-referentially) like this:

[[
doSequence :: Parser ()
doSequence =
     do { symbol "do"
        ; b  <- blockStart (symbol "{")
        ; e1 <- expression
        ; es <- many ( do { blockSep b (symbol ";") ; expression }
        ; blockEnd b (symbol "}")
        ; dostuff (s1:ss)
        }
]]

The intent is that blockStart would look for the separator component, and 
if not present would determine the appropriate indentation level from the 
input character stream.  The other components would match or fail according 
to the way that the corresponding blockStart was matched.

#g


------------
Graham Klyne
For email:
http://www.ninebynine.org/#Contact



More information about the Haskell-Cafe mailing list