@exercism/codemirror-lang-fortran 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (C) 2024 by Erik Schierboom <erik_schierboom@hotmail.com> and others
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
13
+ all 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
21
+ THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,115 @@
1
- # Temporary Holding Version
1
+ # Fortran language support for CodeMirror
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
+ ![NPM Version](https://img.shields.io/npm/v/@exercism/codemirror-lang-fortran)
4
+
5
+ This package gives the CodeMirror 6 editor support for free-form Fortran (Fortran 90 and later).
6
+ Exercism uses it in the editor for its Fortran track.
7
+
8
+ It has:
9
+
10
+ - a Lezer grammar, with highlighting for keywords, strings, numbers, comments, definitions, calls, types and operators.
11
+ - indentation and folding for program units and block constructs.
12
+ - completion for keywords, intrinsic procedures, snippets, and the names declared in the file.
13
+
14
+ ⚠️ Keep the versions of these dependencies as they are, so that the package works on the Exercism website:
15
+
16
+ ```json
17
+ "@codemirror/language": "^6.10.1",
18
+ "@lezer/highlight": "^1.2.0",
19
+ "@lezer/lr": "^1.4.0"
20
+ ```
21
+
22
+ ## Install
23
+
24
+ - NPM: `npm install @exercism/codemirror-lang-fortran`
25
+ - Yarn: `yarn add @exercism/codemirror-lang-fortran`
26
+ - Bun: `bun add @exercism/codemirror-lang-fortran`
27
+
28
+ ## Usage
29
+
30
+ ```js
31
+ import { EditorView, basicSetup } from "codemirror";
32
+ import { fortran } from "@exercism/codemirror-lang-fortran";
33
+
34
+ new EditorView({
35
+ doc: "program hello\n print *, 'Hello, World!'\nend program hello\n",
36
+ extensions: [basicSetup, fortran()],
37
+ parent: document.body,
38
+ });
39
+ ```
40
+
41
+ The package also exports `fortranLanguage`, `snippets` and `localCompletionSource`.
42
+
43
+ ## How the grammar reads Fortran
44
+
45
+ Fortran keywords are case-insensitive and not reserved.
46
+ The tokenizer in `src/tokens.ts` lowercases each word before it looks it up.
47
+ Some keywords, such as `result`, `stop` and `block`, are often used as names.
48
+ For those words the parser tries both readings and keeps the one that fits.
49
+
50
+ A line break or a `;` ends a statement.
51
+ If a line ends with `&`, the statement goes on to the next line.
52
+ The tokenizer skips the `&`, any blank or comment lines after it, and an `&` at the start of the next line.
53
+
54
+ The grammar covers free-form source only.
55
+ It doesn't parse fixed-form source (the column-based layout of FORTRAN 77), numeric statement labels, `format` statements, `common` blocks or `data` statements.
56
+
57
+ ## Completion
58
+
59
+ Completion offers:
60
+
61
+ - keywords and the intrinsic procedures from the Fortran 2018 standard.
62
+ - snippets for `module`, `program`, `subroutine`, `function`, derived types, `do` loops, `do while` loops, `if` blocks and `select case`.
63
+ - the names declared in the file: modules, procedures, derived types, variables, dummy arguments, and names brought in with `use ..., only:`.
64
+
65
+ Names come from the syntax tree, and only the names in scope at the cursor are offered.
66
+ A procedure's dummy arguments and local variables are offered inside that procedure only.
67
+ Completion is turned off inside strings and comments, and where a new name is being declared.
68
+
69
+ ## Prerequisites
70
+
71
+ - [Bun](https://bun.sh/)
72
+
73
+ ## Setup
74
+
75
+ Run `bun install` to install all dependencies.
76
+
77
+ ## Structure
78
+
79
+ ```text
80
+ .
81
+ ├── src
82
+ │ ├── fortran.grammar (the Lezer grammar)
83
+ │ ├── tokens.ts (line breaks, continuation lines, numbers and keywords)
84
+ │ ├── index.ts (the language, highlighting, indentation and folding)
85
+ │ ├── completions.ts (keywords, intrinsics and snippets)
86
+ │ └── complete.ts (completion of names declared in the file)
87
+ ├── test
88
+ │ ├── cases (grammar test cases)
89
+ │ ├── grammar.test.ts
90
+ │ └── completion.test.ts
91
+ └── index.html (dev server page)
92
+ ```
93
+
94
+ ## Developing
95
+
96
+ Run `bun run dev` to build the parser and start a [Vite](https://vite.dev/) dev server (usually at http://localhost:5173/).
97
+ The page shows an editor with some sample Fortran.
98
+ After changing the grammar, run `bun run build` again to regenerate `src/parser.js`.
99
+
100
+ ## Testing
101
+
102
+ Run `bun run test` to build the package and run the tests.
103
+ The grammar test cases are in `test/cases`, in Lezer's test format.
104
+
105
+ ## Building
106
+
107
+ Run `bun run build` to build the package into `dist/`.
108
+ `bun install` runs the same command, so a fresh install also builds the package.
109
+
110
+ ## Publishing
111
+
112
+ To publish a new version, set `version` in `package.json` and commit it.
113
+ Then push a tag made of `v` followed by that version, for example `v1.0.0`.
114
+ The tag starts the Publish workflow, which builds and tests the package and publishes it to npm.
115
+ If the tag differs from `version`, the workflow stops before it publishes.