haskell / haskell/haskell-mode

Wrong parsing and syntax highlighting with DerivingStrategies

Open
#1,588 0 comments 5 reactions 0 assignees View on GitHub
Dominant language
Emacs Lisp
Stars
1.4k
Forks
354
Avg merge
5d 10h
Merged PRs (30d)
2

Description

### Issue

When you have both `DeriveAnyClass` and `GeneralizedNewtypeDeriving` enabled in a file, GHC defaults to using the former. If you want to use the latter, you can enable [`DerivingStrategies`](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#deriving-strategies) and use something like

```
deriving newtype (Functor, Applicative, Monad)
```

This results in a parse error. Also, syntax highlighting + parsing doesn't work when you have `deriving stock` or `deriving anyclass`.

### Digging

1. Looking at the GHC parsing [code](https://github.com/ghc/ghc/blob/fea04defa64871caab6339ff3fc5511a272f37c7/compiler/parser/Parser.y#L1163) and testing things out in the REPL, it seems that these (`stock` and `anyclass`) are keywords only when preceded by `"deriving"` so maybe we can add special cases like the treatment of `import` statements but simpler in `haskell-font-lock.el`. That should fix the syntax highlighting.
2. I'm unable to understand the parsing code in `haskell-indentation.el`. I've narrowed it down to `haskell-indentation-data` which probably needs to be tweaked but I unable to piece together what the multiple copies of `deriving` are doing...

Thoughts on the issue?

### Misc

I don't think this is relevant, but I encountered this issue when using Intero 0.1.28 and Haskell mode version `16.2-git` (the directory name is `haskell-mode-20171022.26`).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.