[Haskell-cafe] Question about implementing an off-side rule in Parsec 2

Ryan Ingram ryani.spam at gmail.com
Mon Apr 27 20:46:56 EDT 2009

I don't have experience solving this problem, but I've read a few
horror stories from people who had state affect the results of parsing
in Parsec.

Haskell's layout rules replace indentation levels with braces and
semicolons; you could run an initial "tokenizing" parser that builds
tokens including the indentation level of each line, then convert
those tokens into the appropriate braces and semicolons (via a pure
function) before feeding the results into the "real" Haskell parser.

  -- ryan

On Mon, Apr 27, 2009 at 2:41 PM, Bas van Gijzel <nenekotan at gmail.com> wrote:
> Hello everyone,
> I'm doing a bachelor project focused on comparing parsers. One of the parser
> libraries I'm using is Parsec (2) and I'm going to implement a very small
> subset of haskell with it, with as most important feature the off-side rule
> (indentation based parsing) used in function definitions and possibly in
> where clauses.
> But I'm still a bit stuck on how to implement this cleanly. I tried to
> search for some examples on blogs but I haven't found anything yet. As far
> as I can see the way to go would be using getState and updateState methods
> defined in Parsec.Prim and to use the methods in Parsec.Pos to compare the
> difference in indendation for tokens.
> But I haven't completely wrapped my head around any state monad yet and I
> don't understand Parsec enough yet to see how to use the methods Parsec.Pos
> and state easily. Some examples or pointers to something to read would
> really be helpful.
> Thanks in advance,
> Bas van Gijzel
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

More information about the Haskell-Cafe mailing list