[Haskell-cafe] Hard cases for "Note 5" in Haskell layout parsing
Albert Y. C. Lai
trebla at vex.net
Mon Mar 18 00:25:34 UTC 2019
Does this help?
x1 = case do Nothing; Nothing of _ -> ()
x2 = case do Nothing
Nothing
of _ -> ()
In fact in f2 play with all ways of positioning the line "of _ -> ()" to
see there is almost no wrong placement!
On 2019-03-11 8:56 p.m., Chris Smith wrote:
> 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
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
>
More information about the Haskell-Cafe
mailing list