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

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