[Haskell-cafe] Parsing Haskell with Layout

J. Garrett Morris jgbm at acm.org
Wed Aug 29 16:32:55 UTC 2018

On Tue, Aug 28, 2018 at 2:53 PM Benjamin Redelings
<benjamin.redelings at gmail.com> wrote:
> I'm not sure of the theory behind implementing Note 5 in section 10.3.
> This says roughly that we insert a "}" token after token t[n] if the
> tokens t[1]...t[n+1] have no valid parses, and the sequence of tokens
> t[1] ... t[n] followed by "}" DO have a valid parse.
> I think this allows you to write
> f z = let x=2;y=3 in x+y+z


> (a) what concepts are assumed by the report that would make it "obvious"
> how Note 5 is supposed to be implemented?

I don't think the report is intending to suggest a particular
implementation approach.  GHC's is described at

> (b) a simple (hopefully) implementation strategy for implementing it?
> I'm looking for a language-independent approach for parsing.

Perhaps you would find Michael Adams "Principled parsing for
indentation-sensitive languages: Revisiting Landin’s offside rule"
helpful.  http://dx.doi.org/10.1145/2429069.2429129

That approach is implemented by the "indentation" library on Hackage,
for either Parsec or Trifecta.


Prosperum ac felix scelus virtus vocatur
 -- Seneca

More information about the Haskell-Cafe mailing list