haskell-lexer icon indicating copy to clipboard operation
haskell-lexer copied to clipboard

Support for Haskell2010

Open erikd opened this issue 5 years ago • 6 comments

The package description says:

A fully compliant Haskell 98 lexer.

The differences between Haskell98 and Haskell2010 as listed here.

erikd avatar Jan 27 '20 05:01 erikd

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

  • do-and-if-then-else is a change to the parser that allows more semicolons
  • hierarchical module names: change the parser to use qconid instead of conid where module names are expected
  • empty data decls, is also just a parser thing
  • fixity resolution is not really related to the lexer
  • FFI, a guess "foregin" is now a key word, so that would be a change (*)
  • Line comment syntax: we seem to already be doing what 2010 suggests
  • pattern guards: these are more changes to the parser
  • relaxed dependency analysis: not to do with lexing
  • language pragma: the lexer preserves comments, so pragmas can be extracted in a post-processing pass (*) * remove (n+k): not a lexical issue.

So the only changes I see seem to be:

  • add foreign as a keyword, and
  • (maybe) make pragmas into their own token.

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

yav avatar Jan 27 '20 19:01 yav

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).

erikd avatar Jan 27 '20 20:01 erikd

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.

yav avatar Jan 28 '20 18:01 yav

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.

jacobstanley avatar Jan 28 '20 19:01 jacobstanley

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.

yav avatar Jan 28 '20 20:01 yav

Great thanks, I'll give it a shot.

jacobstanley avatar Jan 28 '20 22:01 jacobstanley