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