[Haskell-cafe] lexing nested comments in GHC/Parser/Lexer.x

Vanessa McHale vamchale at gmail.com
Thu Feb 11 01:56:03 UTC 2021


The states generated by Alex are a bit inflexible, you could modify the
(user) state when dealing with nested comments I think but then checking
state before applying a rule might be expensive.

Cheers,
Vanessa McHale

On 2/9/21 10:57 PM, Benjamin Redelings wrote:
> Hi,
>
> I notice that in Lexer.x for GHC nested comments are parsed using a
> special function, with the comment "nested comments require traversing
> by hand, they can't be parsed using regular expressions."
>
> While I see that nested comments can't be parsed using regular
> expressions, the lexer has a state stack, and so it seems like nested
> comments could be parsed by pushing a new "nested comment" state onto
> the lexer state every time a "{-" is encountered.  But perhaps this is
> not done because its not clear how to make the entire comment into a
> single token that way?  This might be a naive question -- I don't have
> that much experience with lexers.
>
> Thanks!
>
> -BenRI
>
> _______________________________________________
> 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