[Haskell-cafe] Question on Lexing Haskell syntax

Isaac Elliott isaace71295 at gmail.com
Wed Nov 1 00:55:27 UTC 2023


I like the approach from "Principled Parsing for Indentation-Sensitive
Languages" (https://michaeldadams.org/papers/layout_parsing/)

On Wed, Nov 1, 2023 at 8:32 AM Travis Athougies <travis at athougies.net>
wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA512
>
> According to the Haskell report [1] (See Note 5), a virtual `}` token
> is inserted if parsing the next token would cause a parse error and the
> indentation stack is non-empty.
>
> I'm trying to lex and parse Haskell source and this sort of interplay
> (which requires two-way communication between lexer and parser) makes
> it very difficult to write a conformant implementation.
>
> I can't change the standard (obviously), but I'm wondering if this is
> actually what GHC (de facto the only Haskell compiler) does, or if it
> applies some other rule. If so, does anyone know the exact mechanism of
> its implementation?
>
> I've been programming Haskell for more than a decade, and while I have
> an intuitive understanding of the indentation rules, I would have
> assumed the source could be lexed without also having a parser. In
> particular, the note seems to imply that the main purpose of this is to
> properly lex `let`/`in` bindings. Perhaps there's an alternate
> equivalent rule?
>
> Curious to hear other's thoughts.
>
> Travis
>
> [1]
>
> https://www.haskell.org/onlinereport/haskell2010/haskellch10.html#x17-17800010.3
> -----BEGIN PGP SIGNATURE-----
>
> iIsEARYKADMWIQRW81c55hOCXuY5k/H+BxaRGQDTjQUCZUGARhUcdHJhdmlzQGF0
> aG91Z2llcy5uZXQACgkQ/gcWkRkA041W+wEA/7n5NejGTYu4O6N+Pt7Rn0bBRw6D
> 5D96idagahXqXioA/18hxYFpY45lWwB7pKCh83xQJu2Bcwkxj1xhhCEZBcoA
> =FrDy
> -----END PGP SIGNATURE-----
> _______________________________________________
> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20231101/ecafd91e/attachment.html>


More information about the Haskell-Cafe mailing list