@mmmnt/feat-grammar 0.1.7 → 0.1.8
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 +16 -23
- package/README.md +161 -10
- package/feat.tmLanguage.json +1 -1
- package/index.js +0 -1
- package/package.json +1 -1
package/LICENSE
CHANGED
|
@@ -1,28 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
MIT License
|
|
2
2
|
|
|
3
3
|
Copyright (c) 2026, Moment
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
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:
|
|
7
11
|
|
|
8
|
-
|
|
9
|
-
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
10
14
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
-
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
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,12 +1,59 @@
|
|
|
1
1
|
# @mmmnt/feat-grammar
|
|
2
2
|
|
|
3
|
-
The TextMate grammar for `.feat
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
**The TextMate grammar for `.feat`.** One JSON file, scope `source.feat`, behind
|
|
4
|
+
every place a spec is shown with colour: the VS Code extension, a website
|
|
5
|
+
rendered with Shiki, and any other tool that reads TextMate grammars.
|
|
6
|
+
|
|
7
|
+
The grammar highlights. It does not parse. A line can be coloured as a keyword
|
|
8
|
+
and still be a parse error. For validation use `feat parse`
|
|
9
|
+
([`@mmmnt/feature`](https://www.npmjs.com/package/@mmmnt/feature)) or
|
|
10
|
+
[`@mmmnt/feat-core`](https://www.npmjs.com/package/@mmmnt/feat-core).
|
|
11
|
+
|
|
12
|
+
## Where it sits
|
|
13
|
+
|
|
14
|
+
This package is the source of truth for `.feat` highlighting. The `feat-vscode`
|
|
15
|
+
extension and `editor/` ship copies of the file, synced from here by
|
|
16
|
+
`editors/vscode/scripts-sync-grammar.mjs`. A test fails if either copy drifts. The grammar is tested by tokenizing a
|
|
17
|
+
real corpus exemplar and asserting scopes with `vscode-textmate`, the engine VS
|
|
18
|
+
Code itself uses.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
npm install @mmmnt/feat-grammar
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Requirements:
|
|
27
|
+
|
|
28
|
+
- Node 20 or later (`engines`).
|
|
29
|
+
- ESM only (`"type": "module"`).
|
|
30
|
+
- No dependencies. `vscode-textmate`, `vscode-oniguruma` and `vitest` are dev
|
|
31
|
+
dependencies of the package's own test; you need them only if you tokenize
|
|
32
|
+
yourself, as in [Tokenize without a highlighter](#tokenize-without-a-highlighter).
|
|
33
|
+
|
|
34
|
+
The package ships three files: `index.js`, `index.d.ts` and
|
|
35
|
+
`feat.tmLanguage.json`.
|
|
36
|
+
|
|
37
|
+
## What it exports
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
export declare const grammar: Record<string, unknown>; // the raw TextMate grammar, scopeName "source.feat"
|
|
41
|
+
export declare const featLanguage: Record<string, unknown>; // grammar plus { name: "feat" }, no aliases
|
|
42
|
+
export default featLanguage;
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`index.js` reads the JSON with `node:fs`, so it runs in Node. For a browser
|
|
46
|
+
bundle, import the JSON file directly. The package has no `exports` map, so
|
|
47
|
+
this path resolves:
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
import grammarJson from "@mmmnt/feat-grammar/feat.tmLanguage.json" with { type: "json" };
|
|
51
|
+
```
|
|
7
52
|
|
|
8
53
|
## Websites (Shiki)
|
|
9
54
|
|
|
55
|
+
Pass the default export to Shiki. It is a `LanguageRegistration` named `feat`:
|
|
56
|
+
|
|
10
57
|
```js
|
|
11
58
|
import { createHighlighter } from "shiki";
|
|
12
59
|
import featLanguage from "@mmmnt/feat-grammar";
|
|
@@ -18,16 +65,120 @@ const highlighter = await createHighlighter({
|
|
|
18
65
|
const html = highlighter.codeToHtml(specText, { lang: "feat", theme: "github-dark" });
|
|
19
66
|
```
|
|
20
67
|
|
|
68
|
+
The export carries no `aliases`: an alias equal to the language's own name makes
|
|
69
|
+
Shiki stop with `Circular alias 'feat -> feat'`. A test pins that shape.
|
|
70
|
+
|
|
21
71
|
## Editors
|
|
22
72
|
|
|
23
|
-
- **VS Code
|
|
24
|
-
(
|
|
25
|
-
|
|
73
|
+
- **VS Code, Windsurf, Cursor, Devin**: install the `feat-vscode` extension
|
|
74
|
+
(publisher `mmmnt`). It bundles this grammar for the `.feat` extension, and
|
|
75
|
+
also starts `feat watch --json` in any workspace that has a `feat.config.json`.
|
|
76
|
+
- **JetBrains IDEs**: Settings, Editor, TextMate Bundles, then add a directory
|
|
26
77
|
containing `feat.tmLanguage.json`.
|
|
27
|
-
- **GitHub.com rendering**:
|
|
28
|
-
|
|
78
|
+
- **GitHub.com rendering**: needs a `github-linguist` submission, planned once
|
|
79
|
+
the language has public usage.
|
|
80
|
+
|
|
81
|
+
## Tokenize without a highlighter
|
|
82
|
+
|
|
83
|
+
The engine VS Code uses is available from npm. This prints the most specific
|
|
84
|
+
scope of each token of a line:
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
import { readFileSync } from "node:fs";
|
|
88
|
+
import { createRequire } from "node:module";
|
|
89
|
+
|
|
90
|
+
const require = createRequire(import.meta.url);
|
|
91
|
+
const { Registry, parseRawGrammar } = require("vscode-textmate");
|
|
92
|
+
const { loadWASM, OnigScanner, OnigString } = require("vscode-oniguruma");
|
|
93
|
+
|
|
94
|
+
await loadWASM(readFileSync(require.resolve("vscode-oniguruma/release/onig.wasm")).buffer);
|
|
95
|
+
const registry = new Registry({
|
|
96
|
+
onigLib: Promise.resolve({
|
|
97
|
+
createOnigScanner: (patterns) => new OnigScanner(patterns),
|
|
98
|
+
createOnigString: (s) => new OnigString(s),
|
|
99
|
+
}),
|
|
100
|
+
loadGrammar: async () =>
|
|
101
|
+
parseRawGrammar(readFileSync(require.resolve("@mmmnt/feat-grammar/feat.tmLanguage.json"), "utf8"), "feat.tmLanguage.json"),
|
|
102
|
+
});
|
|
103
|
+
const grammar = await registry.loadGrammar("source.feat");
|
|
104
|
+
|
|
105
|
+
const line = " predict rejection NotOperator:";
|
|
106
|
+
for (const t of grammar.tokenizeLine(line, null).tokens)
|
|
107
|
+
console.log(JSON.stringify(line.slice(t.startIndex, t.endIndex)), t.scopes.at(-1));
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Carry `ruleStack` from one `tokenizeLine` to the next to tokenize a whole file.
|
|
111
|
+
|
|
112
|
+
## Scopes
|
|
113
|
+
|
|
114
|
+
Every scope name ends in `.feat`. The grammar separates the four token classes
|
|
115
|
+
of the language (keywords, validated names, literals and freeform text) so a
|
|
116
|
+
spec reads as structure.
|
|
117
|
+
|
|
118
|
+
| Scope | What carries it |
|
|
119
|
+
| --- | --- |
|
|
120
|
+
| `keyword.control.pragma.feat`, `constant.numeric.version.feat` | `feat` and `1.0` in the version pragma |
|
|
121
|
+
| `keyword.declaration.spec.feat`, `entity.name.type.spec-id.feat`, `string.quoted.double.feat` | `spec`, the spec id, and its quoted name |
|
|
122
|
+
| `keyword.declaration.feat` | `context`, `aggregate`, `type`, `status` |
|
|
123
|
+
| `entity.name.namespace.feat` | the context and aggregate names |
|
|
124
|
+
| `constant.language.spec-type.feat`, `constant.language.status.feat` | `command`, `saga`, ...; `draft`, `agreed`, ... |
|
|
125
|
+
| `keyword.control.section.feat` | `construct`, `enforce`, `contract`, `examples` |
|
|
126
|
+
| `keyword.other.directive.feat` | `handler at`, `touches`, `imports`, `input`, `response`, `record`, `event`, `error`, `rejects`, `clock at`, `execute`, `fault` |
|
|
127
|
+
| `keyword.control.scenario.feat`, `string.quoted.double.scenario-name.feat` | `scenario` and `scenario outline`, and the scenario's name |
|
|
128
|
+
| `keyword.control.trigger.feat` | `when`, `deliver`, `to` |
|
|
129
|
+
| `keyword.other.actor.feat`, `variable.other.actor.feat` | `as`, and the actor name (`anonymous` included) |
|
|
130
|
+
| `entity.name.function.command.feat`, `entity.name.function.event.feat` | the command name after `when:` or `execute`; the event name after `deliver` |
|
|
131
|
+
| `keyword.control.predict.feat`, `constant.language.prediction-type.feat` | `predict`; `success`, `rejection`, `error` |
|
|
132
|
+
| `constant.other.rejection-id.feat`, `constant.other.error-code.feat` | the id after `predict rejection`; the code after `predict error` |
|
|
133
|
+
| `entity.name.type.schema.feat` | the schema name after `response` status, and after `with` |
|
|
134
|
+
| `variable.other.service.feat`, `keyword.other.assertion.feat`, `entity.name.type.record.feat` | the service key; `has` and `contains`; the record type (`INSERT`, `OrderPlaced`, ...) |
|
|
135
|
+
| `keyword.other.with.feat`, `keyword.other.ordering.feat` | `with`; `ordered`, `unordered` |
|
|
136
|
+
| `support.function.matcher.feat`, `support.type.matcher.feat` | `any`, `matching`, `absent`, `equals fixture`; the `uuid`, `timestamp`, `string`, `number`, `boolean` qualifiers |
|
|
137
|
+
| `variable.language.stimulus-ref.feat` | `@when.email`, `@deliver[1].orderId`, `@payments[0].id` |
|
|
138
|
+
| `variable.parameter.placeholder.feat` | outline placeholders such as `<email>` |
|
|
139
|
+
| `string.quoted.double.feat`, `constant.numeric.feat` | string and number literals, including a response's status code |
|
|
140
|
+
| `comment.line.number-sign.feat` | `#` to the end of the line |
|
|
141
|
+
|
|
142
|
+
These are the scopes a token of the language's own corpus produces. A theme
|
|
143
|
+
that styles the standard TextMate names (`keyword.control`, `constant.language`,
|
|
144
|
+
`entity.name.type`, `variable.language`, `support.function`) colours them with
|
|
145
|
+
no extra work.
|
|
146
|
+
|
|
147
|
+
### What the grammar does not scope
|
|
148
|
+
|
|
149
|
+
- The grammar defines `keyword.other.response.feat` and
|
|
150
|
+
`constant.numeric.status.feat` for `response <status> <Schema>` lines, but the
|
|
151
|
+
directive rule matches `response` first, so across the whole corpus neither
|
|
152
|
+
scope is ever produced: `response` takes `keyword.other.directive.feat` and the
|
|
153
|
+
status takes `constant.numeric.feat`.
|
|
154
|
+
- `given:`, `variables:` and `seed` carry no scope of their own. They read as
|
|
155
|
+
plain text in a highlighted spec.
|
|
156
|
+
- On a `fault` line only the word `fault` is scoped (as a directive). The
|
|
157
|
+
service, the `Operation`, the `Fault` and the `times` clause are plain text.
|
|
158
|
+
- `predict rejection` accepts any id made of letters, digits, `_` and `-`, so
|
|
159
|
+
`not-operator` is coloured as a rejection id even though the parser refuses
|
|
160
|
+
it. Both `UPPER_SNAKE` and `UpperCamel` ids are coloured.
|
|
161
|
+
|
|
162
|
+
## What changed in 0.1.8
|
|
163
|
+
|
|
164
|
+
- **`fault` is a directive keyword.** The rule that scopes `handler at`,
|
|
165
|
+
`touches`, `rejects` and the other directives now includes `fault`, so the
|
|
166
|
+
reserved word of `given:` fault lines highlights (ADR-0023, SPEC-CORE-001).
|
|
167
|
+
- **UpperCamel rejection ids are asserted by the tokenizer test.** The grammar
|
|
168
|
+
already coloured `predict rejection NotOperator:` as a rejection id, and the
|
|
169
|
+
test now pins it (ADR-0022, SPEC-CORE-001).
|
|
170
|
+
|
|
171
|
+
## Specs and decisions
|
|
172
|
+
|
|
173
|
+
- [Grammar reference](https://github.com/mmmnt/feature/blob/main/docs/grammar-reference.md):
|
|
174
|
+
the language this grammar colours, including the four token classes (ADR-0007)
|
|
175
|
+
- [ADR-0022: UpperCamel rejection ids](https://github.com/mmmnt/feature/blob/main/docs/adr/ADR-0022-uppercamel-rejection-ids.md)
|
|
176
|
+
- [ADR-0023: adapter interface v2](https://github.com/mmmnt/feature/blob/main/docs/adr/ADR-0023-adapter-interface-v2.md)
|
|
177
|
+
(the `fault` line)
|
|
178
|
+
- [SPEC-CORE-001](https://github.com/mmmnt/feature/blob/main/packages/feat-core/parse.feat):
|
|
179
|
+
the parser's contract
|
|
29
180
|
|
|
30
|
-
Part of [Feature](https://github.com/mmmnt/feature)
|
|
181
|
+
Part of [Feature](https://github.com/mmmnt/feature), the `.feat` execution
|
|
31
182
|
specification language. Docs: https://github.com/mmmnt/feature/wiki
|
|
32
183
|
|
|
33
184
|
MIT
|
package/feat.tmLanguage.json
CHANGED
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
}
|
|
119
119
|
},
|
|
120
120
|
{
|
|
121
|
-
"match": "^\\s+(handler at|touches|imports|input|response|record|event|error|rejects|clock at|execute)\\b",
|
|
121
|
+
"match": "^\\s+(handler at|touches|imports|input|response|record|event|error|rejects|clock at|execute|fault)\\b",
|
|
122
122
|
"captures": {
|
|
123
123
|
"1": {
|
|
124
124
|
"name": "keyword.other.directive.feat"
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mmmnt/feat-grammar",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "TextMate grammar for the .feat execution specification language — powers editor extensions, Shiki, and any TextMate-compatible highlighter",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|