I have been working on a pet language, which has Haskell-like syntax. One of the neat things which Haskell does, which I have been trying to replicate, is its insertion of {, } and ; tokens based on code layout, before the parsing step.
I found http://www.haskell.org/onlinereport/syntax-iso.html, which includes a specification of how to implement the layout program, and have made a version of it (modified, of course, for my (much simpler) language).
Unfortunately, I am getting an incorrect output for the following:
f (do x y z) a b
It should be producing the token stream ID ( DO { ID ID ID } ) ID ID, but it is instead producing the token stream ID ( DO { ID ID ID ) ID ID }.
I imagine that this is due to my unsatisfactory implementation of parse-error(t) (parse-error(t) = false), but I have no idea how I would go about implementing parse-error(t) efficiently.
How do Haskell compilers like GHC etc. handle this case? Is there an easy way to implement parse-error(t) such that it handles this case (and hopefully others that I haven't noticed yet)?
DO, see if there’s a{, and if there is, expect it to end with a}; otherwise, stop parsing the contents of the block when the start column of a token that would potentially start a new item in the block is to the left of the start-column of the first one. - icktoofayparse-error(t), it just needs to handle some basic cases. @icktoofay I am currently doing the parsing in 3 steps, lexing, layout, and then parsing. The layout algorithm is doing basically that, but it doesn't have enough context to handle do blocks in brackets. - Mystor