flix-textmate 0.0.0-stage → 0.1.2
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.md +194 -0
- package/README.md +251 -2
- package/package.json +61 -4
- package/syntaxes/flix.tmLanguage.json +648 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
==============
|
|
3
|
+
|
|
4
|
+
_Version 2.0, January 2004_
|
|
5
|
+
_<<http://www.apache.org/licenses/>>_
|
|
6
|
+
|
|
7
|
+
### Terms and Conditions for use, reproduction, and distribution
|
|
8
|
+
|
|
9
|
+
#### 1. Definitions
|
|
10
|
+
|
|
11
|
+
“License” shall mean the terms and conditions for use, reproduction, and
|
|
12
|
+
distribution as defined by Sections 1 through 9 of this document.
|
|
13
|
+
|
|
14
|
+
“Licensor” shall mean the copyright owner or entity authorized by the copyright
|
|
15
|
+
owner that is granting the License.
|
|
16
|
+
|
|
17
|
+
“Legal Entity” shall mean the union of the acting entity and all other entities
|
|
18
|
+
that control, are controlled by, or are under common control with that entity.
|
|
19
|
+
For the purposes of this definition, “control” means **(i)** the power, direct or
|
|
20
|
+
indirect, to cause the direction or management of such entity, whether by
|
|
21
|
+
contract or otherwise, or **(ii)** ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or **(iii)** beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
“You” (or “Your”) shall mean an individual or Legal Entity exercising
|
|
25
|
+
permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
“Source” form shall mean the preferred form for making modifications, including
|
|
28
|
+
but not limited to software source code, documentation source, and configuration
|
|
29
|
+
files.
|
|
30
|
+
|
|
31
|
+
“Object” form shall mean any form resulting from mechanical transformation or
|
|
32
|
+
translation of a Source form, including but not limited to compiled object code,
|
|
33
|
+
generated documentation, and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
“Work” shall mean the work of authorship, whether in Source or Object form, made
|
|
36
|
+
available under the License, as indicated by a copyright notice that is included
|
|
37
|
+
in or attached to the work (an example is provided in the Appendix below).
|
|
38
|
+
|
|
39
|
+
“Derivative Works” shall mean any work, whether in Source or Object form, that
|
|
40
|
+
is based on (or derived from) the Work and for which the editorial revisions,
|
|
41
|
+
annotations, elaborations, or other modifications represent, as a whole, an
|
|
42
|
+
original work of authorship. For the purposes of this License, Derivative Works
|
|
43
|
+
shall not include works that remain separable from, or merely link (or bind by
|
|
44
|
+
name) to the interfaces of, the Work and Derivative Works thereof.
|
|
45
|
+
|
|
46
|
+
“Contribution” shall mean any work of authorship, including the original version
|
|
47
|
+
of the Work and any modifications or additions to that Work or Derivative Works
|
|
48
|
+
thereof, that is intentionally submitted to Licensor for inclusion in the Work
|
|
49
|
+
by the copyright owner or by an individual or Legal Entity authorized to submit
|
|
50
|
+
on behalf of the copyright owner. For the purposes of this definition,
|
|
51
|
+
“submitted” means any form of electronic, verbal, or written communication sent
|
|
52
|
+
to the Licensor or its representatives, including but not limited to
|
|
53
|
+
communication on electronic mailing lists, source code control systems, and
|
|
54
|
+
issue tracking systems that are managed by, or on behalf of, the Licensor for
|
|
55
|
+
the purpose of discussing and improving the Work, but excluding communication
|
|
56
|
+
that is conspicuously marked or otherwise designated in writing by the copyright
|
|
57
|
+
owner as “Not a Contribution.”
|
|
58
|
+
|
|
59
|
+
“Contributor” shall mean Licensor and any individual or Legal Entity on behalf
|
|
60
|
+
of whom a Contribution has been received by Licensor and subsequently
|
|
61
|
+
incorporated within the Work.
|
|
62
|
+
|
|
63
|
+
#### 2. Grant of Copyright License
|
|
64
|
+
|
|
65
|
+
Subject to the terms and conditions of this License, each Contributor hereby
|
|
66
|
+
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
|
67
|
+
irrevocable copyright license to reproduce, prepare Derivative Works of,
|
|
68
|
+
publicly display, publicly perform, sublicense, and distribute the Work and such
|
|
69
|
+
Derivative Works in Source or Object form.
|
|
70
|
+
|
|
71
|
+
#### 3. Grant of Patent License
|
|
72
|
+
|
|
73
|
+
Subject to the terms and conditions of this License, each Contributor hereby
|
|
74
|
+
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
|
75
|
+
irrevocable (except as stated in this section) patent license to make, have
|
|
76
|
+
made, use, offer to sell, sell, import, and otherwise transfer the Work, where
|
|
77
|
+
such license applies only to those patent claims licensable by such Contributor
|
|
78
|
+
that are necessarily infringed by their Contribution(s) alone or by combination
|
|
79
|
+
of their Contribution(s) with the Work to which such Contribution(s) was
|
|
80
|
+
submitted. If You institute patent litigation against any entity (including a
|
|
81
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work or a
|
|
82
|
+
Contribution incorporated within the Work constitutes direct or contributory
|
|
83
|
+
patent infringement, then any patent licenses granted to You under this License
|
|
84
|
+
for that Work shall terminate as of the date such litigation is filed.
|
|
85
|
+
|
|
86
|
+
#### 4. Redistribution
|
|
87
|
+
|
|
88
|
+
You may reproduce and distribute copies of the Work or Derivative Works thereof
|
|
89
|
+
in any medium, with or without modifications, and in Source or Object form,
|
|
90
|
+
provided that You meet the following conditions:
|
|
91
|
+
|
|
92
|
+
* **(a)** You must give any other recipients of the Work or Derivative Works a copy of
|
|
93
|
+
this License; and
|
|
94
|
+
* **(b)** You must cause any modified files to carry prominent notices stating that You
|
|
95
|
+
changed the files; and
|
|
96
|
+
* **(c)** You must retain, in the Source form of any Derivative Works that You distribute,
|
|
97
|
+
all copyright, patent, trademark, and attribution notices from the Source form
|
|
98
|
+
of the Work, excluding those notices that do not pertain to any part of the
|
|
99
|
+
Derivative Works; and
|
|
100
|
+
* **(d)** If the Work includes a “NOTICE” text file as part of its distribution, then any
|
|
101
|
+
Derivative Works that You distribute must include a readable copy of the
|
|
102
|
+
attribution notices contained within such NOTICE file, excluding those notices
|
|
103
|
+
that do not pertain to any part of the Derivative Works, in at least one of the
|
|
104
|
+
following places: within a NOTICE text file distributed as part of the
|
|
105
|
+
Derivative Works; within the Source form or documentation, if provided along
|
|
106
|
+
with the Derivative Works; or, within a display generated by the Derivative
|
|
107
|
+
Works, if and wherever such third-party notices normally appear. The contents of
|
|
108
|
+
the NOTICE file are for informational purposes only and do not modify the
|
|
109
|
+
License. You may add Your own attribution notices within Derivative Works that
|
|
110
|
+
You distribute, alongside or as an addendum to the NOTICE text from the Work,
|
|
111
|
+
provided that such additional attribution notices cannot be construed as
|
|
112
|
+
modifying the License.
|
|
113
|
+
|
|
114
|
+
You may add Your own copyright statement to Your modifications and may provide
|
|
115
|
+
additional or different license terms and conditions for use, reproduction, or
|
|
116
|
+
distribution of Your modifications, or for any such Derivative Works as a whole,
|
|
117
|
+
provided Your use, reproduction, and distribution of the Work otherwise complies
|
|
118
|
+
with the conditions stated in this License.
|
|
119
|
+
|
|
120
|
+
#### 5. Submission of Contributions
|
|
121
|
+
|
|
122
|
+
Unless You explicitly state otherwise, any Contribution intentionally submitted
|
|
123
|
+
for inclusion in the Work by You to the Licensor shall be under the terms and
|
|
124
|
+
conditions of this License, without any additional terms or conditions.
|
|
125
|
+
Notwithstanding the above, nothing herein shall supersede or modify the terms of
|
|
126
|
+
any separate license agreement you may have executed with Licensor regarding
|
|
127
|
+
such Contributions.
|
|
128
|
+
|
|
129
|
+
#### 6. Trademarks
|
|
130
|
+
|
|
131
|
+
This License does not grant permission to use the trade names, trademarks,
|
|
132
|
+
service marks, or product names of the Licensor, except as required for
|
|
133
|
+
reasonable and customary use in describing the origin of the Work and
|
|
134
|
+
reproducing the content of the NOTICE file.
|
|
135
|
+
|
|
136
|
+
#### 7. Disclaimer of Warranty
|
|
137
|
+
|
|
138
|
+
Unless required by applicable law or agreed to in writing, Licensor provides the
|
|
139
|
+
Work (and each Contributor provides its Contributions) on an “AS IS” BASIS,
|
|
140
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
|
|
141
|
+
including, without limitation, any warranties or conditions of TITLE,
|
|
142
|
+
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
|
|
143
|
+
solely responsible for determining the appropriateness of using or
|
|
144
|
+
redistributing the Work and assume any risks associated with Your exercise of
|
|
145
|
+
permissions under this License.
|
|
146
|
+
|
|
147
|
+
#### 8. Limitation of Liability
|
|
148
|
+
|
|
149
|
+
In no event and under no legal theory, whether in tort (including negligence),
|
|
150
|
+
contract, or otherwise, unless required by applicable law (such as deliberate
|
|
151
|
+
and grossly negligent acts) or agreed to in writing, shall any Contributor be
|
|
152
|
+
liable to You for damages, including any direct, indirect, special, incidental,
|
|
153
|
+
or consequential damages of any character arising as a result of this License or
|
|
154
|
+
out of the use or inability to use the Work (including but not limited to
|
|
155
|
+
damages for loss of goodwill, work stoppage, computer failure or malfunction, or
|
|
156
|
+
any and all other commercial damages or losses), even if such Contributor has
|
|
157
|
+
been advised of the possibility of such damages.
|
|
158
|
+
|
|
159
|
+
#### 9. Accepting Warranty or Additional Liability
|
|
160
|
+
|
|
161
|
+
While redistributing the Work or Derivative Works thereof, You may choose to
|
|
162
|
+
offer, and charge a fee for, acceptance of support, warranty, indemnity, or
|
|
163
|
+
other liability obligations and/or rights consistent with this License. However,
|
|
164
|
+
in accepting such obligations, You may act only on Your own behalf and on Your
|
|
165
|
+
sole responsibility, not on behalf of any other Contributor, and only if You
|
|
166
|
+
agree to indemnify, defend, and hold each Contributor harmless for any liability
|
|
167
|
+
incurred by, or claims asserted against, such Contributor by reason of your
|
|
168
|
+
accepting any such warranty or additional liability.
|
|
169
|
+
|
|
170
|
+
_END OF TERMS AND CONDITIONS_
|
|
171
|
+
|
|
172
|
+
### APPENDIX: How to apply the Apache License to your work
|
|
173
|
+
|
|
174
|
+
To apply the Apache License to your work, attach the following boilerplate
|
|
175
|
+
notice, with the fields enclosed by brackets `[]` replaced with your own
|
|
176
|
+
identifying information. (Don't include the brackets!) The text should be
|
|
177
|
+
enclosed in the appropriate comment syntax for the file format. We also
|
|
178
|
+
recommend that a file or class name and description of purpose be included on
|
|
179
|
+
the same “printed page” as the copyright notice for easier identification within
|
|
180
|
+
third-party archives.
|
|
181
|
+
|
|
182
|
+
Copyright [yyyy] [name of copyright owner]
|
|
183
|
+
|
|
184
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
185
|
+
you may not use this file except in compliance with the License.
|
|
186
|
+
You may obtain a copy of the License at
|
|
187
|
+
|
|
188
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
189
|
+
|
|
190
|
+
Unless required by applicable law or agreed to in writing, software
|
|
191
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
192
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
193
|
+
See the License for the specific language governing permissions and
|
|
194
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,252 @@
|
|
|
1
|
-
#
|
|
1
|
+
# flix-textmate
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/wstein/flix-textmate/actions/workflows/ci.yml)
|
|
4
|
+
[](LICENSE.md)
|
|
5
|
+
[](package.json)
|
|
6
|
+
[](docs/SCOPES.md)
|
|
7
|
+
[](tests/corpus-baseline.json)
|
|
8
|
+
[](syntaxes/flix.tmLanguage.json)
|
|
9
|
+
|
|
10
|
+
A TextMate grammar for the [Flix](https://flix.dev) programming language, authored in
|
|
11
|
+
TypeScript and emitted as `syntaxes/flix.tmLanguage.json`.
|
|
12
|
+
|
|
13
|
+
## Why this exists
|
|
14
|
+
|
|
15
|
+
Flix has two independent highlighting paths, and neither covers the TextMate surface well:
|
|
16
|
+
|
|
17
|
+
- The official VS Code extension, [`flix/vscode-flix`](https://github.com/flix/vscode-flix),
|
|
18
|
+
declares `"grammars": []`. It highlights entirely through LSP semantic tokens, so a
|
|
19
|
+
`.flix` file has no colour until the compiler starts, and none at all if it fails.
|
|
20
|
+
- [`flix/textmate`](https://github.com/flix/textmate) provides the `source.flix` grammar
|
|
21
|
+
that GitHub Linguist vendors, and therefore what colours Flix on github.com and in every
|
|
22
|
+
Shiki-based documentation site. It has drifted from the compiler — see
|
|
23
|
+
[`docs/DEFECTS.md`](docs/DEFECTS.md).
|
|
24
|
+
|
|
25
|
+
This project is a drop-in replacement for the latter: same file name, same `scopeName`,
|
|
26
|
+
same non-standard `copyright_notice` / `license` keys, so the emitted JSON can be
|
|
27
|
+
contributed upstream unchanged.
|
|
28
|
+
|
|
29
|
+
## Using the grammar
|
|
30
|
+
|
|
31
|
+
The artifact is the single file [`syntaxes/flix.tmLanguage.json`](syntaxes/flix.tmLanguage.json).
|
|
32
|
+
It has no runtime dependencies. Install the npm package once the first release is
|
|
33
|
+
published, or vendor the JSON from a Git tag.
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install flix-textmate
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
To vendor from Git:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
curl -fsSLO https://raw.githubusercontent.com/wstein/flix-textmate/v0.1.1/syntaxes/flix.tmLanguage.json
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
A VS Code extension contributes it against the `flix` language identifier:
|
|
46
|
+
|
|
47
|
+
```json
|
|
48
|
+
{
|
|
49
|
+
"contributes": {
|
|
50
|
+
"grammars": [
|
|
51
|
+
{
|
|
52
|
+
"language": "flix",
|
|
53
|
+
"scopeName": "source.flix",
|
|
54
|
+
"path": "./syntaxes/flix.tmLanguage.json"
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
[Shiki](https://shiki.style) — and anything else built on `vscode-textmate`, the engine this
|
|
62
|
+
repository's own tests tokenize with — takes it as a language:
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
import { createHighlighter } from 'shiki';
|
|
66
|
+
import flix from 'flix-textmate' with { type: 'json' };
|
|
67
|
+
|
|
68
|
+
const highlighter = await createHighlighter({
|
|
69
|
+
langs: [{ ...flix, name: 'flix' }],
|
|
70
|
+
themes: ['github-dark'],
|
|
71
|
+
});
|
|
72
|
+
highlighter.codeToHtml(source, { lang: 'flix', theme: 'github-dark' });
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Every scope the grammar can emit is enumerated in [`docs/SCOPES.md`](docs/SCOPES.md). The
|
|
76
|
+
taxonomy is the mainstream VS Code one, so a stock theme needs no configuration.
|
|
77
|
+
|
|
78
|
+
## Source of truth
|
|
79
|
+
|
|
80
|
+
Nothing in the grammar is written from memory. Every token class is derived from the
|
|
81
|
+
reference compiler, [`flix/flix`](https://github.com/flix/flix), under
|
|
82
|
+
`main/src/ca/uwaterloo/flix/language/`:
|
|
83
|
+
|
|
84
|
+
| File | What it decides |
|
|
85
|
+
| ------------------------------ | ------------------------------------------------------------ |
|
|
86
|
+
| `language/phase/Lexer.scala` | tokenization: literals, escapes, comments, character classes |
|
|
87
|
+
| `language/ast/TokenKind.scala` | the exhaustive token list |
|
|
88
|
+
| `language/phase/Parser2.scala` | where a name may appear, and in which case |
|
|
89
|
+
| `language/phase/Weeder2.scala` | the annotation table |
|
|
90
|
+
|
|
91
|
+
The grammar follows the **lexer**, not the weeder. Flix deliberately lexes more than it
|
|
92
|
+
accepts and rejects the remainder later; staying permissive is what keeps highlighting
|
|
93
|
+
stable in a file that does not yet compile.
|
|
94
|
+
|
|
95
|
+
## Development
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
npm install
|
|
99
|
+
npm run build # TypeScript -> syntaxes/flix.tmLanguage.json
|
|
100
|
+
npm run verify # typecheck + lint + build-is-current + every test suite
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Individual steps:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
npm run typecheck # tsc --noEmit
|
|
107
|
+
npm run lint # eslint, the structural grammar lint, then the doc checks
|
|
108
|
+
npm run fmt # prettier --write, then eslint --fix
|
|
109
|
+
npm run check:build # rebuild and fail if the committed JSON changed
|
|
110
|
+
npm run check:scopes # fail if the grammar emits a scope docs/SCOPES.md omits
|
|
111
|
+
npm run check:badges # fail if a README badge misstates its source file
|
|
112
|
+
npm run test:unit # inline scope assertions, tests/unit/**
|
|
113
|
+
npm run test:unscoped # identifiers that must receive no scope at all
|
|
114
|
+
npm run test:scripts # unit tests for the check scripts, tests/scripts/**
|
|
115
|
+
npm run test:snap # full-tokenization snapshots, tests/snap/**
|
|
116
|
+
npm run update:snap # rewrite snapshots (review the diff!)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Against a Flix source tree (not vendored, so CI does not run these):
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
export FLIX_SOURCE=/path/to/flix # https://github.com/flix/flix
|
|
123
|
+
export TREE_SITTER_FLIX=/path/to/tree-sitter-flix
|
|
124
|
+
|
|
125
|
+
npm run audit
|
|
126
|
+
npm run check:boundaries
|
|
127
|
+
npm run docs:mapping
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Each also takes an explicit flag (`--corpus`, `--tree-sitter`, `--flix-source`). There is no
|
|
131
|
+
default location: a hardcoded fallback works on one machine and fails confusingly on every
|
|
132
|
+
other.
|
|
133
|
+
|
|
134
|
+
`check:boundaries` is the only gate with an **independent oracle**. It parses the corpus
|
|
135
|
+
with [`tree-sitter-flix`](https://github.com/wstein/tree-sitter-flix) and asserts that no
|
|
136
|
+
scoped TextMate token covers a strict sub-range of an atomic tree-sitter token — comparing
|
|
137
|
+
token _boundaries_, never scope names, since the two taxonomies deliberately differ. Every
|
|
138
|
+
other gate answers "does a scope exist"; only this one can answer "is it on the right
|
|
139
|
+
characters".
|
|
140
|
+
|
|
141
|
+
`audit` enforces two things: no file may end with a rule still open (a hard gate — currently
|
|
142
|
+
zero across 895 files), and scope coverage may not fall below `tests/corpus-baseline.json`.
|
|
143
|
+
Coverage is a **ratchet, not a target**: this grammar deliberately leaves expression-position
|
|
144
|
+
identifiers bare, so chasing the number would mean inventing the heuristics it refuses to
|
|
145
|
+
ship. That is also why the coverage badge above is a fact, not a goal.
|
|
146
|
+
|
|
147
|
+
Keywords, operators, and annotation names are not written by hand. They are extracted from
|
|
148
|
+
the compiler into `src/typescript/lexicon.generated.ts`, which is committed so CI needs no
|
|
149
|
+
compiler checkout:
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
npm run extract:lexicon # reads $FLIX_SOURCE
|
|
153
|
+
npm run check:lexicon # fail if the committed manifest differs from a fresh run
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
`lexicon.generated.ts` is excluded from Prettier. Reformatting a generated file means the
|
|
157
|
+
committed copy stops matching what its generator emits, so regenerating always dirties the
|
|
158
|
+
tree — `check:lexicon` is what makes that visible.
|
|
159
|
+
|
|
160
|
+
The grammar maps that manifest with `Record<Keyword, ScopeName>`, so a keyword added to or
|
|
161
|
+
removed from Flix becomes a **type error** until it is classified. Combined with
|
|
162
|
+
`ScopeName` being `` `${string}.flix` ``, three classes of defect are unrepresentable:
|
|
163
|
+
a keyword that does not exist, a keyword left unscoped, and a scope missing its language
|
|
164
|
+
suffix.
|
|
165
|
+
|
|
166
|
+
`syntaxes/flix.tmLanguage.json` is generated **and committed**. CI runs `check:build`, so a
|
|
167
|
+
grammar edit that is not rebuilt fails the build rather than shipping stale JSON.
|
|
168
|
+
|
|
169
|
+
### Writing tests
|
|
170
|
+
|
|
171
|
+
Three suites, each answering a different question:
|
|
172
|
+
|
|
173
|
+
- `tests/unit/*.test.flix` — intent. Each file opens with `// SYNTAX TEST "source.flix"`
|
|
174
|
+
and asserts scopes with caret lines. These encode _why_ a rule exists; most of them are
|
|
175
|
+
regressions for a specific defect in the previous grammar.
|
|
176
|
+
- `tests/snap/*.test.flix` — ground truth. `npm run update:snap` records the complete
|
|
177
|
+
tokenization, which is also the fastest way to discover the exact column of a token when
|
|
178
|
+
writing a unit assertion.
|
|
179
|
+
- `tests/scripts/*.test.mjs` — the gates themselves, run under `node --test`. A gate that
|
|
180
|
+
cannot fail is indistinguishable from no gate, so anything in `scripts/` that decides
|
|
181
|
+
pass or fail gets its failure modes exercised here.
|
|
182
|
+
|
|
183
|
+
Fixture lines are indented by four spaces so an assertion line's own `//` prefix does not
|
|
184
|
+
overlap the columns it points at.
|
|
185
|
+
|
|
186
|
+
A negative assertion needs care: `vscode-tmgrammar-test` compares scopes by exact string
|
|
187
|
+
equality, so `- keyword` passes against `keyword.control.flix` and proves nothing. Cases of
|
|
188
|
+
the form "this must _not_ be highlighted" belong in `scripts/check-unscoped.mjs`.
|
|
189
|
+
|
|
190
|
+
## npm releases
|
|
191
|
+
|
|
192
|
+
Run [Prepare and publish npm package][npm-workflow] on `main` with
|
|
193
|
+
`publish_npm` off to build and test a tarball. For the first release,
|
|
194
|
+
download the `npm-package` artifact, extract it, and run
|
|
195
|
+
`npm publish ./flix-textmate-*.tgz --access public` with an npm account that can
|
|
196
|
+
publish the package. Then configure an npm [trusted publisher][npm-trusted] for
|
|
197
|
+
`wstein/flix-textmate`, workflow filename `npm-publish.yml`, environment `npm`.
|
|
198
|
+
Use the workflow with `publish_npm` on for subsequent releases.
|
|
199
|
+
|
|
200
|
+
[npm-workflow]: https://github.com/wstein/flix-textmate/actions/workflows/npm-publish.yml
|
|
201
|
+
[npm-trusted]: https://docs.npmjs.com/trusted-publishers/
|
|
202
|
+
|
|
203
|
+
## Contributing
|
|
204
|
+
|
|
205
|
+
Run `npm run fmt && npm run verify` before every commit, and `npm run audit` after any rule
|
|
206
|
+
change — commit the refreshed `tests/corpus-baseline.json` alongside it. Commits follow
|
|
207
|
+
[Conventional Commits](https://www.conventionalcommits.org); every defect fixed gets a unit
|
|
208
|
+
test that fails before the fix. Adding a scope means documenting it in `docs/SCOPES.md` in
|
|
209
|
+
the same change — `npm run check:scopes` enforces that, because requiring it in prose is
|
|
210
|
+
what let the incumbent grammar drift. For the same reason `npm run check:badges` re-derives
|
|
211
|
+
the numeric badges above from `package.json` and `tests/corpus-baseline.json`, so a stale
|
|
212
|
+
one fails the build instead of misinforming the landing page.
|
|
213
|
+
|
|
214
|
+
Dependency and workflow updates arrive as grouped weekly Dependabot pull requests
|
|
215
|
+
([`.github/dependabot.yml`](.github/dependabot.yml)), and run the same CI gates as any
|
|
216
|
+
other pull request.
|
|
217
|
+
|
|
218
|
+
## Documentation
|
|
219
|
+
|
|
220
|
+
- [`docs/SCOPES.md`](docs/SCOPES.md) — every scope, and why it is what it is.
|
|
221
|
+
- [`docs/SCOPE-MAPPING.md`](docs/SCOPE-MAPPING.md) — correspondence with `tree-sitter-flix`.
|
|
222
|
+
- [`docs/LEXICAL-SOURCE.md`](docs/LEXICAL-SOURCE.md) — source pin, CI regeneration, and vocabulary limits.
|
|
223
|
+
- [`docs/DEFECTS.md`](docs/DEFECTS.md) — what is wrong with the grammar this replaces.
|
|
224
|
+
|
|
225
|
+
## Licence
|
|
226
|
+
|
|
227
|
+
Apache License 2.0. The grammar carries forward the copyright notice of the upstream
|
|
228
|
+
`flix/textmate` grammar it replaces.
|
|
229
|
+
|
|
230
|
+
### Flix 0.80 source baseline
|
|
231
|
+
|
|
232
|
+
The lexical inventory and corpus checks require Flix v0.80.0 at
|
|
233
|
+
`0c641c73c4635dee992d01c4364f224ea56d9a46`. The boundary and scope-mapping
|
|
234
|
+
oracle is tree-sitter-flix at `377841bfbedcd10d818e213b8b8e34c51d081119`
|
|
235
|
+
([migration PR #13](https://github.com/wstein/tree-sitter-flix/pull/13));
|
|
236
|
+
this pin does not imply that the PR has merged. External checks reject another HEAD.
|
|
237
|
+
|
|
238
|
+
The Flix 0.80 inventory includes `val` as a keyword and excludes the retired keywords `law` and `lawful`. Neither those names nor a
|
|
239
|
+
following name receive declaration scopes. Operators and primitive types are unchanged.
|
|
240
|
+
The accepted annotation inventory removes `Export` and replaces `LoweringTarget` with
|
|
241
|
+
`LoweringTargetChannel` and `LoweringTargetDatalog`. Annotation highlighting remains
|
|
242
|
+
lexical: every `@` followed by ASCII letters is highlighted, including unknown names.
|
|
243
|
+
|
|
244
|
+
The 0.80 corpus has 895 files, 65.79% coverage and 64 scopes; no file ends in an open rule.
|
|
245
|
+
The earlier 0.79 corpus contained 894 files, with 65.79% coverage and 64 scopes.
|
|
246
|
+
Both the original grammar at `ead9878a26cae5b2568768eddbd6f5c0789ba69e` and
|
|
247
|
+
the migrated grammar measure 65.79% on these same 5,218,078 non-whitespace
|
|
248
|
+
characters, with zero files ending in an open rule.
|
|
249
|
+
The previous 688-file baseline had no recorded source revision and cannot be compared as
|
|
250
|
+
the same corpus. The former lexicon revision has 873 tracked Flix files; upstream adds
|
|
251
|
+
35 and removes 14 by 0.79 (renames counted separately). Coverage is a measurement,
|
|
252
|
+
not a syntax conformance claim or a target for expression-name heuristics.
|
package/package.json
CHANGED
|
@@ -1,6 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flix-textmate",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "TextMate grammar for the Flix programming language",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "Werner Stein",
|
|
9
|
+
"email": "claude@wstein.de"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/wstein/flix-textmate.git"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"flix",
|
|
17
|
+
"textmate",
|
|
18
|
+
"tmlanguage",
|
|
19
|
+
"syntax-highlighting"
|
|
20
|
+
],
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=22.18.0"
|
|
23
|
+
},
|
|
24
|
+
"exports": "./syntaxes/flix.tmLanguage.json",
|
|
25
|
+
"files": [
|
|
26
|
+
"syntaxes/flix.tmLanguage.json"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "node src/typescript/GenerateTmLanguageFile.ts",
|
|
30
|
+
"check:build": "npm run build && git diff --exit-code -- syntaxes/flix.tmLanguage.json",
|
|
31
|
+
"typecheck": "tsc --noEmit",
|
|
32
|
+
"lint": "eslint . && npm run lint:grammar && npm run check:scopes && npm run check:badges && npm run check:pin",
|
|
33
|
+
"lint:grammar": "node scripts/lint-grammar.mjs",
|
|
34
|
+
"fmt": "prettier --write . && eslint --fix .",
|
|
35
|
+
"fmt:check": "prettier --check .",
|
|
36
|
+
"test": "npm-run-all -c test:unit test:unscoped test:scripts",
|
|
37
|
+
"test:unit": "vscode-tmgrammar-test -g syntaxes/flix.tmLanguage.json 'tests/unit/**/*.test.flix'",
|
|
38
|
+
"test:snap": "vscode-tmgrammar-snap --config tests/tmgrammar.config.json -g syntaxes/flix.tmLanguage.json 'tests/snap/**/*.test.flix'",
|
|
39
|
+
"update:snap": "vscode-tmgrammar-snap --updateSnapshot --config tests/tmgrammar.config.json -g syntaxes/flix.tmLanguage.json 'tests/snap/**/*.test.flix'",
|
|
40
|
+
"verify": "npm-run-all -c typecheck lint check:build test:unit test:unscoped test:scripts test:snap",
|
|
41
|
+
"extract:lexicon": "node scripts/extract-lexicon.mjs",
|
|
42
|
+
"test:unscoped": "node scripts/check-unscoped.mjs",
|
|
43
|
+
"test:scripts": "node --test 'tests/scripts/**/*.test.mjs'",
|
|
44
|
+
"audit": "node scripts/audit-corpus.mjs",
|
|
45
|
+
"docs:mapping": "node scripts/generate-scope-mapping.mjs",
|
|
46
|
+
"check:lexicon": "node scripts/extract-lexicon.mjs && git diff --exit-code -- src/typescript/lexicon.generated.ts",
|
|
47
|
+
"check:scopes": "node scripts/check-scopes-documented.mjs",
|
|
48
|
+
"check:badges": "node scripts/check-badges.mjs",
|
|
49
|
+
"check:boundaries": "node scripts/check-token-boundaries.mjs",
|
|
50
|
+
"check:pin": "node scripts/check-flix-pin.mjs"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@eslint/js": "^10.0.1",
|
|
54
|
+
"@types/node": "^22.20.5",
|
|
55
|
+
"ajv": "^8.17.1",
|
|
56
|
+
"eslint": "^10.14.0",
|
|
57
|
+
"npm-run-all2": "^9.0.4",
|
|
58
|
+
"prettier": "^3.10.1",
|
|
59
|
+
"typescript": "^5.7.2",
|
|
60
|
+
"typescript-eslint": "^8.72.2",
|
|
61
|
+
"vscode-tmgrammar-test": "^0.1.3"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,648 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
|
|
3
|
+
"copyright_notice": "Copyright 2020 Stephen Tetley, Magnus Madsen; Copyright 2026 Werner Stein",
|
|
4
|
+
"license": "Apache License, Version 2.0",
|
|
5
|
+
"name": "Flix",
|
|
6
|
+
"scopeName": "source.flix",
|
|
7
|
+
"fileTypes": [
|
|
8
|
+
"flix"
|
|
9
|
+
],
|
|
10
|
+
"patterns": [
|
|
11
|
+
{
|
|
12
|
+
"include": "#comments"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"include": "#literals"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"include": "#annotations"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"include": "#declarations"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"include": "#keywords"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"include": "#names"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"include": "#operators"
|
|
31
|
+
}
|
|
32
|
+
],
|
|
33
|
+
"repository": {
|
|
34
|
+
"comments": {
|
|
35
|
+
"patterns": [
|
|
36
|
+
{
|
|
37
|
+
"include": "#block-comment"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"include": "#doc-comment"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"include": "#line-comment"
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
},
|
|
47
|
+
"block-comment": {
|
|
48
|
+
"comment": "Nests, per Lexer.acceptBlockComment, via the self-include below.",
|
|
49
|
+
"name": "comment.block.flix",
|
|
50
|
+
"begin": "/\\*",
|
|
51
|
+
"beginCaptures": {
|
|
52
|
+
"0": {
|
|
53
|
+
"name": "punctuation.definition.comment.begin.flix"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"end": "\\*/",
|
|
57
|
+
"endCaptures": {
|
|
58
|
+
"0": {
|
|
59
|
+
"name": "punctuation.definition.comment.end.flix"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"patterns": [
|
|
63
|
+
{
|
|
64
|
+
"include": "#block-comment"
|
|
65
|
+
}
|
|
66
|
+
]
|
|
67
|
+
},
|
|
68
|
+
"doc-comment": {
|
|
69
|
+
"comment": "Exactly three slashes. Lexer.acceptLineOrDocComment, slashCount == 1.",
|
|
70
|
+
"match": "(///)(?!/).*$",
|
|
71
|
+
"name": "comment.line.documentation.flix",
|
|
72
|
+
"captures": {
|
|
73
|
+
"1": {
|
|
74
|
+
"name": "punctuation.definition.comment.flix"
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
"line-comment": {
|
|
79
|
+
"patterns": [
|
|
80
|
+
{
|
|
81
|
+
"comment": "Two slashes not followed by a third.",
|
|
82
|
+
"match": "(//)(?!/).*$",
|
|
83
|
+
"name": "comment.line.double-slash.flix",
|
|
84
|
+
"captures": {
|
|
85
|
+
"1": {
|
|
86
|
+
"name": "punctuation.definition.comment.flix"
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"comment": "Four or more slashes: not documentation, per the slash count above.",
|
|
92
|
+
"match": "(/{4,}).*$",
|
|
93
|
+
"name": "comment.line.double-slash.flix",
|
|
94
|
+
"captures": {
|
|
95
|
+
"1": {
|
|
96
|
+
"name": "punctuation.definition.comment.flix"
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
},
|
|
102
|
+
"literals": {
|
|
103
|
+
"patterns": [
|
|
104
|
+
{
|
|
105
|
+
"include": "#regex-literal"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"include": "#debug-string"
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"include": "#string"
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"include": "#char"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"include": "#builtin"
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"include": "#number-hex"
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
"include": "#number"
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"include": "#holes"
|
|
127
|
+
}
|
|
128
|
+
]
|
|
129
|
+
},
|
|
130
|
+
"string-escape": {
|
|
131
|
+
"comment": "`Lexer.consumeSingleEscapes` accepts a backslash followed by any character; `\\uXXXX` is kept whole because that is the unit the weeder decodes.",
|
|
132
|
+
"match": "\\\\(?:u[0-9a-fA-F]{4}|.)",
|
|
133
|
+
"name": "constant.character.escape.flix"
|
|
134
|
+
},
|
|
135
|
+
"string": {
|
|
136
|
+
"comment": "Single-line: `Lexer.acceptString` returns UnterminatedString on `\\n`, so the end pattern is line-anchored rather than running to the next quote in the file.",
|
|
137
|
+
"name": "string.quoted.double.flix",
|
|
138
|
+
"begin": "\"",
|
|
139
|
+
"beginCaptures": {
|
|
140
|
+
"0": {
|
|
141
|
+
"name": "punctuation.definition.string.begin.flix"
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
"end": "\"|$",
|
|
145
|
+
"endCaptures": {
|
|
146
|
+
"0": {
|
|
147
|
+
"name": "punctuation.definition.string.end.flix"
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
"patterns": [
|
|
151
|
+
{
|
|
152
|
+
"include": "#string-escape"
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
"include": "#string-interpolation"
|
|
156
|
+
}
|
|
157
|
+
]
|
|
158
|
+
},
|
|
159
|
+
"debug-string": {
|
|
160
|
+
"comment": "`d\"...\"` is TokenKind.DebugInterpolator; see the dispatch in Lexer.scanToken.",
|
|
161
|
+
"name": "string.quoted.double.flix",
|
|
162
|
+
"begin": "(?<![A-Za-z0-9_!$])(d)(\")",
|
|
163
|
+
"beginCaptures": {
|
|
164
|
+
"1": {
|
|
165
|
+
"name": "keyword.other.debug.flix"
|
|
166
|
+
},
|
|
167
|
+
"2": {
|
|
168
|
+
"name": "punctuation.definition.string.begin.flix"
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
"end": "\"|$",
|
|
172
|
+
"endCaptures": {
|
|
173
|
+
"0": {
|
|
174
|
+
"name": "punctuation.definition.string.end.flix"
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
"patterns": [
|
|
178
|
+
{
|
|
179
|
+
"include": "#string-escape"
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
"include": "#string-interpolation"
|
|
183
|
+
}
|
|
184
|
+
]
|
|
185
|
+
},
|
|
186
|
+
"string-interpolation": {
|
|
187
|
+
"comment": "The escape rule is listed before this one in #string, so `\\${` stays a literal — matching Lexer.acceptString, which requires the `$` to be unescaped.",
|
|
188
|
+
"begin": "(\\$)(\\{)",
|
|
189
|
+
"beginCaptures": {
|
|
190
|
+
"1": {
|
|
191
|
+
"name": "punctuation.definition.template-expression.begin.flix"
|
|
192
|
+
},
|
|
193
|
+
"2": {
|
|
194
|
+
"name": "punctuation.definition.template-expression.begin.flix"
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
"end": "\\}|$",
|
|
198
|
+
"endCaptures": {
|
|
199
|
+
"0": {
|
|
200
|
+
"name": "punctuation.definition.template-expression.end.flix"
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
"contentName": "meta.embedded.line.flix",
|
|
204
|
+
"patterns": [
|
|
205
|
+
{
|
|
206
|
+
"include": "#interpolation-block"
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
"include": "$self"
|
|
210
|
+
}
|
|
211
|
+
]
|
|
212
|
+
},
|
|
213
|
+
"interpolation-block": {
|
|
214
|
+
"comment": "A braced block inside an interpolation, so the interpolation is not closed by the inner brace of `\"${ {40 + 2} }\"`. Mirrors the blockNestingLevel counter in Lexer.acceptStringInterpolation.",
|
|
215
|
+
"begin": "\\{",
|
|
216
|
+
"end": "\\}|$",
|
|
217
|
+
"patterns": [
|
|
218
|
+
{
|
|
219
|
+
"include": "#interpolation-block"
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
"include": "$self"
|
|
223
|
+
}
|
|
224
|
+
]
|
|
225
|
+
},
|
|
226
|
+
"regex-literal": {
|
|
227
|
+
"comment": "`regex\"...\"` is TokenKind.LiteralRegex. No interpolation: Lexer.acceptRegex only consumes escapes and looks for the closing quote.",
|
|
228
|
+
"name": "string.regexp.flix",
|
|
229
|
+
"begin": "(?<![A-Za-z0-9_!$])(regex)(\")",
|
|
230
|
+
"beginCaptures": {
|
|
231
|
+
"1": {
|
|
232
|
+
"name": "keyword.other.regexp.flix"
|
|
233
|
+
},
|
|
234
|
+
"2": {
|
|
235
|
+
"name": "punctuation.definition.string.begin.flix"
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
"end": "\"|$",
|
|
239
|
+
"endCaptures": {
|
|
240
|
+
"0": {
|
|
241
|
+
"name": "punctuation.definition.string.end.flix"
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
"patterns": [
|
|
245
|
+
{
|
|
246
|
+
"include": "#string-escape"
|
|
247
|
+
}
|
|
248
|
+
]
|
|
249
|
+
},
|
|
250
|
+
"char": {
|
|
251
|
+
"comment": "Line-anchored by choice, not by the lexer: Lexer.acceptChar has no newline check, so a char literal may technically span lines. Honouring that would let one stray apostrophe paint the rest of the file — the incumbent grammar's defect #10 — for a construct that does not occur in practice.",
|
|
252
|
+
"name": "string.quoted.single.flix",
|
|
253
|
+
"begin": "'",
|
|
254
|
+
"beginCaptures": {
|
|
255
|
+
"0": {
|
|
256
|
+
"name": "punctuation.definition.string.begin.flix"
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
"end": "'|$",
|
|
260
|
+
"endCaptures": {
|
|
261
|
+
"0": {
|
|
262
|
+
"name": "punctuation.definition.string.end.flix"
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
"patterns": [
|
|
266
|
+
{
|
|
267
|
+
"include": "#string-escape"
|
|
268
|
+
}
|
|
269
|
+
]
|
|
270
|
+
},
|
|
271
|
+
"builtin": {
|
|
272
|
+
"comment": "`%%ARRAY_LOAD%%` is TokenKind.BuiltIn. Lexer.isBuiltInChar is an uppercase letter, a digit, or an underscore.",
|
|
273
|
+
"match": "(%%)([A-Z0-9_]+)(%%)",
|
|
274
|
+
"name": "support.function.builtin.flix",
|
|
275
|
+
"captures": {
|
|
276
|
+
"1": {
|
|
277
|
+
"name": "punctuation.definition.builtin.begin.flix"
|
|
278
|
+
},
|
|
279
|
+
"3": {
|
|
280
|
+
"name": "punctuation.definition.builtin.end.flix"
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
},
|
|
284
|
+
"number-hex": {
|
|
285
|
+
"comment": "Must precede #number: both match at offset 0 of `0x1F`. See defect #1.",
|
|
286
|
+
"match": "(?<![0-9A-Za-z_$!.])0x[0-9a-fA-F]+(?:_[0-9a-fA-F]+)*(?:i8|i16|i32|i64|ii)?(?![0-9A-Za-z_.])",
|
|
287
|
+
"name": "constant.numeric.hex.flix"
|
|
288
|
+
},
|
|
289
|
+
"number": {
|
|
290
|
+
"comment": "The grammar documented on Lexer.acceptNumber: \\D([.]\\D)?(e([+]|[-])?\\D([.]\\D)?)?(i8|i16|i32|i64|ii|f32|f64|ff)?",
|
|
291
|
+
"match": "(?<![0-9A-Za-z_$!.])[0-9]+(?:_[0-9]+)*(?:\\.[0-9]+(?:_[0-9]+)*)?(?:e[+-]?[0-9]+(?:_[0-9]+)*(?:\\.[0-9]+(?:_[0-9]+)*)?)?(?:i8|i16|i32|i64|ii|f32|f64|ff)?(?![0-9A-Za-z_.])",
|
|
292
|
+
"name": "constant.numeric.flix"
|
|
293
|
+
},
|
|
294
|
+
"holes": {
|
|
295
|
+
"patterns": [
|
|
296
|
+
{
|
|
297
|
+
"comment": "`???` is TokenKind.HoleAnonymous, one of Lexer.SimpleTokens.",
|
|
298
|
+
"match": "\\?\\?\\?",
|
|
299
|
+
"name": "constant.language.hole.flix"
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
"comment": "`?name` is TokenKind.HoleNamed; see Lexer.acceptNamedHole.",
|
|
303
|
+
"match": "\\?[A-Za-z][A-Za-z0-9_!$]*",
|
|
304
|
+
"name": "constant.language.hole.flix"
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
"comment": "`name?` is TokenKind.HoleVariable; Lexer.acceptName returns it when a name is followed by `?`. The leading guard matters as much as it does for #wildcard: without it `9x?` scopes only the `x?`, painting half of what the lexer treats as one erroneous token. A leading `_` is included because Lexer.scanToken routes `_` followed by a name character into acceptName.",
|
|
308
|
+
"match": "(?<![A-Za-z0-9_!$])[A-Za-z_][A-Za-z0-9_!$]*\\?",
|
|
309
|
+
"name": "constant.language.hole.flix"
|
|
310
|
+
}
|
|
311
|
+
]
|
|
312
|
+
},
|
|
313
|
+
"annotations": {
|
|
314
|
+
"match": "(@)([A-Za-z]+)",
|
|
315
|
+
"name": "storage.type.annotation.flix",
|
|
316
|
+
"captures": {
|
|
317
|
+
"1": {
|
|
318
|
+
"name": "punctuation.definition.annotation.flix"
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
},
|
|
322
|
+
"declarations": {
|
|
323
|
+
"patterns": [
|
|
324
|
+
{
|
|
325
|
+
"include": "#declaration-type-alias"
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
"include": "#declaration-module"
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
"include": "#declaration-function"
|
|
332
|
+
},
|
|
333
|
+
{
|
|
334
|
+
"include": "#declaration-type"
|
|
335
|
+
}
|
|
336
|
+
]
|
|
337
|
+
},
|
|
338
|
+
"declaration-function": {
|
|
339
|
+
"comment": "A definition may be named by a user-defined operator, e.g. `def >>`.",
|
|
340
|
+
"match": "(?<![A-Za-z0-9_!$])(def|redef)(?![A-Za-z0-9_!$])\\s+((?:\\$[A-Za-z][A-Za-z0-9_!$]*|_?[\\x{2200}-\\x{22FF}]+|_?[+\\-*<>=!&|^$]+|[a-z_][A-Za-z0-9_!$]*|[A-Z][A-Za-z0-9_!$]*))",
|
|
341
|
+
"captures": {
|
|
342
|
+
"1": {
|
|
343
|
+
"name": "storage.type.flix"
|
|
344
|
+
},
|
|
345
|
+
"2": {
|
|
346
|
+
"name": "entity.name.function.flix"
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
},
|
|
350
|
+
"declaration-type": {
|
|
351
|
+
"match": "(?<![A-Za-z0-9_!$])(enum|struct|trait|eff|instance|restrictable)(?![A-Za-z0-9_!$])\\s+([A-Z][A-Za-z0-9_!$]*)",
|
|
352
|
+
"captures": {
|
|
353
|
+
"1": {
|
|
354
|
+
"name": "storage.type.flix"
|
|
355
|
+
},
|
|
356
|
+
"2": {
|
|
357
|
+
"name": "entity.name.type.flix"
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
},
|
|
361
|
+
"declaration-type-alias": {
|
|
362
|
+
"comment": "Listed before #declaration-type so `type alias Foo` is not read as `type`.",
|
|
363
|
+
"match": "(?<![A-Za-z0-9_!$])(type)\\s+(alias)(?![A-Za-z0-9_!$])\\s+([A-Z][A-Za-z0-9_!$]*)",
|
|
364
|
+
"captures": {
|
|
365
|
+
"1": {
|
|
366
|
+
"name": "storage.type.flix"
|
|
367
|
+
},
|
|
368
|
+
"2": {
|
|
369
|
+
"name": "storage.type.flix"
|
|
370
|
+
},
|
|
371
|
+
"3": {
|
|
372
|
+
"name": "entity.name.type.flix"
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
"declaration-module": {
|
|
377
|
+
"match": "(?<![A-Za-z0-9_!$])(mod)(?![A-Za-z0-9_!$])\\s+([A-Z][A-Za-z0-9_!$]*(?:\\.[A-Z][A-Za-z0-9_!$]*)*)",
|
|
378
|
+
"captures": {
|
|
379
|
+
"1": {
|
|
380
|
+
"name": "storage.type.flix"
|
|
381
|
+
},
|
|
382
|
+
"2": {
|
|
383
|
+
"name": "entity.name.namespace.flix"
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
},
|
|
387
|
+
"keywords": {
|
|
388
|
+
"patterns": [
|
|
389
|
+
{
|
|
390
|
+
"match": "(?<![A-Za-z0-9_!$])(?:false|true)(?![A-Za-z0-9_!$])",
|
|
391
|
+
"name": "constant.language.boolean.flix"
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
"match": "(?<![A-Za-z0-9_!$])(?:null)(?![A-Za-z0-9_!$])",
|
|
395
|
+
"name": "constant.language.null.flix"
|
|
396
|
+
},
|
|
397
|
+
{
|
|
398
|
+
"match": "(?<![A-Za-z0-9_!$])(?:else|if)(?![A-Za-z0-9_!$])",
|
|
399
|
+
"name": "keyword.control.conditional.flix"
|
|
400
|
+
},
|
|
401
|
+
{
|
|
402
|
+
"match": "(?<![A-Za-z0-9_!$])(?:project|inject|pquery|psolve|query|solve|fix)(?![A-Za-z0-9_!$])",
|
|
403
|
+
"name": "keyword.control.datalog.flix"
|
|
404
|
+
},
|
|
405
|
+
{
|
|
406
|
+
"match": "(?<![A-Za-z0-9_!$])(?:choose\\*|foreach|handler|choose|ematch|region|select|catch|match|spawn|throw|yield|case|forA|forM|par|run|try)(?![A-Za-z0-9_!$])",
|
|
407
|
+
"name": "keyword.control.flix"
|
|
408
|
+
},
|
|
409
|
+
{
|
|
410
|
+
"match": "(?<![A-Za-z0-9_!$])(?:import|use)(?![A-Za-z0-9_!$])",
|
|
411
|
+
"name": "keyword.control.import.flix"
|
|
412
|
+
},
|
|
413
|
+
{
|
|
414
|
+
"match": "(?<![A-Za-z0-9_!$])(?:unchecked_cast|checked_ecast|checked_cast|unsafe)(?![A-Za-z0-9_!$])",
|
|
415
|
+
"name": "keyword.operator.cast.flix"
|
|
416
|
+
},
|
|
417
|
+
{
|
|
418
|
+
"match": "(?<![A-Za-z0-9_!$])(?:and|not|xor|or)(?![A-Za-z0-9_!$])",
|
|
419
|
+
"name": "keyword.operator.logical.flix"
|
|
420
|
+
},
|
|
421
|
+
{
|
|
422
|
+
"match": "(?<![A-Za-z0-9_!$])(?:Vector#|Array#|List#|Map#|Set#|new)(?![A-Za-z0-9_!$])",
|
|
423
|
+
"name": "keyword.operator.new.flix"
|
|
424
|
+
},
|
|
425
|
+
{
|
|
426
|
+
"match": "(?<![A-Za-z0-9_!$])(?:open_variant_as|open_variant|instanceof|rvadd|rvand|rvnot|rvsub|as)(?![A-Za-z0-9_!$])",
|
|
427
|
+
"name": "keyword.operator.word.flix"
|
|
428
|
+
},
|
|
429
|
+
{
|
|
430
|
+
"match": "(?<![A-Za-z0-9_!$])(?:discard|forall|static|force|super|where|from|into|lazy|with|xvar)(?![A-Za-z0-9_!$])",
|
|
431
|
+
"name": "keyword.other.flix"
|
|
432
|
+
},
|
|
433
|
+
{
|
|
434
|
+
"match": "(?<![A-Za-z0-9_!$])(?:sealed|mut|pub)(?![A-Za-z0-9_!$])",
|
|
435
|
+
"name": "storage.modifier.flix"
|
|
436
|
+
},
|
|
437
|
+
{
|
|
438
|
+
"match": "(?<![A-Za-z0-9_!$])(?:restrictable|instance|struct|alias|redef|trait|enum|type|def|eff|let|mod|val)(?![A-Za-z0-9_!$])",
|
|
439
|
+
"name": "storage.type.flix"
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
"match": "(?<![A-Za-z0-9_!$])(?:Static|Univ)(?![A-Za-z0-9_!$])",
|
|
443
|
+
"name": "support.type.builtin.flix"
|
|
444
|
+
}
|
|
445
|
+
]
|
|
446
|
+
},
|
|
447
|
+
"names": {
|
|
448
|
+
"patterns": [
|
|
449
|
+
{
|
|
450
|
+
"include": "#primitive-type"
|
|
451
|
+
},
|
|
452
|
+
{
|
|
453
|
+
"include": "#math-name"
|
|
454
|
+
},
|
|
455
|
+
{
|
|
456
|
+
"include": "#escaped-name"
|
|
457
|
+
},
|
|
458
|
+
{
|
|
459
|
+
"include": "#wildcard"
|
|
460
|
+
}
|
|
461
|
+
]
|
|
462
|
+
},
|
|
463
|
+
"primitive-type": {
|
|
464
|
+
"comment": "The `// Basic Types` table in Resolver.visitType: resolved structurally, before any name lookup, so unlike `Some` or `Nil` these cannot be shadowed by a user declaration. Scoping library constructors as language constants is defect #11e.",
|
|
465
|
+
"match": "(?<![A-Za-z0-9_!$])(?:BigDecimal|Receiver|Float32|Float64|BigInt|Region|Sender|String|Vector|Array|Int16|Int32|Int64|Regex|Bool|Char|Int8|Lazy|Null|Unit|Void)(?![A-Za-z0-9_!$])",
|
|
466
|
+
"name": "support.type.primitive.flix"
|
|
467
|
+
},
|
|
468
|
+
"math-name": {
|
|
469
|
+
"comment": "A leading `_` belongs to the token: Lexer.scanToken routes `_` followed by a math character into acceptMathName. The lookbehind keeps the `_` of `x_` out of it.",
|
|
470
|
+
"match": "(?<![A-Za-z0-9_!$])_?[\\x{2200}-\\x{22FF}]+",
|
|
471
|
+
"name": "variable.other.math.flix"
|
|
472
|
+
},
|
|
473
|
+
"escaped-name": {
|
|
474
|
+
"comment": "`$name` escapes a name that would otherwise be a keyword (Lexer.acceptEscapedName). The leading guard is essential: `$` is also a name character, and Lexer.acceptName names Java inner-class spellings such as `Map$Entry` as the reason. Without it, `Map$Entry` is split at the `$` into two differently scoped tokens.",
|
|
475
|
+
"match": "(?<![A-Za-z0-9_!$])(\\$)([a-z_][A-Za-z0-9_!$]*|[A-Z][A-Za-z0-9_!$]*)",
|
|
476
|
+
"name": "variable.other.escaped.flix",
|
|
477
|
+
"captures": {
|
|
478
|
+
"1": {
|
|
479
|
+
"name": "punctuation.definition.variable.flix"
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
},
|
|
483
|
+
"wildcard": {
|
|
484
|
+
"comment": "TokenKind.Underscore. The leading guard matters as much as the trailing one: `_` is a name character, so the underscore in `case_` continues that name rather than starting a wildcard.",
|
|
485
|
+
"match": "(?<![A-Za-z0-9_!$])_(?![A-Za-z0-9_!$+\\-*<>=&|^\\x{2200}-\\x{22FF}])",
|
|
486
|
+
"name": "variable.language.wildcard.flix"
|
|
487
|
+
},
|
|
488
|
+
"operators": {
|
|
489
|
+
"patterns": [
|
|
490
|
+
{
|
|
491
|
+
"include": "#datalog"
|
|
492
|
+
},
|
|
493
|
+
{
|
|
494
|
+
"include": "#extensible-type"
|
|
495
|
+
},
|
|
496
|
+
{
|
|
497
|
+
"include": "#record-lookup"
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
"include": "#struct-access"
|
|
501
|
+
},
|
|
502
|
+
{
|
|
503
|
+
"include": "#arrow-function"
|
|
504
|
+
},
|
|
505
|
+
{
|
|
506
|
+
"include": "#arrow-struct"
|
|
507
|
+
},
|
|
508
|
+
{
|
|
509
|
+
"include": "#effect-separator"
|
|
510
|
+
},
|
|
511
|
+
{
|
|
512
|
+
"include": "#operator"
|
|
513
|
+
},
|
|
514
|
+
{
|
|
515
|
+
"include": "#operator-slash"
|
|
516
|
+
},
|
|
517
|
+
{
|
|
518
|
+
"include": "#operator-misc"
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
"include": "#punctuation"
|
|
522
|
+
}
|
|
523
|
+
]
|
|
524
|
+
},
|
|
525
|
+
"datalog": {
|
|
526
|
+
"patterns": [
|
|
527
|
+
{
|
|
528
|
+
"match": "#\\{|#\\(",
|
|
529
|
+
"name": "punctuation.section.datalog.begin.flix"
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
"comment": "Rule implication, TokenKind.ColonMinus.",
|
|
533
|
+
"match": ":-(?![+\\-*<>=!&|^$])",
|
|
534
|
+
"name": "keyword.operator.datalog.flix"
|
|
535
|
+
},
|
|
536
|
+
{
|
|
537
|
+
"comment": "Fixpoint merge, TokenKind.AngledPlus.",
|
|
538
|
+
"match": "<\\+>(?![+\\-*<>=!&|^$])",
|
|
539
|
+
"name": "keyword.operator.datalog.flix"
|
|
540
|
+
}
|
|
541
|
+
]
|
|
542
|
+
},
|
|
543
|
+
"extensible-type": {
|
|
544
|
+
"comment": "`#| ... |#`, Parser2.extensibleType. Not Datalog despite the leading `#`.",
|
|
545
|
+
"patterns": [
|
|
546
|
+
{
|
|
547
|
+
"match": "#\\|",
|
|
548
|
+
"name": "punctuation.section.extensible.begin.flix"
|
|
549
|
+
},
|
|
550
|
+
{
|
|
551
|
+
"match": "\\|#",
|
|
552
|
+
"name": "punctuation.section.extensible.end.flix"
|
|
553
|
+
}
|
|
554
|
+
]
|
|
555
|
+
},
|
|
556
|
+
"record-lookup": {
|
|
557
|
+
"comment": "A bare `#` followed by a lowercase name is a record select (Parser2, `case TokenKind.Hash if nth(1) == TokenKind.NameLowercase`), not a Datalog form.",
|
|
558
|
+
"match": "(#)([a-z_][A-Za-z0-9_!$]*)",
|
|
559
|
+
"captures": {
|
|
560
|
+
"1": {
|
|
561
|
+
"name": "punctuation.accessor.flix"
|
|
562
|
+
},
|
|
563
|
+
"2": {
|
|
564
|
+
"name": "variable.other.member.flix"
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
},
|
|
568
|
+
"struct-access": {
|
|
569
|
+
"comment": "Tight `->` followed by a lowercase name is a struct get or put, per Parser2 `case TokenKind.ArrowThinRTight if nth(1) == TokenKind.NameLowercase`.",
|
|
570
|
+
"match": "(?<=[A-Za-z0-9_!$])(->)([a-z_][A-Za-z0-9_!$]*)",
|
|
571
|
+
"captures": {
|
|
572
|
+
"1": {
|
|
573
|
+
"name": "keyword.operator.accessor.flix"
|
|
574
|
+
},
|
|
575
|
+
"2": {
|
|
576
|
+
"name": "variable.other.member.flix"
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
},
|
|
580
|
+
"effect-separator": {
|
|
581
|
+
"comment": "`\\` separates a type from its effect set, per Type.typeAndEffect — `def f(): t \\ ef`. It is not a lambda: Flix lambdas are written `x -> e`.",
|
|
582
|
+
"match": "\\\\",
|
|
583
|
+
"name": "keyword.operator.effect.flix"
|
|
584
|
+
},
|
|
585
|
+
"arrow-function": {
|
|
586
|
+
"comment": "Whitespace on either side makes this the function arrow, per Lexer.scanToken.",
|
|
587
|
+
"match": "(?:(?<=\\s)->|->(?=\\s))(?![+\\-*<>=!&|^$])",
|
|
588
|
+
"name": "keyword.operator.arrow.flix"
|
|
589
|
+
},
|
|
590
|
+
"arrow-struct": {
|
|
591
|
+
"comment": "No surrounding whitespace: struct field access, TokenKind.ArrowThinRTight. #struct-access above needs no such guard: it already requires a lowercase name after the arrow, which is never an operator character.",
|
|
592
|
+
"match": "->(?![+\\-*<>=!&|^$])",
|
|
593
|
+
"name": "keyword.operator.accessor.flix"
|
|
594
|
+
},
|
|
595
|
+
"operator": {
|
|
596
|
+
"comment": "Flix admits user-defined operators, so this is a character class rather than an enumeration of Lexer.Operators. The named entries are a subset of what this matches.",
|
|
597
|
+
"match": "(?:(?<![A-Za-z0-9_!$])_?[+\\-*<>=!&|^$]|[+\\-*<>=&|^])[+\\-*<>=!&|^$]*",
|
|
598
|
+
"name": "keyword.operator.flix"
|
|
599
|
+
},
|
|
600
|
+
"operator-misc": {
|
|
601
|
+
"comment": "Operator tokens outside Lexer.isUserOp. `~` is TokenKind.Tilde. A bare `@` is TokenKind.At, the region operator in `new Struct @ rc {...}` (Parser2.regionName) -- not annotation punctuation, which is why the lookahead defers to #annotations.",
|
|
602
|
+
"match": "~|@(?![A-Za-z])",
|
|
603
|
+
"name": "keyword.operator.flix"
|
|
604
|
+
},
|
|
605
|
+
"operator-slash": {
|
|
606
|
+
"comment": "`/` is TokenKind.Slash, a real operator. Lexer.isUserOp excludes it only so that `//` can begin a comment, so it is absent from #operator and needs its own rule. The lookahead is belt-and-braces: #comments is matched before #operators, so a comment already wins the tie at the same offset.",
|
|
607
|
+
"match": "/(?![/*])",
|
|
608
|
+
"name": "keyword.operator.flix"
|
|
609
|
+
},
|
|
610
|
+
"punctuation": {
|
|
611
|
+
"patterns": [
|
|
612
|
+
{
|
|
613
|
+
"match": "[{}]",
|
|
614
|
+
"name": "punctuation.section.braces.flix"
|
|
615
|
+
},
|
|
616
|
+
{
|
|
617
|
+
"match": "[()]",
|
|
618
|
+
"name": "punctuation.section.parens.flix"
|
|
619
|
+
},
|
|
620
|
+
{
|
|
621
|
+
"match": "\\[|\\]",
|
|
622
|
+
"name": "punctuation.section.brackets.flix"
|
|
623
|
+
},
|
|
624
|
+
{
|
|
625
|
+
"comment": "Defect #11c: the incumbent scopes `;` as keyword.control.",
|
|
626
|
+
"match": ";",
|
|
627
|
+
"name": "punctuation.terminator.flix"
|
|
628
|
+
},
|
|
629
|
+
{
|
|
630
|
+
"match": ",",
|
|
631
|
+
"name": "punctuation.separator.comma.flix"
|
|
632
|
+
},
|
|
633
|
+
{
|
|
634
|
+
"match": ":::|::|:",
|
|
635
|
+
"name": "punctuation.separator.colon.flix"
|
|
636
|
+
},
|
|
637
|
+
{
|
|
638
|
+
"match": "\\.",
|
|
639
|
+
"name": "punctuation.accessor.flix"
|
|
640
|
+
},
|
|
641
|
+
{
|
|
642
|
+
"match": "`",
|
|
643
|
+
"name": "punctuation.definition.infix.flix"
|
|
644
|
+
}
|
|
645
|
+
]
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
}
|