[Haskell-cafe] Hard cases for "Note 5" in Haskell layout parsing

Chris Smith cdsmith at gmail.com
Tue Mar 12 00:56:14 UTC 2019


Quick question.  I'm trying to resolve Haskell layout in order to provide
better syntax highlighting, but without committing to building a full
Haskell parser.  The reason this is hard at face value is because of the
"Note 5" in the relevant part of the Haskell Report, which says that a
layout context closes whenever (a) the next token without closing the
layout context would not be the start of any valid Haskell syntax, but (b)
the current statement followed by an implicit '}' could be valid Haskell
syntax.  This rule is why it's okay to write "let x = 5 in x^2", even
though let introduces a new layout syntax: the "in" implicitly closes it
because "x = 5 in" isn't the start of any valid syntax, so the layout
context is implicitly closed before the "in".

Now for my question.  Does anyone know other cases besides let/in where
this commonly comes up?  Everywhere I've seen this before uses let/in as an
example, but then concludes that full parsing is needed and gives up on
simpler answers.  But the specific example with let/in is easily handled
with a special-purpose rule that closes layout contexts as needed when an
"in" keyword shows up.  I cannot seem to construct any other examples,
because other layout-introducing keywords have their contents at the end of
syntactic element.

Is there something I've missed here?  I don't even care if it's a situation
where something is technically valid but a horrible edge case.  I'm
interested in realistic counterexamples.

Thanks,
Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20190311/33811332/attachment.html>


More information about the Haskell-Cafe mailing list