<div dir="ltr"><div>Hi Alexis, Hi Iavor,</div><div><br></div><div>I'm afraid I'm not particularly acquainted with how GHC implements indentation-sensitive parsing, but I really like the way in which <a href="https://www.springer.com/gp/book/9783642175398">this book</a> frames the problem. If you look at the preview for the first chapter, you'll notice that (they call the lexer scanner, and) they introduce an additional pass between lexer and parser that handles the context-sensitive bits about indentation-sensitive parsing, which doesn't fit well with the parser (which assumes a context-free grammar to stay sane) or with the lexer (which should better be just a simple DFA).</div><div><br></div><div>In particular, the short section 1.3 about the screener explicitly mentions Haskell as use case:</div><div><br></div><div><img src="cid:ii_kn4jvfzm1" alt="2021-04-05-140820_543x163_scrot.png" width="480" height="144"><br></div><div>Although that doesn't really explain the how. Maybe section 2.5 (where impl of screeners is covered) provides more insight into that.</div><div>Screeners are a bit like semantic analysis, but on the token stream instead of the parse tree.<br></div><div><br></div><div>Reach out in private if you want more excerpts.</div><div><br></div><div>Cheers,</div><div>Sebastian<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Am Mo., 5. Apr. 2021 um 00:19 Uhr schrieb Alexis King <<a href="mailto:lexi.lambda@gmail.com">lexi.lambda@gmail.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
On 4/4/21 1:52 PM, Iavor Diatchki wrote:<br>
<blockquote type="cite">
<div dir="ltr">Hi Alexis,
<div><br>
</div>
<div>I wasn't sure what the "alternative layout" is either and
did some googling, and it appears that it is something that
was never really documented properly. The following link
contains pointers to the commit that introduced it (in 2009!)
(not the main ticket but some of the comments)</div>
</div>
</blockquote>
<p>Thanks, that’s a helpful pointer, though of course it still
doesn’t explain very much. I’m still interested in understanding
what the purpose of “alternative layout” is and how it operates,
if anyone else has any idea.<br>
</p>
<blockquote type="cite">
<div dir="ltr">
<div>Overall, I do think that Haskell's layout rule is more
complicated than it needs to be, and this is mostly because of
the rule that requires the insertion of a "virtual close
curly" on a parse error.</div>
</div>
</blockquote>
<p>Yes, this does seem to be by far the trickiest bit. But I’d be
sad not to have it, as without it, even simple things like</p>
<blockquote>
<pre>let x = 3 in e</pre>
</blockquote>
<p>would not be grammatically valid.<br>
</p>
<blockquote type="cite">
<div dir="ltr">My feeling is that it'd be pretty tricky to do
layout in the parser with grammar rules, but you may be able to
do something with the parser state.</div>
</blockquote>
<p>Yes, I have some vague ideas, but none of them are particularly
fleshed out. It’s entirely possible that I just don’t understand
the relationship between the lexer and the parser (which seems
somewhat obscured by the “alternative layout” stuff), and the
ideas I have are what’s already implemented today. I’ll have to
study the implementation more closely.<br>
</p>
<p>In any case, thank you for your response! The ALR-related pointer
certainly clarifies at least a little.</p>
<p>Alexis<br>
</p>
</div>
_______________________________________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a><br>
</blockquote></div>