yav / haskell-lexer

A fully compliant Haskell 98 lexer.
MIT License
15 stars 7 forks source link

Support for Haskell2010 #6

Open erikd opened 4 years ago

erikd commented 4 years ago

The package description says:

A fully compliant Haskell 98 lexer.

The differences between Haskell98 and Haskell2010 as listed here.

yav commented 4 years ago

Hm, I haven't thought about it much, but looking at this I am not sure that we need to do much?

So the only changes I see seem to be:

Did I miss something? Both of these are easy to fix in a post-processing pass, that simply walks over the tokens and fixes the classification, which I could add to the library if it would help.

Let me know

erikd commented 4 years ago

I raised this issue thinking that Quasiquotation was part of Haskell2010. Turns out its not, so this ticket makes less sense now, unless you would consider adding support for GHC extensions, like quasiquotation (need this to improve pretty-show).

yav commented 4 years ago

I don't mind extending the lexer, but I haven't really looked into what changes are needed to get quasiquotation to work, and I don't have much time to work on this at the moment. If you want to have a go at it, I'd be happy to answer questions, otherwise I'll put it on my todo list.

I'd approach it by having a look at what GHC's lexer does for quasi quotes, and just port it to this one. It would be nice if we could add it to the lexer in a way that makes it optional, although I am not hugely worried about that.

jacobstanley commented 4 years ago

Thanks @erikd for bringing this up.

@yav So if someone looked at how GHC implemented lexing of quasi-quotes you'd be happy to accept a PR?

How would you see the optional aspect working?

To add more context, the impetuous behind this request was that I started trying to implement https://github.com/yav/pretty-show/issues/40 and ran in to the quasi-quotes roadblock. So that is really my ultimate goal, maybe there is a quicker way to achieve that.

yav commented 4 years ago

Sure. I just looked at what GHC does, and it basically just treats the whole quasi quote as a single token, with some manual stuff to implement it.

To do this with this lexer, you'd probably have to do something similar to the way nested comments are handled.

Ideally, it'd be nice to have a parameterized lexer, that takes as an input a configuration specifying how it should lex things, but this might be too complex to implement given how this lexer is generated (it's a haskell program that prints out the modules for the actual lexer---old style template haskell :-) So I wouldn't worry too much about it, bit if you can figure out how to do it, it would certainly be nice to have.

jacobstanley commented 4 years ago

Great thanks, I'll give it a shot.