@exercism/codemirror-lang-pascal 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,157 @@
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-pascal`. It adds completion of the names in scope and
9
+ of class and record members after a dot, snippets and more standard library
10
+ routines, and reads a few more Free Pascal forms.
11
+
12
+ ### New features
13
+
14
+ Completion offers the names declared in the file, each only where it is in
15
+ scope. A subprogram's parameters, locals and `Result` count inside it,
16
+ including inside the subprograms nested in it. Inside a method, the fields,
17
+ methods and properties of its class and the classes it inherits from count
18
+ too, and so does `Self`. After `name.` it offers the members of the type of
19
+ `name`, or the values of an enumeration.
20
+
21
+ Snippets for `program`, a unit with its interface and implementation,
22
+ `procedure`, `function`, `begin`/`end`, `if`, the three `for` loops, `while`,
23
+ `repeat`, `case`, `try`, and class and record types.
24
+
25
+ More routines from SysUtils, StrUtils and Math, and the common exception
26
+ types. Keyword completion is turned off inside strings and comments, and
27
+ after a dot.
28
+
29
+ An empty array constant `()`, an array of one record or one array, and the
30
+ shift operators `<<` and `>>` parse.
31
+
32
+ ### Bug fixes
33
+
34
+ `procedure A; inline;` at the top level kept `inline` as a statement after the
35
+ header, which left the body loose from its header. The directive now belongs
36
+ to the header.
37
+
38
+ ## 0.5.0 (2026-08-15)
39
+
40
+ Five readings real Pascal has and this did not.
41
+
42
+ A closure may declare locals of its own between its header and its body, which
43
+ is what Delphi's threading and messaging code is written with. A constant may
44
+ be declared where a statement belongs, and its value is any expression the
45
+ block can work out. A type parameter may be held to `constructor` as well as to
46
+ `class`, so `<T: class, constructor>` reads as the one constraint list it is.
47
+ An attribute may name what it belongs to, and a run of `[assembly: ...]` on its
48
+ own is a declaration. `namespace RemObjects.Calendar;` opens an Oxygene unit.
49
+
50
+ The angle brackets read one word further: a `>` in front of `then`, `do`,
51
+ `else`, `end`, `to`, `downto` or `of` closes a list of type arguments, because
52
+ a comparison in front of any of those has nothing on its right.
53
+
54
+ 94.29% of 13111 published files parse with no error node, up from 90.22%.
55
+
56
+ ## 0.4.0 (2026-08-15)
57
+
58
+ A lock statement, an operator named after the type it belongs to, an extension
59
+ method whose body is one statement written behind the header, a choice written
60
+ in words where a value belongs, and every reserved word read as a name behind a
61
+ dot. The extension list comes from the corpus harness rather than being
62
+ repeated here.
63
+
64
+ ## 0.3.0 (2026-08-13)
65
+
66
+ ### Dialects
67
+
68
+ Free Pascal: the power operator, `extdecl`, an operator whose body names the
69
+ type it belongs to, a type parameter held to a constraint, a member of a
70
+ generic (`TAVLTree<T>.PNode`), a routine a library exports by number, and the
71
+ Amiga bindings' `syscall` with a calling convention in front of the library
72
+ base. Free Pascal's own compiler settled two of these: `compiler/tokens.pas`
73
+ lists the operators that may be overloaded, which is where `**` came from, and
74
+ the absence of `<<` from that table is why the shift written with angle
75
+ brackets is still read as an error.
76
+
77
+ Objective-C: a protocol somebody else owns, written as
78
+ `objcprotocol external name 'NSAccessibility' (NSObjectProtocol)`.
79
+
80
+ PascalABC.NET: a function type written as an arrow (`T -> boolean`,
81
+ `(integer, integer) -> real`, `T -> ()`), a choice written in words where a
82
+ value belongs, a body of one statement behind the header, extension methods,
83
+ `lock`, a conversion operator with type parameters of its own, and an operator
84
+ whose type stands in front of the word.
85
+
86
+ ### Reading
87
+
88
+ An include file that holds a piece of a `var` section, which is how Free
89
+ Pascal writes a library's whole function table. A run of modifiers with no
90
+ semicolon between them (`cdecl varargs;`), which used to lose the header in
91
+ front of it as well. Hint directives on a variable and on a record field, which
92
+ only a constant could carry before. A generic subprogram standing after a type
93
+ section, told from a generic type by a tokenizer, because the reading that
94
+ carries the answer is pruned before the answer arrives. Every reserved word as
95
+ a name behind a dot, rather than the handful that had been listed.
96
+
97
+ ### Coverage
98
+
99
+ 36092 files of published Pascal, 433 MiB. 95.02% parse with no error node, up
100
+ from 89.90%. Of the five projects written in Object Pascal proper, 96.44%.
101
+
102
+ The measurement now counts `.inc` and `.dpk` alongside `.pas`, `.pp`, `.dpr`
103
+ and `.lpr`. An include file is real Free Pascal and a Delphi package is real
104
+ Delphi, and leaving them out flattered every figure this package has published.
105
+ Against the narrower list the earlier releases used, 94.78%, up from 92.90%.
106
+
107
+ Set aside from that: 439 files that are meant to fail, being Pascal-P6's
108
+ conformance suite, PascalABC.NET's error tests and Free Pascal's own
109
+ must-not-compile tests. Without them, 95.70% of 35653.
110
+
111
+ ## 0.2.0 (2026-08-06)
112
+
113
+ ### Dialects
114
+
115
+ Free Pascal's older spellings: the bracketed directive list
116
+ (`procedure Move(...); [public, alias: 'FPC_MOVE']`), `bitpacked`, a procedural
117
+ type that is `nested`, a code page on a string type, `otherwise` in a `case`,
118
+ and a modifier that runs on without a semicolon. `object` is no longer reserved,
119
+ so standard Pascal may name a variable with it.
120
+
121
+ PascalABC.NET: `match`, `yield`, `loop`, ranges as values, the conditional
122
+ expression, `??`, `?.`, `auto` and `partial` classes, type classes, type
123
+ parameters in square brackets, `static` on a field or a method, a variable that
124
+ takes its type from its value, patterns that take a value apart, and a method
125
+ written out inside the class that declares it.
126
+
127
+ Pascaline: `joins`, `fixed`, an array written with its length, and an array
128
+ constant closed by `end`. Standard Pascal passes a subprogram as a parameter,
129
+ which had no rule at all.
130
+
131
+ ### Reading
132
+
133
+ Reserved words behind a dot (`System.Type`), the shebang of an `instantfpc`
134
+ script, a modifier written in front of a header, and an include file that holds
135
+ only the values of a table.
136
+
137
+ ### Coverage
138
+
139
+ Against the same 29054 files, 92.90% parse with no error node, up from 77.10%.
140
+ Of the five projects written in Object Pascal proper, 95.16%, up from 84.21%.
141
+
142
+ ## 0.1.0 (2026-08-06)
143
+
144
+ ### First release
145
+
146
+ Pascal language support: a Lezer grammar covering Object Pascal as Free Pascal
147
+ and Delphi compile it, plus highlighting, folding, indentation and completion.
148
+
149
+ No Lezer grammar for Pascal existed anywhere, so there was nothing to be
150
+ compatible with. What a CodeMirror 6 editor fell back on was the stream mode
151
+ carried over from CodeMirror 5, which colours keywords, strings, numbers and
152
+ comments by reading one line at a time, and leaves no tree behind.
153
+
154
+ Measured against 29054 files of published Pascal, 346 MiB drawn from Free
155
+ Pascal, Lazarus, PascalABC.NET, the Castle Game Engine, mORMot, Indy and
156
+ Pascal-P6, 77.10% parse with no error node. Of the five projects written in
157
+ Object Pascal proper, 84.21%.
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,214 @@
1
- # Temporary Holding Version
1
+ # @exercism/codemirror-lang-pascal
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
+ [ [**CHANGELOG**](CHANGELOG.md) ]
4
+
5
+ This package implements Pascal 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 Delphi Pascal and Free Pascal editors on
9
+ [exercism.org](https://exercism.org).
10
+
11
+ No Lezer grammar for Pascal existed before this one. A Pascal file in a
12
+ CodeMirror 6 editor was read by the stream mode carried over from CodeMirror 5,
13
+ which recognises keywords, strings, numbers and comments, and has no tree to
14
+ fold, indent or navigate by.
15
+
16
+ This code is released under an [MIT license](LICENSE).
17
+
18
+ ## Install
19
+
20
+ ```
21
+ npm install @exercism/codemirror-lang-pascal
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ ```javascript
27
+ import {EditorView, basicSetup} from "codemirror"
28
+ import {pascal} from "@exercism/codemirror-lang-pascal"
29
+
30
+ const view = new EditorView({
31
+ parent: document.body,
32
+ doc: `unit Greeting;
33
+
34
+ interface
35
+
36
+ type
37
+ TGreeter = class
38
+ private
39
+ FName: string;
40
+ public
41
+ constructor Create(const AName: string);
42
+ procedure Say;
43
+ end;
44
+
45
+ implementation
46
+
47
+ constructor TGreeter.Create(const AName: string);
48
+ begin
49
+ FName := AName;
50
+ end;
51
+
52
+ procedure TGreeter.Say;
53
+ begin
54
+ WriteLn('hello, ', FName);
55
+ end;
56
+
57
+ end.
58
+ `,
59
+ extensions: [basicSetup, pascal()]
60
+ })
61
+ ```
62
+
63
+ ## Completion
64
+
65
+ Completion offers keywords, snippets, types, routines and units, including
66
+ SysUtils, StrUtils and Math routines. It also offers the names declared in the
67
+ file, each where it is in scope, and the members of a class or record after a
68
+ dot. It offers nothing inside strings and comments.
69
+
70
+ The package exports `pascal()`, which includes both completion sources,
71
+ `pascalLanguage`, `pascalCompletion` (keywords, snippets, types, routines and
72
+ units), `localCompletionSource` (the names declared in the file), `snippets`
73
+ and `parser`.
74
+
75
+ ## Coverage
76
+
77
+ Object Pascal as Free Pascal and Delphi compile it. Units, programs, libraries
78
+ and packages; classes, records, interfaces, helpers and metaclasses; properties
79
+ with their specifiers; generics on both the Delphi spelling and the Free Pascal
80
+ one; variant records; procedural types; RTTI attributes; the whole directive
81
+ vocabulary; inline variables; anonymous methods; assembler blocks; and every
82
+ number and string spelling the two compilers accept. The grammar also
83
+ reads Free Pascal's empty array `()`, an array of one record, and the shift operators `<<`
84
+ and `>>`. A directive such as `inline` that follows a top-level header attaches
85
+ to that header.
86
+
87
+ Three other dialects are read as far as they go without costing Object Pascal
88
+ anything. PascalABC.NET has `match`, `yield`, ranges as values, type classes and
89
+ a variable that takes its type from its value. Pascaline has `joins`, `fixed`
90
+ and an array written with its length. Standard Pascal passes a subprogram as a
91
+ parameter.
92
+
93
+ The top level is deliberately looser than a compiler's. An editor is shown
94
+ fragments as often as whole files, so a bare statement, a lone declaration and a
95
+ unit cut off halfway all parse.
96
+
97
+ Measured against 36092 files of published Pascal, 433 MiB, 95.02% parse with no
98
+ error node. By project:
99
+
100
+ | Project | Files | Clean |
101
+ | --- | ---: | ---: |
102
+ | Free Pascal | 22332 | 96.57% |
103
+ | Lazarus | 4976 | 96.32% |
104
+ | PascalABC.NET | 4405 | 90.62% |
105
+ | Castle Game Engine | 2470 | 95.43% |
106
+ | mORMot | 576 | 97.92% |
107
+ | Indy | 803 | 95.89% |
108
+ | Pascal-P6 | 530 | 47.55% |
109
+
110
+ The five Object Pascal projects together are 96.44% clean. Much of what is left
111
+ in the other two is not meant to parse: 246 of Pascal-P6's 278 failures are its
112
+ ISO conformance suite, files whose whole purpose is to be rejected, and
113
+ PascalABC.NET keeps a directory of compiler error tests beside its samples. Set
114
+ those aside, along with Free Pascal's must-not-compile tests, and 95.70% of the
115
+ remaining 35653 files parse.
116
+
117
+ The extensions counted are `.pas`, `.pp`, `.inc`, `.dpr`, `.lpr` and `.dpk`.
118
+ An include file is a piece of a unit rather than a unit, and Free Pascal writes
119
+ 6752 of them; a Delphi package is a file Delphi compiles. Both are the language
120
+ and both are counted.
121
+
122
+ Measured a second way, against 13077 files the extensions gather from anywhere
123
+ rather than from seven named projects, 95.12% parse with no error node. That
124
+ corpus is the harder of the two: it holds every dialect at once, and what still
125
+ fails in it is mostly one file of one dialect at a time. Getting it there meant
126
+ teaching the grammar the anonymous method that declares locals, the constant
127
+ declared where a statement belongs, `<T: class, constructor>`, the attribute
128
+ that names what it belongs to, and the Oxygene namespace header, and getting
129
+ Puppet, Terraform, ppremake and a suite of files written to be rejected out of
130
+ the corpus, `.pp` being an extension four languages answer to.
131
+
132
+ Every project in the corpus has its own licence, so the corpus is kept out of this package.
133
+
134
+ ## What a tokenizer has to settle
135
+
136
+ Some things about Pascal cannot be written as grammar rules, and they are the
137
+ whole of `tokens.ts`.
138
+
139
+ **Case does not matter.** `BEGIN`, `Begin` and `begin` are one word, and real
140
+ code uses all three. The reserved words are therefore recognised by a function
141
+ that lowercases a word before looking it up, rather than by a list of literals
142
+ in the grammar file.
143
+
144
+ **Most of the words are not reserved.** `read`, `write`, `name`, `index`,
145
+ `message`, `default`, `private` and the calling conventions are directives. They
146
+ mean something in one position and are ordinary names everywhere else, and a
147
+ single unit will often use one both ways. They come in through
148
+ `@external extend`, which offers the parser the keyword and leaves the
149
+ identifier standing wherever the keyword cannot go.
150
+
151
+ **An angle bracket is two different things.** `TList<Integer>` and `a < b` open
152
+ on the same character. Where a type belongs there is no comparison to be had and
153
+ the parser says so. Where an expression belongs the answer is further along the
154
+ line, so the tokenizer reads ahead to find it.
155
+
156
+ **An assembler block is not Pascal.** `asm ... end` holds another language, with
157
+ its own comment characters and its own uses for `[` and `%`. It is taken whole
158
+ by a tokenizer that looks only for the `end` that closes it.
159
+
160
+ **A modifier says nothing about what it binds.** `static` behind a header is a
161
+ directive and ends with a semicolon; in front of one it belongs to the method or
162
+ the field that follows. Free Pascal's `[public, alias: 'x']` and an RTTI
163
+ attribute are the same bracket, told apart by the word inside it. Both answers
164
+ lie past what a parser is allowed to look at, so a tokenizer reads ahead and
165
+ hands back a different token.
166
+
167
+ **The branch of a conditional the compiler would not read is skipped.** A
168
+ compiler reads one arm of a `{$ifdef}` and an editor is shown both, so a grammar
169
+ that reads what is in front of it sees one declaration written twice. Everything
170
+ from an `{$else}` to the `{$endif}` that closes it is passed over, which is what
171
+ the compiler does with the same file, and the only reading that yields a tree.
172
+
173
+ ## What the tree does not say
174
+
175
+ **A subprogram body is a sibling of its header, never a child of another
176
+ subprogram.** Nothing before the body says whether there will be one: an
177
+ interface entry, a `forward`, an `external` and a full definition all open the
178
+ same way, and the answer can be thousands of lines off. A parser that goes
179
+ looking nests every header in a unit's interface section inside the one above
180
+ it, and buries `implementation` at the bottom. So a header ends the moment the
181
+ next declaration starts, and a procedure nested in another stands beside it.
182
+ Folding, indentation and highlighting want the body, and none of them wants the
183
+ nesting.
184
+
185
+ **A parenthesised list is not read for meaning.** The same brackets spell a
186
+ call, an index, an enumeration, a record constant and an array constant, and
187
+ which one is meant depends on what the name in front of them refers to. This
188
+ grammar knows what no name refers to, so it separates the five by what is inside
189
+ the brackets and no further.
190
+
191
+ **`^A` is a name, not a control character.** Turbo Pascal wrote control
192
+ characters as a caret and a letter, and Delphi still accepts `#13^J`. The same
193
+ caret spells a pointer dereference, and `PLooper^` and `^ALooper` differ only in
194
+ which side of the name it falls on. Real code dereferences constantly and writes
195
+ control characters rarely, so the caret is always the operator.
196
+
197
+ **A few PascalABC.NET spellings are left out.** Tuples, slices, `if` used as an
198
+ expression, a nullable `T?` and parameterless lambdas each collide with
199
+ something Object Pascal writes, and Object Pascal is what the grammar is for. A
200
+ tuple type and an enumeration are the same brackets around the same names; a
201
+ nullable type and the conditional expression are the same question mark.
202
+
203
+ ## Building and testing
204
+
205
+ ```
206
+ npm install # installs the dependencies and builds the package into dist/
207
+ npm run build # regenerates the parser, then rebuilds the package
208
+ npm test # builds the package, then runs the tests
209
+ ```
210
+
211
+ ## Contributing
212
+
213
+ Please read about how to [contribute to Exercism](https://exercism.org/docs/building).
214
+ Be sure to read the Exercism [Code of Conduct](https://exercism.org/docs/using/legal/code-of-conduct).