@exercism/codemirror-lang-cfml 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,120 @@
1
- # Temporary Holding Version
1
+ # CFML 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-cfml)
4
+
5
+ This package gives the [CodeMirror 6](https://codemirror.net/) editor a [Lezer](https://lezer.codemirror.net/) grammar for CFScript, the script syntax of [CFML](https://cfdocs.org/) (Adobe ColdFusion and Lucee), with highlighting, indentation, folding and completion.
6
+ Exercism uses it in the editor for its CFML track.
7
+
8
+ To keep the package working on the Exercism website, don't change the versions of these packages:
9
+
10
+ ```json
11
+ "@codemirror/language": "^6.10.1",
12
+ "@lezer/highlight": "^1.2.0",
13
+ "@lezer/lr": "^1.4.0"
14
+ ```
15
+
16
+ ## Install
17
+
18
+ - NPM: `npm install @exercism/codemirror-lang-cfml`
19
+ - Yarn: `yarn add @exercism/codemirror-lang-cfml`
20
+ - Bun: `bun add @exercism/codemirror-lang-cfml`
21
+
22
+ ## Usage
23
+
24
+ ```ts
25
+ import { EditorView, basicSetup } from "codemirror";
26
+ import { cfml } from "@exercism/codemirror-lang-cfml";
27
+
28
+ new EditorView({
29
+ doc: "component {\n\tfunction hello() {\n\t\treturn 'Hello, World!';\n\t}\n}",
30
+ extensions: [basicSetup, cfml()],
31
+ parent: document.body,
32
+ });
33
+ ```
34
+
35
+ `cfml()` includes the completion. The package also exports `cfmlLanguage`, the two completion sources (`localCompletionSource` and `cfmlCompletion`) and the `snippets`.
36
+
37
+ ## What it covers
38
+
39
+ The grammar reads `.cfc` components and plain CFScript:
40
+
41
+ - `component` and `interface` declarations with attributes, as in `component extends="Base" accessors=true { }`.
42
+ - `property` declarations, in both the `property name="x" type="string";` and `property string x;` forms.
43
+ - functions with access modifiers, return types, `required` and typed arguments, defaults and attributes, as in `public numeric function add(required numeric a, b = 1) output=false { }`.
44
+ - closures (`function(x) { }`) and arrow functions (`(x) => x * 2`, `x => x`).
45
+ - `var`, `if`, `else if`, Lucee's `elseif`, `for`, `for (x in y)`, `while`, `do`, `switch`, `try`, `catch`, `finally`, `throw` and `rethrow`.
46
+ - tags written as script, as in `cfloop(index="i" from="1" to="#n#") { }`, `lock name="x" { }`, `include "page.cfm";` and `abort;`.
47
+ - operators, including the word operators `EQ`, `NEQ`, `GT`, `LT`, `GTE`, `LTE`, `IS`, `CONTAINS`, `MOD`, `AND`, `OR`, `NOT`, `XOR`, `EQV` and `IMP`, `&` for joining strings, and the `?:` Elvis operator.
48
+ - strings with `#expression#` interpolation, and `""`, `''` and `##` escapes.
49
+ - structs (`{a: 1, "b" = 2}`), ordered structs (`["a": 1]`, `[:]`), arrays, `new`, and member functions such as `name.len()`.
50
+
51
+ Keywords are case-insensitive, so `FUNCTION`, `Function` and `function` all work.
52
+ Semicolons are optional at the end of a line, as Lucee allows.
53
+ The rule that lets a line break end a statement is adapted in `src/tokens.js` from `@lezer/javascript` (MIT licence, by Marijn Haverbeke and others).
54
+
55
+ The completion offers:
56
+
57
+ - keywords, CFML's built-in functions (such as `arrayLen`, `listToArray` and `structKeyExists`) and the scopes (`arguments`, `variables`, `local` and the others).
58
+ - snippets for `component`, `function`, `public` and `private` functions, closures, `if`, `if`/`else`, `for`, `for in`, `while`, `do`, `switch`, `try`/`catch`, `var`, `property` and `throw`. The statement snippets appear at the start of a statement.
59
+ - types for return types and arguments, such as `numeric`, `string` and `struct`.
60
+ - the names declared in the file, each only where it is in scope. Inside a function that means its arguments, and the `var` and `local.` names, loop variables and caught errors declared before the cursor. Everywhere in the component, it means the functions, the properties, and the variables set outside a function's own scope (`total = 0`, `variables.total = 0` or `this.total = 0`).
61
+ - after `arguments.`, `local.`, `variables.` or `this.`, the names that scope holds.
62
+ - after any other dot, CFML's member functions, such as `len`, `each`, `map` and `keyExists`.
63
+
64
+ It offers nothing inside strings (outside `#...#`) and comments, or while you type a new name.
65
+
66
+ The grammar reads CFScript only, so `.cfm` pages written in tags (`<cfset>`, `<cfoutput>`) will show errors.
67
+
68
+ ## Prerequisites
69
+
70
+ - [Bun](https://bun.sh/)
71
+
72
+ ## Setup
73
+
74
+ Run `bun install` to install all dependencies.
75
+
76
+ ## Developing
77
+
78
+ To help with development, run `bun run dev`.
79
+ This will start a [Vite](https://vite.dev/) dev server (usually at http://localhost:5173/) that renders the `index.html` file.
80
+ The `#editor` element shows some sample CFML code, highlighted by the grammar in `src/syntax.grammar`.
81
+ Any changes to the grammar will auto-refresh the dev server's rendered contents.
82
+
83
+ ## Structure
84
+
85
+ ```text
86
+ .
87
+ ├── src
88
+ │ ├── index.ts (the language, with its indentation and folding)
89
+ │ ├── syntax.grammar (the Lezer grammar)
90
+ │ ├── tokens.js (the case-insensitive keywords and the line break rule)
91
+ │ ├── highlight.js (the highlighting)
92
+ │ ├── complete.ts (the completion)
93
+ │ └── builtins.ts (the names of the built-in functions, member functions and types)
94
+ ├── test
95
+ │ ├── cases (grammar test cases)
96
+ │ ├── grammar.test.ts (runs the grammar test cases)
97
+ │ ├── complete.test.ts (completion tests)
98
+ │ ├── editor.test.ts (indentation and folding tests)
99
+ │ └── lezer-plugin.ts (builds the grammar for the tests)
100
+ ├── index.html (dev server file)
101
+ ├── rollup.config.js (bundling config)
102
+ ├── tsconfig.json (typescript config)
103
+ └── vite.config.js (vite dev server config)
104
+ ```
105
+
106
+ ## Testing
107
+
108
+ Run `bun test` to run the tests.
109
+
110
+ ## Building
111
+
112
+ Run `bun run prepare` to build the package into `dist/`.
113
+ `bun install` runs the same command, so a fresh install also builds the package.
114
+
115
+ ## Publishing
116
+
117
+ To publish a new version, set `version` in `package.json` and commit it.
118
+ Then push a tag made of `v` followed by that version, for example `v1.0.0`.
119
+ The tag starts the Publish workflow, which builds and tests the package and publishes it to npm.
120
+ If the tag differs from `version`, the workflow stops before it publishes.