2009/4/28 Bas van Gijzel <neneko...@gmail.com> > > 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.
Parsing a simple form of the offside rule is discussed in the paper: Monadic Parser Combinators, Hutton and Meijer, 1996 http://www.cs.nott.ac.uk/~gmh/monparsing.pdf see section 8, page 30. Their parsers are similar in style to Parsec, but you may need to do some translation. I haven't thought about it hard, but I suspect their approach is not efficient for deeply nested examples, due to repeated processing of the token stream (but I could be wrong, and maybe it doesn't matter for what you are trying to do). I followed their approach in a toy language once, and the result was very pleasing to read in code. Cheers, Bernie.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe