<div class="gmail_quote">2009/4/28 Bas van Gijzel <span dir="ltr">&lt;<a href="mailto:nenekotan@gmail.com">nenekotan@gmail.com</a>&gt;</span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I&#39;m doing a bachelor project focused on comparing parsers. One of the parser libraries I&#39;m using is Parsec (2) and I&#39;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. <br>

<br>But I&#39;m still a bit stuck on how to implement this cleanly. I tried to search for some examples on blogs but I haven&#39;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. <br>

<br>But I haven&#39;t completely wrapped my head around any state monad yet and I don&#39;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.</blockquote>
<div><br></div><div>Parsing a simple form of the offside rule is discussed in the paper:</div><div><br></div><div>    Monadic Parser Combinators, Hutton and Meijer, 1996</div><div>    <a href="http://www.cs.nott.ac.uk/~gmh/monparsing.pdf">http://www.cs.nott.ac.uk/~gmh/monparsing.pdf</a></div>
<div><br></div><div>    see section 8, page 30.</div><div><br></div><div>Their parsers are similar in style to Parsec, but you may need to do some translation.</div><div><br></div><div>I haven&#39;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&#39;t matter for what you are trying to do).</div>
<div><br></div><div>I followed their approach in a toy language once, and the result was very pleasing to read in code.</div><div><br></div><div>Cheers,</div><div>Bernie. </div></div>