@exercism/codemirror-lang-haskell 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,91 @@
1
+ ## 1.0.0
2
+
3
+ This is Exercism's first release of the package, published as
4
+ `@exercism/codemirror-lang-haskell`. It adds a `Callee` node for the function an
5
+ application calls, completion of the names in scope, and snippets.
6
+
7
+ ## 0.2.0 (2026-08-13)
8
+
9
+ ### From 81.41% to 97.51% of published Haskell
10
+
11
+ The first release was measured against six libraries. Six libraries turned out
12
+ to be a narrow sample. Against a corpus of 51365 files from 297 projects, the
13
+ same grammar read 81.41% of a 12000-file sample with no error node, and eleven
14
+ changes took it to 97.51%. Over all 51365 files the figure is 97.49%.
15
+
16
+ **`ImportQualifiedPost` was most of the gap.**
17
+ `import Arkham.Act.Cards qualified as Cards` stood at 1099 sites in 301 of 3000
18
+ files sampled. GHC 8.10 put the word behind the module name so that a list of
19
+ imports lines up on the names, and a great deal of the Haskell published since
20
+ is written that way. One optional word in the import rule was worth nine points
21
+ on its own. The quoted package name of `PackageImports` came with it.
22
+
23
+ **Quasi quotes are read.** `[sql| ... |]` holds somebody else's language, so
24
+ there is nothing for a Haskell parser to do with it but read to the `|]` and
25
+ hand the run over as one token. The lettered Template Haskell quotations
26
+ `[e| |]`, `[p| |]`, `[t| |]` and `[d| |]` hold Haskell of a kind their letter
27
+ names, and each is parsed as that kind. The typed `[|| ||]` is read as well.
28
+
29
+ The reason the first release left all of these out was that `[t| Int64 |]` and
30
+ the list comprehension `[t|t<-ts]` are written alike, and which is meant depends
31
+ on whether `TemplateHaskell` is on. The bracket that closes the run says it
32
+ instead: a quotation ends on `|]` and a comprehension on `]`, and the tokenizer
33
+ reads ahead to see which comes first.
34
+
35
+ **`RecordWildCards`.** `Foo {username = v, ..}` writes the `..` behind the
36
+ fields somebody named, which the record rule did not allow.
37
+
38
+ **`BlockArguments`.** `for_ xs \x -> ...` and `flip runBuilder mempty do ...`
39
+ pass a block as an argument with no `$` in front of it. An application that ends
40
+ on a block reaches as far right as the block does, so it ends the operator chain
41
+ it stands in.
42
+
43
+ **`UnicodeSyntax`.** 564 files in the corpus write `∷`, `→`, `⇒`, `←` or `∀`.
44
+ Each spelling is specialized to the same node as the ASCII one, so the tree says
45
+ `::` whichever character the file used. The set of five was checked against
46
+ `grammar/lexeme.js` in tree-sitter-haskell, which has the same list plus the
47
+ linear arrow `⊸`.
48
+
49
+ **The smaller ones.** A closed type family's `where` holds equations rather
50
+ than declarations, so `type family F a where F [e] = e` reads its right hand
51
+ side as a type. A binding carries its own signature: `let i :: Int = ...`. An
52
+ unboxed literal keeps its hash, which is what `1#` and `42##` are made of. A
53
+ `foreign import` names its calling convention in capitals, because
54
+ `WINDOWS_CCONV` is a macro the Win32 packages define. A pattern signature names
55
+ several synonyms at once. A semicolon somebody wrote may stand where there is
56
+ nothing to separate, which is how the older GHC sources lay out a braced `do`.
57
+
58
+ ### New nodes
59
+
60
+ `QuasiQuote` covers a quasi quoter's name and its body. `QuoteOpen`,
61
+ `TypeQuoteOpen`, `DeclarationQuoteOpen` and `TypedQuoteOpen` open the four
62
+ Template Haskell quotations, and `||]` closes the typed one. `TypeEquation` is
63
+ one equation of a closed type family. The old `[|` node is gone; `QuoteOpen`
64
+ stands where it did.
65
+
66
+ ## 0.1.1 (2026-08-06)
67
+
68
+ The repository link, which npm renders as a link and a browser cannot follow
69
+ with `git+` in front of it.
70
+
71
+ ## 0.1.0 (2026-07-31)
72
+
73
+ ### First release
74
+
75
+ Haskell language support: a Lezer grammar covering Haskell 2010 and the
76
+ extensions GHC 9 turns on for ordinary code, plus highlighting, folding,
77
+ indentation and completion.
78
+
79
+ CodeMirror has never shipped Haskell, and no Lezer grammar for it existed
80
+ anywhere. What an editor could fall back on was the CodeMirror 5 stream mode,
81
+ which colours a token at a time and knows nothing about the shape of what it is
82
+ reading.
83
+
84
+ The layout rule is the whole of the difficulty. Indentation opens and closes
85
+ blocks, a block also closes wherever the parser would otherwise fail, and a
86
+ block that opens no further right than the one around it is empty. None of that
87
+ can be written as a grammar, so an external tokenizer hands the parser the
88
+ braces and semicolons the report says are there.
89
+
90
+ The grammar was developed against 832 files of containers, text, aeson, lens,
91
+ xmonad and pandoc, of which 98.56% parse with no error node.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 CodinCod
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,200 @@
1
- # Temporary Holding Version
1
+ # @exercism/codemirror-lang-haskell
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ This is Exercism's fork of
4
+ [@codincod/codemirror-lang-haskell](https://codeberg.org/reeven/codemirror-lang-haskell),
5
+ written by CodinCod. Exercism uses it in the Haskell editor on
6
+ [exercism.org](https://exercism.org). Our changes are on the `main` branch.
7
+
8
+ The fork adds three things:
9
+
10
+ - The parser puts the name of the function being called into a `Callee` node,
11
+ so `map` in `map show xs` is highlighted as a function.
12
+ - Completion offers the names declared in the file that are in scope at the
13
+ cursor. That covers top-level functions, types, constructors, record fields,
14
+ class methods and import aliases, and also parameters, pattern variables, and
15
+ the bindings of `where`, `let`, `do`, `case`, lambdas, guards and list
16
+ comprehensions.
17
+ - Completion offers snippets for functions, guards, `case`, `if`, `let`,
18
+ `where`, `do`, lambdas, list comprehensions, `data`, `newtype`, `type`,
19
+ `class`, `instance`, imports and the module header. It offers nothing inside
20
+ strings and comments.
21
+
22
+ The rest of this README is upstream's.
23
+
24
+ This package implements Haskell language support for the
25
+ [CodeMirror](https://codemirror.net/) code editor, using a
26
+ [Lezer](https://lezer.codemirror.net/) grammar written for this package.
27
+
28
+ CodeMirror has never shipped Haskell. What a CodeMirror 6 editor can fall back
29
+ on is the stream mode from CodeMirror 5, which colours keywords and literals a
30
+ token at a time and knows nothing about the shape of what it is reading. No
31
+ Lezer grammar for Haskell existed anywhere before this one.
32
+
33
+ Written in part for [CodinCod](https://codincod.com/), a competitive coding
34
+ platform, where it colours the editor people solve puzzles in.
35
+
36
+ This code is released under an
37
+ [MIT license](https://codeberg.org/reeven/codemirror-lang-haskell/src/branch/master/LICENSE).
38
+
39
+ ## Install
40
+
41
+ ```bash
42
+ npm install @exercism/codemirror-lang-haskell
43
+ ```
44
+
45
+ ## Usage
46
+
47
+ ```javascript
48
+ import {EditorView, basicSetup} from "codemirror"
49
+ import {haskell} from "@exercism/codemirror-lang-haskell"
50
+
51
+ const view = new EditorView({
52
+ parent: document.body,
53
+ doc: `module Main where
54
+
55
+ import Data.List (sort)
56
+
57
+ main :: IO ()
58
+ main = do
59
+ input <- getContents
60
+ mapM_ print (sort (map read (lines input) :: [Int]))
61
+ `,
62
+ extensions: [basicSetup, haskell()]
63
+ })
64
+ ```
65
+
66
+ ## Coverage
67
+
68
+ Haskell 2010, and the extensions GHC 9 turns on for ordinary code: bang
69
+ patterns, lambda case, multi-way if, GADTs, standalone and strategy deriving,
70
+ type families, functional dependencies, pattern synonyms, view patterns, tuple
71
+ sections, `BlockArguments`, `ImportQualifiedPost`, `MagicHash`, `PackageImports`,
72
+ `RecordWildCards`, `UnicodeSyntax`, the arrow `proc` notation, quasi quotes, and
73
+ the Template Haskell quotations and splices written `[| |]`, `[e| |]`, `[p| |]`,
74
+ `[t| |]`, `[d| |]`, `[|| ||]`, `''Name` and `$( )`.
75
+
76
+ Measured against 51365 files of Haskell that somebody else wrote, drawn from
77
+ 297 projects and from Hackage, 97.49% parse with no error node. The largest
78
+ groups in it:
79
+
80
+ | | files | clean |
81
+ | --- | --- | --- |
82
+ | [amazonka](https://github.com/brendanhay/amazonka) | 498 | 100.00% |
83
+ | [wire-server](https://github.com/wireapp/wire-server) | 486 | 99.79% |
84
+ | [plutus](https://github.com/IntersectMBO/plutus) | 491 | 98.37% |
85
+ | Hackage releases | 15481 | 97.85% |
86
+ | [clash-compiler](https://github.com/clash-lang/clash-compiler) | 467 | 97.22% |
87
+ | [haskell-language-server](https://github.com/haskell/haskell-language-server) | 449 | 96.88% |
88
+ | [ghc](https://gitlab.haskell.org/ghc/ghc) | 495 | 93.94% |
89
+ | | **51365** | **97.49%** |
90
+
91
+ The first release was measured against six libraries, and against a 12000-file
92
+ sample of this corpus it read 81.41%. Reading those failures is what the 0.2.0
93
+ changelog entry is.
94
+
95
+ ## What a tokenizer has to settle
96
+
97
+ Most of Haskell can be written down as a grammar. Seven things cannot, and
98
+ they are the whole of `tokens.ts`.
99
+
100
+ **Indentation opens and closes blocks.** A `where`, a `do`, a `let` or an `of`
101
+ opens a block at the column of the token after it, a line beginning at exactly
102
+ that column starts a new item, and the first token to the left of it ends the
103
+ block. Almost no Haskell writes the braces and semicolons the report says are
104
+ there, so the tokenizer puts them back: it hands the parser a `blockOpen`, a
105
+ `blockSep` and a `blockEnd` with no text in them, standing where the
106
+ indentation put them. Where somebody did write the braces, they are read as the
107
+ same two tokens, which is what lets one rule in the grammar serve both.
108
+
109
+ **A block also closes where the parser would fail.** `let x = 1 in x` keeps the
110
+ `in` on the same line and nothing is indented differently, so no column says
111
+ the block is over. The report closes an implicit block wherever the parser
112
+ would otherwise fail, and the only thing that knows is the parser, so the
113
+ tokenizer asks it: before `in`, `then`, `else`, `of`, `where`, a closing
114
+ bracket or a comma, it checks whether the parser could shift that token, and
115
+ ends the block where it could not.
116
+
117
+ **A block that opens too far left is empty.** A `where` with nothing under it,
118
+ followed by a declaration at the left margin, opens a block and closes it in
119
+ the same place. That is the rule that keeps the declaration below it a
120
+ declaration rather than an error.
121
+
122
+ **Block comments nest.** `{- {- -} -}` is one comment rather than two, which no
123
+ regular token can count. Two things ride along with them: `{-# ... #-}` is a
124
+ pragma rather than a comment, and Haddock's `-- |`, `-- ^`, `{-| ... -}` and
125
+ `{-^ ... -}` are documentation rather than either, so a highlighter can give
126
+ all three different colours. A line comment is two or more dashes that no
127
+ symbol character follows, which is what keeps `-->` an operator.
128
+
129
+ **A name may carry its module.** `Data.Map.insert` is one name in three parts,
130
+ and the dots in it are not the composition operator. The tokenizer reads the
131
+ module part off the front and hands it over as a token of its own, so it can be
132
+ coloured as the namespace it is, and so `M.map`, `M.Map` and `M.!` need one
133
+ rule each rather than three. Which of the three follows is decided there as
134
+ well: `f M.x` applies a function and `f M.+ y` does not, and one token of
135
+ lookahead is not enough to tell them apart afterwards.
136
+
137
+ **A bracket and a bar open a quotation or a comprehension.** `[t| Int64 |]` is
138
+ Template Haskell and `[t|t<-ts]` is a list comprehension, and which is meant
139
+ depends on whether `TemplateHaskell` is on, which is written in a pragma or in
140
+ the file that builds the package. The bracket that closes the run says it
141
+ instead: a quotation ends on `|]` and a comprehension on `]`, so the tokenizer
142
+ reads ahead, counting the brackets it passes, and sees which comes first.
143
+
144
+ **Whitespace says what `!` and `~` mean.** `m ! k` looks something up and
145
+ `f !x = ...` takes a strict argument, and the difference is the space. GHC
146
+ decides it that way and so does this: a `!` or a `~` with space in front of it
147
+ and none behind it marks a pattern, and everywhere else it is an operator.
148
+
149
+ **A name being declared looks like any other name.** `f x = x` declares `f`,
150
+ and `xs !! n = ...` declares the operator and neither name around it. Which one
151
+ it is depends on what stands after the name, and an LR parser cannot hold both
152
+ readings open long enough to find out, so the tokenizer looks one token ahead
153
+ and decides, the same way it does for Odin. An operator behind the name means
154
+ the name is not the one being declared, and `::`, `∷`, `=` and `|` are what say
155
+ otherwise: the first two open a signature and the others open a body.
156
+
157
+ ## What the tree does not say
158
+
159
+ **Patterns are expressions.** Haskell writes them with the same syntax, and the
160
+ difference between `Just x` in a `case` and `Just x` in an argument is which
161
+ side of the equals sign it stands on. Reading them as one thing accepts a few
162
+ programs GHC rejects and refuses none that it accepts, which is the trade every
163
+ highlighting grammar makes.
164
+
165
+ **Types are their own small grammar.** That is the opposite decision, and it is
166
+ made for the highlighter: a name in a type is a type name, and the only way to
167
+ say so is for the tree to know it is in a type. Types are read as a flat run of
168
+ elements rather than as a tree of arrows, because nothing that reads this tree
169
+ cares how `a -> b -> c` associates.
170
+
171
+ **An operator chain is flat as well.** Haskell resolves fixity after parsing,
172
+ with `infixl` declarations the parser may never have read, so `a + b * c` is
173
+ one run of three operands rather than a tree. A run that begins or ends on its
174
+ operator is a section, a negation, or `(+)` on its own, and all three are the
175
+ same shape here.
176
+
177
+ **A lambda ends where its chain ends.** `\x -> a + b` reads the whole of
178
+ `a + b` as the body, which is what Haskell means, and it is why a lambda, a
179
+ `let` and an `if` stand at the end of an operator chain and nowhere else in
180
+ one. A `do` and a `case` end on a block instead, and the block says where they
181
+ end, so a chain may carry on after those.
182
+
183
+ ## What is left out
184
+
185
+ **A quasi quoter's body.** `[sql| ... |]` holds somebody else's language, so
186
+ the whole run from the bracket to the `|]` arrives as one `QuasiQuote` token and
187
+ nothing inside it is read. A grammar that reads SQL is a grammar for SQL.
188
+
189
+ **The C preprocessor.** `#if`, `#else` and `#endif` lines are skipped the way
190
+ comments are, which is right for a file that turns one feature on and wrong for
191
+ a file that writes a declaration twice. Both branches reach the parser, and one
192
+ of them is usually the error.
193
+
194
+ ## Building and testing
195
+
196
+ ```bash
197
+ npm install # installs the dependencies and builds dist/
198
+ npm run build # regenerates the parser and rebuilds dist/
199
+ npm test # builds, then runs the tests
200
+ ```