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)?