@exercism/codemirror-lang-euphoria 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,31 @@
1
+ ## 1.0.0
2
+
3
+ This is Exercism's first release of the package, published as
4
+ `@exercism/codemirror-lang-euphoria`. It adds completion of the names in scope,
5
+ snippets and the standard libraries, and highlights a call through a namespace
6
+ as a call.
7
+
8
+ ## 0.1.0 (2026-08-09)
9
+
10
+ First release.
11
+
12
+ Euphoria and Phix, as one grammar under two dialects. Declarations, routines
13
+ and types; `if`, `for`, `while`, `switch`, `ifdef`, `enum`, `include` and the
14
+ `with`/`without` clauses; Euphoria's `loop`, labels and `entry`; Phix's
15
+ `for x in s`, classes, structs, `try`/`catch`, the conditional operator, the
16
+ bit shifts, the length operator, nested unpacking and `#ilASM` blocks; every
17
+ number and string spelling, and all five ways of writing a comment, nested the
18
+ way both compilers nest them.
19
+
20
+ ## Unreleased
21
+
22
+ Six things real Euphoria and real Phix turned out to need, found by measuring
23
+ the grammar against 2570 files of one and 2499 of the other.
24
+
25
+ A field may be named after a builtin, which is how every wrapper in the corpus
26
+ writes `handle.seek(3)` and `IUP.open()`. A DOS text file ends at a Ctrl-Z and
27
+ the bytes behind it are not part of the program. A `with warning` clause runs
28
+ to the closing brace of its list however many lines that takes. `u"abDF012E"`
29
+ is a string of sixteen bit characters, the way `x"68 65"` is one of bytes.
30
+ `namespace` and `goto` are words programs use as names, and Euphoria's own
31
+ creole does. And a Phix class says how it is taken down: `procedure ~Window()`.
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,257 @@
1
- # Temporary Holding Version
1
+ # @exercism/codemirror-lang-euphoria
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-euphoria](https://codeberg.org/reeven/codemirror-lang-euphoria),
5
+ written by CodinCod. Exercism uses it for Euphoria in the editor on
6
+ [exercism.org](https://exercism.org). Our changes are on the `main`
7
+ branch.
8
+
9
+ The fork adds completion for the names declared in the file, each where it is
10
+ in scope. It also adds snippets, and completion for the public routines, types and constants of
11
+ OpenEuphoria's standard libraries. The common libraries (such as
12
+ `std/sequence.e`, `std/math.e` and `std/text.e`) are always offered. The others
13
+ (such as `std/map.e` and `std/regex.e`) are offered once the file includes
14
+ them. After a namespace such as `map:` or `stdseq:`, or one set with
15
+ `include ... as`, it offers only that library's names, and after `include` it
16
+ offers the library paths. Completion is switched off inside strings and comments, and
17
+ while a new name is being typed. The fork also colours a call through a
18
+ namespace, such as `map:put(...)`, as a call.
19
+
20
+ The package exports `euphoria()` and `phix()` (Phix is a related language that
21
+ the grammar also reads). Both include two completion sources:
22
+ `euphoriaCompletion` (keywords, snippets, built-ins and the standard libraries)
23
+ and `localCompletionSource` (the names declared in the file). The package also
24
+ exports `euphoriaLanguage`, `phixLanguage`, `snippets`, `libraries` and `parser`.
25
+
26
+ ## Install
27
+
28
+ ```
29
+ npm install @exercism/codemirror-lang-euphoria
30
+ ```
31
+
32
+ Exercism's Euphoria editor calls `euphoria()`:
33
+
34
+ ```javascript
35
+ import {EditorView, basicSetup} from "codemirror"
36
+ import {euphoria} from "@exercism/codemirror-lang-euphoria"
37
+
38
+ new EditorView({
39
+ parent: document.body,
40
+ doc: `include std/io.e\nputs(1, "Hello, World!\\n")\n`,
41
+ extensions: [basicSetup, euphoria()]
42
+ })
43
+ ```
44
+
45
+ The rest of this README is upstream's.
46
+
47
+ ## @codincod/codemirror-lang-euphoria
48
+
49
+ [ [**CHANGELOG**](https://codeberg.org/reeven/codemirror-lang-euphoria/src/branch/master/CHANGELOG.md) ]
50
+
51
+ This package implements Euphoria and Phix language support for the
52
+ [CodeMirror](https://codemirror.net/) code editor, using a
53
+ [Lezer](https://lezer.codemirror.net/) grammar written for this package.
54
+
55
+ Neither language had a grammar anywhere. There is no Lezer parser, no
56
+ tree-sitter grammar and no CodeMirror 5 stream mode for either, so a `.exw` file
57
+ in an editor was plain text, or at best the comments and strings a generic
58
+ fallback could find.
59
+
60
+ Written in part for [CodinCod](https://codincod.com/), a competitive coding
61
+ platform, where it colours the editor people solve puzzles in.
62
+
63
+ This code is released under an
64
+ [MIT license](https://codeberg.org/reeven/codemirror-lang-euphoria/src/branch/master/LICENSE).
65
+
66
+ ## Usage
67
+
68
+ ```javascript
69
+ import {EditorView, basicSetup} from "codemirror"
70
+ import {phix} from "@exercism/codemirror-lang-euphoria"
71
+
72
+ const view = new EditorView({
73
+ parent: document.body,
74
+ doc: `include std/math.e
75
+
76
+ constant NAMES = {"ann","bo","cy"}
77
+
78
+ function greet(string name, integer times = 1)
79
+ sequence out = {}
80
+ for i=1 to times do
81
+ out = append(out,sprintf("hello, %s",{name}))
82
+ end for
83
+ return out
84
+ end function
85
+
86
+ for name in NAMES do
87
+ puts(1,join(greet(name),"\\n"))
88
+ end for
89
+ `,
90
+ extensions: [basicSetup, phix()]
91
+ })
92
+ ```
93
+
94
+ Import `euphoria()` instead for Euphoria. The two are one grammar under two
95
+ dialects; the section below says what the dialect decides.
96
+
97
+ ## One package, two languages
98
+
99
+ Phix is a reimplementation of Euphoria that keeps roughly 999 lines in every
100
+ thousand compiling unchanged. Phix's own tooling takes the same view: its
101
+ editor colours Phix files with a syntax definition named `Euphoria.syn`, and
102
+ that file, together with OpenEuphoria's `include/euphoria/keywords.e`, is where
103
+ this grammar's word lists were read from.
104
+
105
+ What the dialect settles is which words a program may use as names, and it
106
+ matters in both directions. `label`, `loop`, `entry`, `retry` and `routine` are
107
+ reserved in Euphoria and ordinary identifiers in Phix; `class`, `struct`, `try`,
108
+ `catch`, `forward`, `default`, `from` and `in` are the other way round.
109
+ Reserving the union would break real files in both languages, so neither
110
+ dialect is shown the other's words.
111
+
112
+ The dialect also selects the constructs only one of them has. Euphoria gets
113
+ `loop ... until ... end loop`, `label`/`goto` by string, and the `entry` clause
114
+ of a `while`. Phix gets `for x in s`, `class` and `struct`, `try`/`catch`, the
115
+ `cond?a:b` operator, the `?` that discards an element of an unpacking, and
116
+ `#ilASM` blocks.
117
+
118
+ Everything else is shared and needs no dialect: declarations, routines, `if`,
119
+ `for`, `while`, `switch`, `ifdef`, `enum`, `include`, `with`/`without`, every
120
+ number and string spelling, and all five ways of writing a comment.
121
+
122
+ ## Coverage
123
+
124
+ Measured on the source of both implementations and on 1735 Rosetta Code
125
+ snippets, counting files that parse with no error node:
126
+
127
+ | Corpus | Files | Clean |
128
+ | --- | ---: | ---: |
129
+ | Rosetta Code, Euphoria | 270 | 97.78% |
130
+ | Rosetta Code, Phix | 1465 | 97.68% |
131
+ | OpenEuphoria | 469 | 96.80% |
132
+ | Phix | 1506 | 97.14% |
133
+
134
+ The two implementation corpora are the hard end of the range and are the reason
135
+ they are quoted. They are compilers written in their own language: OpenEuphoria
136
+ holds the interpreter, its standard library and its conformance tests, and the
137
+ Phix tree holds the whole compiler, its builtins and its demos, including files
138
+ that keep C and assembler beside the Phix for reference. Ordinary programs, of
139
+ the kind an editor is usually shown, are the Rosetta rows.
140
+
141
+ The corpora do not ship with this package, because both are somebody else's.
142
+
143
+ ## What a tokenizer has to settle
144
+
145
+ Most of this language can be written down as grammar rules. What is left over
146
+ is the whole of `tokens.ts`.
147
+
148
+ **An include names a file, not an expression.** `include std/math.e` has a
149
+ slash and a dot in it that are not operators, and `include builtins\machine` has
150
+ a backslash. The path is one token, and it is only offered where the parser can
151
+ already take one.
152
+
153
+ **`with` and `without` take the rest of their line.** The clauses are open
154
+ ended: `with define BITS64`, `with warning {none}`, `without inline`,
155
+ `format PE32`. A rule that read them as a list of identifiers would eat the
156
+ first word of the next line, because nothing in this language terminates a
157
+ statement.
158
+
159
+ Both of those work by falling back rather than by competing. Lezer reads a
160
+ grammar's tokenizers in the order they are written and stops at the first that
161
+ hands the parser something it can use, so a path would otherwise arrive as the
162
+ identifier `math` with `/std.e` left over. What makes that not happen is that no
163
+ ordinary token can be shifted after `include` or `with`: the parser has nothing
164
+ to do with the identifier, the run carries on, and the line is read instead.
165
+
166
+ A comment goes the other way and is declared in front of everything, because
167
+ `--`, `/` and `#` are all an operator or a number until you have read further.
168
+
169
+ **A comment counts how deep it is.** Both compilers nest: OpenEuphoria's
170
+ scanner keeps a level and Phix's calls itself, and either closer shuts either
171
+ opener. That is what the dashed form is for. A file says *this line is code in
172
+ Phix and a comment in Euphoria* by putting an opener and a closer in front of
173
+ it, and it says *this whole passage is Euphoria's* by opening alone. A scanner
174
+ that stopped at the first closer would take the second of those for the first
175
+ and read the rest of the file at the wrong level, which is most of what a
176
+ grammar for these languages gets wrong.
177
+
178
+ **A hash is a number and a block of assembler.** `#ab` is hexadecimal and
179
+ `#ilASM{ ... }` holds another language, with its own uses for `[`, `%` and `;`.
180
+ The brace is what tells them apart and it lies past the word, so the tokenizer
181
+ reads ahead before claiming either.
182
+
183
+ **A colon ends a case label and joins a qualified name.** `case 1: x = 1` and
184
+ `case reserved:MULTIPLY then` put the same character in the same place, and one
185
+ token of lookahead sees no difference. What tells them apart is the space around
186
+ it: a qualifier is written tight against the name it qualifies, and a label's
187
+ colon is followed by the end of the line or by the statement it introduces.
188
+
189
+ **A question mark is a statement and an operator.** `?x` prints x and `a?b:c`
190
+ chooses between b and c. After a statement that was itself an expression both
191
+ are possible, and the line under `?sum(v)` may well open with a `?` of its own,
192
+ which a parser reading it as a conditional would join to the line above. Where
193
+ only one fits, that is the answer; where both do, the one that opens a line is
194
+ the statement, because nobody writes the middle of an expression in the first
195
+ column. A semicolon counts as opening a line, so `x = f(); ?x` reads as two
196
+ statements.
197
+
198
+ ## What the grammar decides
199
+
200
+ **Two identifiers in a row is a declaration.** A type in these languages is an
201
+ ordinary function that a declaration happens to stand in front of, so `integer i`
202
+ and `my_colour c` are the same shape and neither word is reserved. That is the
203
+ whole of how a declaration is told from a call, and it is why a statement that
204
+ is only an expression has to be a call: a statement that could be a bare name
205
+ would make `atom x` two of them.
206
+
207
+ **A name being declared may be one the runtime already uses.** Both standard
208
+ libraries define routines over the names of their own runtime, so
209
+ `function insert`, `function get_position` and `sequence length` all have to be
210
+ readable. A name in a declaration is the one place where no other reading is
211
+ possible, so that is where the built-in words step aside.
212
+
213
+ **Five statements end where their line does, and nothing says so.** `return`,
214
+ and the four that may name a label, all end without an operand often enough that
215
+ the parser has to guess. Each is followed by `end` far more often than by a
216
+ statement that could have been its operand, so a value is read wherever one
217
+ could start. The cost is unreachable code directly under a bare `return`, which
218
+ nobody writes.
219
+
220
+ **A class outweighs a declaration of one.** `class item` opens a class, and
221
+ `class food = box.contents[i]` declares a variable of the base type, so a whole
222
+ class body is read both ways and one reading is thrown away at the end. Lezer
223
+ keeps two readings side by side only while they are close in weight, so each
224
+ member of a class is worth a point to the reading that took `class` for a
225
+ keyword. Without them a body of any length outlives the split and the
226
+ declaration wins by having got there first.
227
+
228
+ **Inside a conditional, `a?b:c` beats `b:c`.** A colon separates a namespace
229
+ from the name it qualifies, and it also separates the two branches of the
230
+ conditional operator, and `a?b:c` is both. The conditional wins, because a
231
+ branch is rarely a qualified name and a qualified name is common everywhere
232
+ else. Outside a conditional nothing changes: `math:floor(x)` reads as it should.
233
+
234
+ ## What the tree does not say
235
+
236
+ **A call is not made on a value.** `f(a)(b)` does not parse, because closing the
237
+ statement and reading a call of a call are the same two tokens, and closing it
238
+ would leave `(b)` to be read as a statement of its own. Neither language can
239
+ call the result of a call, so nothing is lost.
240
+
241
+ **`iff(cond?a,b)` is not read.** Phix will take a comma in place of the colon
242
+ inside `iff`, and inside an argument list that comma is also the separator. The
243
+ colon spelling parses; the comma one does not.
244
+
245
+ **The top level is looser than a compiler's.** An editor is shown fragments as
246
+ often as whole files, so a bare statement, a lone declaration and a routine cut
247
+ off halfway all parse. A line holding nothing but `...` parses too: Phix writes
248
+ one where a parameter list goes on, and a published snippet writes one where the
249
+ code it left out went.
250
+
251
+ ## Building and testing
252
+
253
+ ```
254
+ npm install # installs the dependencies and builds the package into dist/
255
+ npm run build # regenerates the parser, then rebuilds the package
256
+ npm test # builds the package, then runs the tests
257
+ ```