@fraczak/k 6.1.2 → 6.2.0

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.
Files changed (76) hide show
  1. package/AGENTS.md +4 -4
  2. package/CLAUDE.md +1 -1
  3. package/DOCS/BIG_PICTURE.md +10 -10
  4. package/DOCS/DIVERGENCE_DETECTION.md +1 -1
  5. package/DOCS/OBJECT_FILE_AND_PATTERN.md +6 -0
  6. package/DOCS/REPL.md +22 -17
  7. package/DOCS/TYPE_DERIVATION.md +12 -12
  8. package/DOCS/book/01-introduction.md +2 -2
  9. package/DOCS/book/02-syntax-and-values.md +8 -8
  10. package/DOCS/book/03-types-as-finite-automata.md +2 -2
  11. package/DOCS/book/04-partial-functions-and-composition.md +2 -2
  12. package/DOCS/book/05-typing-filters-and-normalization.md +3 -3
  13. package/DOCS/book/06-values-in-memory.md +3 -3
  14. package/DOCS/book/07-the-partial-function-abi.md +1 -1
  15. package/DOCS/book/08-operational-semantics-and-execution.md +1 -1
  16. package/DOCS/book/09-compiler-architecture.md +2 -2
  17. package/DOCS/book/appendix-b-incorporating-external-predefined-types-and-functions.md +1 -0
  18. package/README.md +13 -13
  19. package/codecs/BINARY_FORMAT.md +1 -1
  20. package/codecs/POLYMORPHIC_BINARY_FORMAT.md +1 -1
  21. package/codes.mjs +14 -33
  22. package/export.mjs +13 -3
  23. package/k-vscode/README.md +10 -1
  24. package/k-vscode/extension.js +273 -0
  25. package/k-vscode/package.json +22 -0
  26. package/k-vscode/syntaxes/k.tmLanguage.json +493 -137
  27. package/k-vscode/test/background-ranges.test.js +50 -0
  28. package/k-vscode/themes/k-contrast-color-theme.json +104 -0
  29. package/object.mjs +20 -7
  30. package/package.json +3 -2
  31. package/repl.mjs +43 -2
  32. package/scripts/benchmark-idempotency.mjs +72 -0
  33. package/scripts/run-tests.mjs +54 -0
  34. package/{Code-derivation-tests → tests/code-derivation}/codec-witness-pattern.mjs +3 -3
  35. package/{Code-derivation-tests → tests/code-derivation}/convergence-strategy.mjs +1 -1
  36. package/{Code-derivation-tests → tests/code-derivation}/dot.mjs +1 -1
  37. package/{Code-derivation-tests → tests/code-derivation}/filter-syntax.mjs +1 -1
  38. package/{Code-derivation-tests → tests/code-derivation}/index.mjs +1 -1
  39. package/{Code-derivation-tests → tests/code-derivation}/pattern-envelope.mjs +5 -5
  40. package/{Code-derivation-tests → tests/code-derivation}/product.mjs +1 -1
  41. package/{tests.sh → tests/integration.sh} +3 -1
  42. package/{test-fingerprint.mjs → tests/test-fingerprint.mjs} +3 -3
  43. package/{test-hash-fuzz.mjs → tests/test-hash-fuzz.mjs} +1 -1
  44. package/{test-hash-normalization.mjs → tests/test-hash-normalization.mjs} +2 -2
  45. package/{test-ieee-arithmetic.mjs → tests/test-ieee-arithmetic.mjs} +14 -27
  46. package/{test-k-object.mjs → tests/test-k-object.mjs} +26 -7
  47. package/{test-repl.mjs → tests/test-repl.mjs} +22 -4
  48. package/{test.mjs → tests/test.mjs} +1 -1
  49. package/.codex +0 -0
  50. package/DOCS/a.html +0 -398
  51. package/DOCS/dependency-graph.html +0 -140
  52. package/DOCS/dependency-graph.md +0 -144
  53. package/NAT.k~ +0 -452
  54. package/UU/ta.k +0 -1
  55. package/UU/ta.k~ +0 -0
  56. package/UU/tb.k +0 -0
  57. package/UU/tc.k +0 -0
  58. package/codecs/BINARY_FORMAT.html +0 -471
  59. package/codecs/POLYMORPHIC_BINARY_FORMAT.html +0 -355
  60. package/core.json +0 -1
  61. package/core.klib +0 -1
  62. package/core.klib~ +0 -0
  63. package/ieee.klib +0 -1
  64. package/k-vscode/package-lock.json +0 -4176
  65. package/kkk.k +0 -197
  66. package/kkk.klib +0 -0
  67. package/kkk.klib~ +0 -0
  68. package/p.json +0 -5475
  69. package/type_registry/registry.mjs~ +0 -105
  70. package/type_registry/typeParser.jison~ +0 -132
  71. /package/{Code-derivation-tests → tests/code-derivation}/blowup.mjs +0 -0
  72. /package/{Code-derivation-tests → tests/code-derivation}/bnat.mjs +0 -0
  73. /package/{Code-derivation-tests → tests/code-derivation}/loop.mjs +0 -0
  74. /package/{Code-derivation-tests → tests/code-derivation}/nat.mjs +0 -0
  75. /package/{Code-derivation-tests → tests/code-derivation}/not-not.mjs +0 -0
  76. /package/{Code-derivation-tests → tests/code-derivation}/rlz.mjs +0 -0
@@ -6,236 +6,592 @@
6
6
  { "include": "#comment-block" },
7
7
  { "include": "#comment-line" },
8
8
  { "include": "#type-definition" },
9
- { "include": "#function-definition" },
10
- { "include": "#filter" },
11
- { "include": "#type-ref" },
12
- { "include": "#canonical-ref" },
13
- { "include": "#projection-dot" },
14
- { "include": "#projection-slash" },
15
- { "include": "#variant-intro" },
16
- { "include": "#string-double" },
17
- { "include": "#string-single" },
18
- { "include": "#dots" },
19
- { "include": "#operators" },
20
- { "include": "#brackets" }
9
+ { "include": "#relation-definition" },
10
+ { "include": "#main-relation-expression" }
21
11
  ],
22
12
  "repository": {
23
-
24
13
  "comment-block": {
25
14
  "name": "comment.block.k",
26
15
  "begin": "/\\*",
27
16
  "end": "\\*/",
28
- "beginCaptures": { "0": { "name": "punctuation.definition.comment.k" } },
29
- "endCaptures": { "0": { "name": "punctuation.definition.comment.k" } }
17
+ "beginCaptures": {
18
+ "0": { "name": "punctuation.definition.comment.begin.k" }
19
+ },
20
+ "endCaptures": {
21
+ "0": { "name": "punctuation.definition.comment.end.k" }
22
+ }
30
23
  },
31
-
32
24
  "comment-line": {
33
25
  "name": "comment.line.k",
34
- "match": "(?://|--|%|#).*$"
26
+ "match": "(?://|--|%|#|\\\\\\\\).*$"
35
27
  },
36
-
37
28
  "type-definition": {
38
- "comment": "$ name = ... ; — defines a named code (type)",
39
- "match": "(\\$)\\s*([a-zA-Z0-9_+\\-][a-zA-Z0-9_?!+\\-]*)(?=\\s*=)",
40
- "captures": {
29
+ "comment": "$ name = code; defines a named code (type)",
30
+ "name": "meta.definition.type.k",
31
+ "contentName": "meta.expression.type.k",
32
+ "begin": "(\\$)\\s*([a-zA-Z0-9_+\\-][a-zA-Z0-9_?!+\\-]*)\\s*(=)",
33
+ "end": "(;)",
34
+ "beginCaptures": {
41
35
  "1": { "name": "keyword.operator.type.k" },
42
- "2": { "name": "entity.name.type.k" }
43
- }
36
+ "2": { "name": "entity.name.type.k" },
37
+ "3": { "name": "keyword.operator.assignment.k" }
38
+ },
39
+ "endCaptures": {
40
+ "1": { "name": "punctuation.terminator.definition.k" }
41
+ },
42
+ "patterns": [
43
+ { "include": "#type-content" }
44
+ ]
45
+ },
46
+ "relation-definition": {
47
+ "comment": "name = expression; defines a named relation/function",
48
+ "name": "meta.definition.function.k",
49
+ "contentName": "meta.expression.relation.k",
50
+ "begin": "^\\s*([a-zA-Z0-9_+\\-][a-zA-Z0-9_?!+\\-]*)\\s*(=)",
51
+ "end": "(;)",
52
+ "beginCaptures": {
53
+ "1": { "name": "support.function.identifier.k" },
54
+ "2": { "name": "keyword.operator.assignment.k" }
55
+ },
56
+ "endCaptures": {
57
+ "1": { "name": "punctuation.terminator.definition.k" }
58
+ },
59
+ "patterns": [
60
+ { "include": "#relation-content" }
61
+ ]
62
+ },
63
+ "main-relation-expression": {
64
+ "comment": "The parser requires one trailing top-level relation expression after definitions",
65
+ "name": "meta.expression.relation.k",
66
+ "begin": "(?=\\S)",
67
+ "end": "(?=$)",
68
+ "patterns": [
69
+ { "include": "#relation-content" }
70
+ ]
71
+ },
72
+ "type-content": {
73
+ "patterns": [
74
+ { "include": "#comment-block" },
75
+ { "include": "#comment-line" },
76
+ { "include": "#type-product" },
77
+ { "include": "#type-union" },
78
+ { "include": "#canonical-type-ref" },
79
+ { "include": "#type-name" },
80
+ { "include": "#separator" }
81
+ ]
82
+ },
83
+ "type-product": {
84
+ "name": "meta.expression.type.product.k",
85
+ "begin": "(\\{)",
86
+ "end": "(\\})",
87
+ "beginCaptures": {
88
+ "1": { "name": "punctuation.section.product.begin.k" }
89
+ },
90
+ "endCaptures": {
91
+ "1": { "name": "punctuation.section.product.end.k" }
92
+ },
93
+ "patterns": [
94
+ { "include": "#comment-block" },
95
+ { "include": "#comment-line" },
96
+ { "include": "#type-product-label" },
97
+ { "include": "#type-product" },
98
+ { "include": "#type-union" },
99
+ { "include": "#canonical-type-ref" },
100
+ { "include": "#type-name" },
101
+ { "include": "#separator" }
102
+ ]
103
+ },
104
+ "type-union": {
105
+ "name": "meta.expression.type.union.k",
106
+ "begin": "(<)",
107
+ "end": "(>)",
108
+ "beginCaptures": {
109
+ "1": { "name": "punctuation.section.union.begin.k" }
110
+ },
111
+ "endCaptures": {
112
+ "1": { "name": "punctuation.section.union.end.k" }
113
+ },
114
+ "patterns": [
115
+ { "include": "#comment-block" },
116
+ { "include": "#comment-line" },
117
+ { "include": "#type-union-tag" },
118
+ { "include": "#type-product" },
119
+ { "include": "#type-union" },
120
+ { "include": "#canonical-type-ref" },
121
+ { "include": "#type-name" },
122
+ { "include": "#separator" }
123
+ ]
124
+ },
125
+ "type-product-label": {
126
+ "patterns": [
127
+ {
128
+ "name": "entity.name.label.k",
129
+ "match": "[a-zA-Z0-9_+\\-][a-zA-Z0-9_?!+\\-]*(?=\\s*[,}])"
130
+ },
131
+ {
132
+ "name": "entity.name.label.k",
133
+ "match": "(?:\"(?:[^\"\\\\]|\\\\.)*\"|'(?:[^'\\\\]|\\\\.)*')(?=\\s*[,}])"
134
+ }
135
+ ]
136
+ },
137
+ "type-union-tag": {
138
+ "patterns": [
139
+ {
140
+ "name": "entity.name.tag.k",
141
+ "match": "[a-zA-Z0-9_+\\-][a-zA-Z0-9_?!+\\-]*(?=\\s*[,>])"
142
+ },
143
+ {
144
+ "name": "entity.name.tag.k",
145
+ "match": "(?:\"(?:[^\"\\\\]|\\\\.)*\"|'(?:[^'\\\\]|\\\\.)*')(?=\\s*[,>])"
146
+ }
147
+ ]
148
+ },
149
+ "type-expression": {
150
+ "patterns": [
151
+ {
152
+ "name": "meta.expression.type.k",
153
+ "match": "(\\$)\\s*(@)([a-zA-Z0-9_+\\-][a-zA-Z0-9_?!+\\-]*)",
154
+ "captures": {
155
+ "1": { "name": "keyword.operator.type.k" },
156
+ "2": { "name": "punctuation.definition.canonical.k" },
157
+ "3": { "name": "support.type.canonical.k" }
158
+ }
159
+ },
160
+ {
161
+ "name": "meta.expression.type.k",
162
+ "match": "(\\$)\\s*([a-zA-Z0-9_+\\-][a-zA-Z0-9_?!+\\-]*)",
163
+ "captures": {
164
+ "1": { "name": "keyword.operator.type.k" },
165
+ "2": { "name": "support.type.k" }
166
+ }
167
+ },
168
+ {
169
+ "name": "meta.expression.type.k",
170
+ "begin": "(\\$)\\s*(\\{)",
171
+ "end": "(\\})",
172
+ "beginCaptures": {
173
+ "1": { "name": "keyword.operator.type.k" },
174
+ "2": { "name": "punctuation.section.product.begin.k" }
175
+ },
176
+ "endCaptures": {
177
+ "1": { "name": "punctuation.section.product.end.k" }
178
+ },
179
+ "patterns": [
180
+ { "include": "#type-product-label" },
181
+ { "include": "#type-content" }
182
+ ]
183
+ },
184
+ {
185
+ "name": "meta.expression.type.k",
186
+ "begin": "(\\$)\\s*(<)",
187
+ "end": "(>)",
188
+ "beginCaptures": {
189
+ "1": { "name": "keyword.operator.type.k" },
190
+ "2": { "name": "punctuation.section.union.begin.k" }
191
+ },
192
+ "endCaptures": {
193
+ "1": { "name": "punctuation.section.union.end.k" }
194
+ },
195
+ "patterns": [
196
+ { "include": "#type-union-tag" },
197
+ { "include": "#type-content" }
198
+ ]
199
+ }
200
+ ]
44
201
  },
45
-
46
- "function-definition": {
47
- "comment": "name = ... ; — top-level function/relation definition",
48
- "match": "^\\s*([a-zA-Z_][a-zA-Z0-9_?!+\\-]*)\\s*(?==)",
202
+ "type-name": {
203
+ "name": "support.type.k",
204
+ "match": "[a-zA-Z0-9_+\\-][a-zA-Z0-9_?!+\\-]*"
205
+ },
206
+ "canonical-type-ref": {
207
+ "match": "(@)([a-zA-Z0-9_+\\-][a-zA-Z0-9_?!+\\-]*)",
49
208
  "captures": {
50
- "1": { "name": "entity.name.function.k" }
209
+ "1": { "name": "punctuation.definition.canonical.k" },
210
+ "2": { "name": "support.type.canonical.k" }
51
211
  }
52
212
  },
53
-
54
- "filter": {
55
- "comment": "? introduces a filter/pattern constraint: ?<...>=X, ?{...}=X",
213
+ "relation-content": {
214
+ "patterns": [
215
+ { "include": "#comment-block" },
216
+ { "include": "#comment-line" },
217
+ { "include": "#filter-expression" },
218
+ { "include": "#type-expression" },
219
+ { "include": "#projection-dot" },
220
+ { "include": "#projection-slash" },
221
+ { "include": "#variant-intro" },
222
+ { "include": "#canonical-function-ref" },
223
+ { "include": "#relation-product" },
224
+ { "include": "#relation-union" },
225
+ { "include": "#relation-parens" },
226
+ { "include": "#string-double" },
227
+ { "include": "#string-single" },
228
+ { "include": "#dots" },
229
+ { "include": "#relation-identifier" },
230
+ { "include": "#separator" },
231
+ { "include": "#brackets" }
232
+ ]
233
+ },
234
+ "relation-product": {
235
+ "begin": "(\\{)",
236
+ "end": "(\\})",
237
+ "beginCaptures": {
238
+ "1": { "name": "punctuation.section.product.begin.k" }
239
+ },
240
+ "endCaptures": {
241
+ "1": { "name": "punctuation.section.product.end.k" }
242
+ },
243
+ "patterns": [
244
+ { "include": "#relation-product-label" },
245
+ { "include": "#relation-content" }
246
+ ]
247
+ },
248
+ "relation-union": {
249
+ "begin": "(<)",
250
+ "end": "(>)",
251
+ "beginCaptures": {
252
+ "1": { "name": "punctuation.section.union.begin.k" }
253
+ },
254
+ "endCaptures": {
255
+ "1": { "name": "punctuation.section.union.end.k" }
256
+ },
257
+ "patterns": [
258
+ { "include": "#relation-content" }
259
+ ]
260
+ },
261
+ "relation-parens": {
262
+ "begin": "(\\()",
263
+ "end": "(\\))",
264
+ "beginCaptures": {
265
+ "1": { "name": "punctuation.section.parens.begin.k" }
266
+ },
267
+ "endCaptures": {
268
+ "1": { "name": "punctuation.section.parens.end.k" }
269
+ },
270
+ "patterns": [
271
+ { "include": "#relation-content" }
272
+ ]
273
+ },
274
+ "relation-product-label": {
275
+ "patterns": [
276
+ {
277
+ "name": "entity.name.label.k",
278
+ "match": "[a-zA-Z0-9_+\\-][a-zA-Z0-9_?!+\\-]*(?=\\s*[,}])"
279
+ },
280
+ {
281
+ "name": "entity.name.label.k",
282
+ "match": "(?:\"(?:[^\"\\\\]|\\\\.)*\"|'(?:[^'\\\\]|\\\\.)*')(?=\\s*[,}])"
283
+ }
284
+ ]
285
+ },
286
+ "filter-expression": {
56
287
  "patterns": [
57
288
  {
58
- "comment": "filter union ?< ... > = X",
289
+ "name": "meta.expression.filter.k",
59
290
  "begin": "(\\?)\\s*(<)",
60
- "end": "(>)(?:\\s*(=)\\s*([a-zA-Z0-9_?!+\\-]+))?",
291
+ "end": "(>)(?:\\s*(=)\\s*([a-zA-Z0-9_+\\-][a-zA-Z0-9_?!+\\-]*))?",
61
292
  "beginCaptures": {
62
293
  "1": { "name": "keyword.operator.filter.k" },
63
- "2": { "name": "punctuation.brackets.k" }
294
+ "2": { "name": "punctuation.section.filter.union.begin.k" }
64
295
  },
65
296
  "endCaptures": {
66
- "1": { "name": "punctuation.brackets.k" },
67
- "2": { "name": "keyword.operator.filter.k" },
297
+ "1": { "name": "punctuation.section.filter.union.end.k" },
298
+ "2": { "name": "keyword.operator.binding.k" },
68
299
  "3": { "name": "variable.other.pattern.k" }
69
300
  },
70
301
  "patterns": [
71
- { "include": "#comment-block" },
72
- { "include": "#comment-line" },
73
- { "include": "#filter" },
74
- { "include": "#pattern-variable" },
75
- { "include": "#type-ref" },
76
- { "include": "#string-double" },
77
- { "include": "#string-single" },
78
- { "include": "#dots" },
79
- { "include": "#operators" },
80
- { "include": "#brackets" }
302
+ { "include": "#filter-union-content" }
81
303
  ]
82
304
  },
83
305
  {
84
- "comment": "filter product ?{ ... } = X",
306
+ "name": "meta.expression.filter.k",
85
307
  "begin": "(\\?)\\s*(\\{)",
86
- "end": "(\\})(?:\\s*(=)\\s*([a-zA-Z0-9_?!+\\-]+))?",
308
+ "end": "(\\})(?:\\s*(=)\\s*([a-zA-Z0-9_+\\-][a-zA-Z0-9_?!+\\-]*))?",
309
+ "beginCaptures": {
310
+ "1": { "name": "keyword.operator.filter.k" },
311
+ "2": { "name": "punctuation.section.filter.product.begin.k" }
312
+ },
313
+ "endCaptures": {
314
+ "1": { "name": "punctuation.section.filter.product.end.k" },
315
+ "2": { "name": "keyword.operator.binding.k" },
316
+ "3": { "name": "variable.other.pattern.k" }
317
+ },
318
+ "patterns": [
319
+ { "include": "#filter-product-content" }
320
+ ]
321
+ },
322
+ {
323
+ "name": "meta.expression.filter.k",
324
+ "begin": "(\\?)\\s*(\\()",
325
+ "end": "(\\))(?:\\s*(=)\\s*([a-zA-Z0-9_+\\-][a-zA-Z0-9_?!+\\-]*))?",
87
326
  "beginCaptures": {
88
327
  "1": { "name": "keyword.operator.filter.k" },
89
- "2": { "name": "punctuation.brackets.k" }
328
+ "2": { "name": "punctuation.section.filter.any.begin.k" }
90
329
  },
91
330
  "endCaptures": {
92
- "1": { "name": "punctuation.brackets.k" },
93
- "2": { "name": "keyword.operator.filter.k" },
331
+ "1": { "name": "punctuation.section.filter.any.end.k" },
332
+ "2": { "name": "keyword.operator.binding.k" },
94
333
  "3": { "name": "variable.other.pattern.k" }
95
334
  },
96
335
  "patterns": [
97
- { "include": "#comment-block" },
98
- { "include": "#comment-line" },
99
- { "include": "#filter" },
100
- { "include": "#pattern-variable" },
101
- { "include": "#type-ref" },
102
- { "include": "#string-double" },
103
- { "include": "#string-single" },
104
- { "include": "#dots" },
105
- { "include": "#operators" },
106
- { "include": "#brackets" }
336
+ { "include": "#filter-any-content" }
107
337
  ]
338
+ },
339
+ {
340
+ "name": "meta.expression.filter.k",
341
+ "match": "(\\?)\\s*(\\$)\\s*(@)([a-zA-Z0-9_+\\-][a-zA-Z0-9_?!+\\-]*)",
342
+ "captures": {
343
+ "1": { "name": "keyword.operator.filter.k" },
344
+ "2": { "name": "keyword.operator.type.k" },
345
+ "3": { "name": "punctuation.definition.canonical.k" },
346
+ "4": { "name": "support.type.canonical.k" }
347
+ }
348
+ },
349
+ {
350
+ "name": "meta.expression.filter.k",
351
+ "match": "(\\?)\\s*(\\$)\\s*([a-zA-Z0-9_+\\-][a-zA-Z0-9_?!+\\-]*)",
352
+ "captures": {
353
+ "1": { "name": "keyword.operator.filter.k" },
354
+ "2": { "name": "keyword.operator.type.k" },
355
+ "3": { "name": "support.type.k" }
356
+ }
357
+ },
358
+ {
359
+ "name": "meta.expression.filter.k",
360
+ "match": "(\\?)\\s*([a-zA-Z0-9_+\\-][a-zA-Z0-9_?!+\\-]*)",
361
+ "captures": {
362
+ "1": { "name": "keyword.operator.filter.k" },
363
+ "2": { "name": "variable.other.pattern.k" }
364
+ }
108
365
  }
109
366
  ]
110
367
  },
111
-
112
- "pattern-variable": {
113
- "comment": "Uppercase identifiers used as pattern variables inside filter expressions",
114
- "name": "variable.other.pattern.k",
115
- "match": "\\b[A-Z][a-zA-Z0-9_]*\\b"
368
+ "filter-union": {
369
+ "name": "meta.expression.filter.k",
370
+ "begin": "(<)",
371
+ "end": "(>)(?:\\s*(=)\\s*([a-zA-Z0-9_+\\-][a-zA-Z0-9_?!+\\-]*))?",
372
+ "beginCaptures": {
373
+ "1": { "name": "punctuation.section.filter.union.begin.k" }
374
+ },
375
+ "endCaptures": {
376
+ "1": { "name": "punctuation.section.filter.union.end.k" },
377
+ "2": { "name": "keyword.operator.binding.k" },
378
+ "3": { "name": "variable.other.pattern.k" }
379
+ },
380
+ "patterns": [
381
+ { "include": "#filter-union-content" }
382
+ ]
116
383
  },
117
-
118
- "type-ref": {
119
- "comment": "$name — use of a named code as a type annotation or type expression",
120
- "match": "(\\$)([a-zA-Z0-9_+\\-][a-zA-Z0-9_?!+\\-]*)?",
121
- "captures": {
122
- "1": { "name": "keyword.operator.type.k" },
123
- "2": { "name": "storage.type.k" }
124
- }
384
+ "filter-product": {
385
+ "name": "meta.expression.filter.k",
386
+ "begin": "(\\{)",
387
+ "end": "(\\})(?:\\s*(=)\\s*([a-zA-Z0-9_+\\-][a-zA-Z0-9_?!+\\-]*))?",
388
+ "beginCaptures": {
389
+ "1": { "name": "punctuation.section.filter.product.begin.k" }
390
+ },
391
+ "endCaptures": {
392
+ "1": { "name": "punctuation.section.filter.product.end.k" },
393
+ "2": { "name": "keyword.operator.binding.k" },
394
+ "3": { "name": "variable.other.pattern.k" }
395
+ },
396
+ "patterns": [
397
+ { "include": "#filter-product-content" }
398
+ ]
125
399
  },
126
-
127
- "canonical-ref": {
128
- "comment": "@base58hash — content-addressed canonical code reference",
129
- "name": "variable.other.constant.k",
130
- "match": "@[a-zA-Z0-9]+"
400
+ "filter-any": {
401
+ "name": "meta.expression.filter.k",
402
+ "begin": "(\\()",
403
+ "end": "(\\))(?:\\s*(=)\\s*([a-zA-Z0-9_+\\-][a-zA-Z0-9_?!+\\-]*))?",
404
+ "beginCaptures": {
405
+ "1": { "name": "punctuation.section.filter.any.begin.k" }
406
+ },
407
+ "endCaptures": {
408
+ "1": { "name": "punctuation.section.filter.any.end.k" },
409
+ "2": { "name": "keyword.operator.binding.k" },
410
+ "3": { "name": "variable.other.pattern.k" }
411
+ },
412
+ "patterns": [
413
+ { "include": "#filter-any-content" }
414
+ ]
131
415
  },
132
-
133
- "projection-dot": {
134
- "comment": ".label or .\"label\" — product field projection",
416
+ "filter-union-content": {
417
+ "patterns": [
418
+ { "include": "#comment-block" },
419
+ { "include": "#comment-line" },
420
+ { "include": "#filter-tag" },
421
+ { "include": "#filter-product" },
422
+ { "include": "#filter-union" },
423
+ { "include": "#filter-any" },
424
+ { "include": "#filter-type-ref" },
425
+ { "include": "#dots" },
426
+ { "include": "#pattern-variable" },
427
+ { "include": "#separator" }
428
+ ]
429
+ },
430
+ "filter-product-content": {
431
+ "patterns": [
432
+ { "include": "#comment-block" },
433
+ { "include": "#comment-line" },
434
+ { "include": "#filter-label" },
435
+ { "include": "#filter-product" },
436
+ { "include": "#filter-union" },
437
+ { "include": "#filter-any" },
438
+ { "include": "#filter-type-ref" },
439
+ { "include": "#dots" },
440
+ { "include": "#pattern-variable" },
441
+ { "include": "#separator" }
442
+ ]
443
+ },
444
+ "filter-any-content": {
445
+ "patterns": [
446
+ { "include": "#comment-block" },
447
+ { "include": "#comment-line" },
448
+ { "include": "#dots" },
449
+ { "include": "#separator" }
450
+ ]
451
+ },
452
+ "filter-label": {
135
453
  "patterns": [
136
454
  {
137
- "name": "keyword.operator.projection.k",
138
- "match": "\\.(?:[a-zA-Z0-9_+\\-][a-zA-Z0-9_?!+\\-]*)"
455
+ "name": "entity.name.label.k",
456
+ "match": "[a-zA-Z0-9_+\\-][a-zA-Z0-9_?!+\\-]*(?=\\s*[,}])"
139
457
  },
140
458
  {
141
- "begin": "\\.(\")",
142
- "end": "\"",
143
- "beginCaptures": { "0": { "name": "keyword.operator.projection.k" } },
144
- "endCaptures": { "0": { "name": "keyword.operator.projection.k" } },
145
- "contentName": "string.quoted.double.k"
459
+ "name": "entity.name.label.k",
460
+ "match": "(?:\"(?:[^\"\\\\]|\\\\.)*\"|'(?:[^'\\\\]|\\\\.)*')(?=\\s*[,}])"
461
+ }
462
+ ]
463
+ },
464
+ "filter-tag": {
465
+ "patterns": [
466
+ {
467
+ "name": "entity.name.tag.k",
468
+ "match": "[a-zA-Z0-9_+\\-][a-zA-Z0-9_?!+\\-]*(?=\\s*[,>])"
146
469
  },
147
470
  {
148
- "begin": "\\.(\')",
149
- "end": "\'",
150
- "beginCaptures": { "0": { "name": "keyword.operator.projection.k" } },
151
- "endCaptures": { "0": { "name": "keyword.operator.projection.k" } },
152
- "contentName": "string.quoted.single.k"
471
+ "name": "entity.name.tag.k",
472
+ "match": "(?:\"(?:[^\"\\\\]|\\\\.)*\"|'(?:[^'\\\\]|\\\\.)*')(?=\\s*[,>])"
153
473
  }
154
474
  ]
155
475
  },
156
-
157
- "projection-slash": {
158
- "comment": "/tag or /\"tag\" — union tag projection (assert and unwrap)",
476
+ "filter-type-ref": {
159
477
  "patterns": [
160
478
  {
161
- "name": "keyword.operator.projection.k",
162
- "match": "/(?:[a-zA-Z0-9_+\\-][a-zA-Z0-9_?!+\\-]*)"
479
+ "match": "(\\$)\\s*(@)([a-zA-Z0-9_+\\-][a-zA-Z0-9_?!+\\-]*)",
480
+ "captures": {
481
+ "1": { "name": "keyword.operator.type.k" },
482
+ "2": { "name": "punctuation.definition.canonical.k" },
483
+ "3": { "name": "support.type.canonical.k" }
484
+ }
163
485
  },
164
486
  {
165
- "begin": "/(\")",
166
- "end": "\"",
167
- "beginCaptures": { "0": { "name": "keyword.operator.projection.k" } },
168
- "endCaptures": { "0": { "name": "keyword.operator.projection.k" } },
169
- "contentName": "string.quoted.double.k"
487
+ "match": "(\\$)\\s*([a-zA-Z0-9_+\\-][a-zA-Z0-9_?!+\\-]*)",
488
+ "captures": {
489
+ "1": { "name": "keyword.operator.type.k" },
490
+ "2": { "name": "support.type.k" }
491
+ }
492
+ }
493
+ ]
494
+ },
495
+ "pattern-variable": {
496
+ "name": "variable.other.pattern.k",
497
+ "match": "[a-zA-Z0-9_+\\-][a-zA-Z0-9_?!+\\-]*"
498
+ },
499
+ "projection-dot": {
500
+ "comment": ".label projects a product field",
501
+ "patterns": [
502
+ {
503
+ "match": "(\\.)([a-zA-Z0-9_+\\-][a-zA-Z0-9_?!+\\-]*)",
504
+ "captures": {
505
+ "1": { "name": "keyword.operator.projection.product.k" },
506
+ "2": { "name": "entity.name.label.k" }
507
+ }
170
508
  },
171
509
  {
172
- "begin": "/(\')",
173
- "end": "\'",
174
- "beginCaptures": { "0": { "name": "keyword.operator.projection.k" } },
175
- "endCaptures": { "0": { "name": "keyword.operator.projection.k" } },
176
- "contentName": "string.quoted.single.k"
510
+ "match": "(\\.)(\"(?:[^\"\\\\]|\\\\.)*\"|'(?:[^'\\\\]|\\\\.)*')",
511
+ "captures": {
512
+ "1": { "name": "keyword.operator.projection.product.k" },
513
+ "2": { "name": "entity.name.label.k" }
514
+ }
177
515
  }
178
516
  ]
179
517
  },
180
-
181
- "variant-intro": {
182
- "comment": "|tag or |\"tag\" — variant (tagged union) introduction",
518
+ "projection-slash": {
519
+ "comment": "/tag asserts and unwraps a union variant",
183
520
  "patterns": [
184
521
  {
185
- "name": "keyword.operator.intro.k",
186
- "match": "\\|[a-zA-Z0-9_+\\-][a-zA-Z0-9_?!+\\-]*"
522
+ "match": "(/)([a-zA-Z0-9_+\\-][a-zA-Z0-9_?!+\\-]*)",
523
+ "captures": {
524
+ "1": { "name": "keyword.operator.projection.union.k" },
525
+ "2": { "name": "entity.name.tag.k" }
526
+ }
187
527
  },
188
528
  {
189
- "begin": "\\|(\")",
190
- "end": "\"",
191
- "beginCaptures": { "0": { "name": "keyword.operator.intro.k" } },
192
- "endCaptures": { "0": { "name": "keyword.operator.intro.k" } },
193
- "contentName": "string.quoted.double.k"
529
+ "match": "(/)(\"(?:[^\"\\\\]|\\\\.)*\"|'(?:[^'\\\\]|\\\\.)*')",
530
+ "captures": {
531
+ "1": { "name": "keyword.operator.projection.union.k" },
532
+ "2": { "name": "entity.name.tag.k" }
533
+ }
534
+ }
535
+ ]
536
+ },
537
+ "variant-intro": {
538
+ "comment": "|tag or \\tag introduces a union variant",
539
+ "patterns": [
540
+ {
541
+ "match": "([|\\\\])([a-zA-Z0-9_+\\-][a-zA-Z0-9_?!+\\-]*)",
542
+ "captures": {
543
+ "1": { "name": "keyword.operator.variant.k" },
544
+ "2": { "name": "entity.name.tag.k" }
545
+ }
194
546
  },
195
547
  {
196
- "begin": "\\|(\')",
197
- "end": "\'",
198
- "beginCaptures": { "0": { "name": "keyword.operator.intro.k" } },
199
- "endCaptures": { "0": { "name": "keyword.operator.intro.k" } },
200
- "contentName": "string.quoted.single.k"
548
+ "match": "([|\\\\])(\"(?:[^\"\\\\]|\\\\.)*\"|'(?:[^'\\\\]|\\\\.)*')",
549
+ "captures": {
550
+ "1": { "name": "keyword.operator.variant.k" },
551
+ "2": { "name": "entity.name.tag.k" }
552
+ }
201
553
  }
202
554
  ]
203
555
  },
204
-
556
+ "canonical-function-ref": {
557
+ "match": "(@)([a-zA-Z0-9_+\\-][a-zA-Z0-9_?!+\\-]*)",
558
+ "captures": {
559
+ "1": { "name": "punctuation.definition.canonical.k" },
560
+ "2": { "name": "support.function.canonical.k" }
561
+ }
562
+ },
563
+ "relation-identifier": {
564
+ "name": "support.function.identifier.k",
565
+ "match": "[a-zA-Z0-9_+\\-][a-zA-Z0-9_?!+\\-]*"
566
+ },
205
567
  "string-double": {
206
568
  "name": "string.quoted.double.k",
207
569
  "begin": "\"",
208
570
  "end": "\"",
209
571
  "patterns": [
210
572
  { "name": "constant.character.escape.k", "match": "\\\\(?:[\"\\\\/bfnrt]|u[0-9a-fA-F]{4})" },
211
- { "name": "invalid.illegal.escape.k", "match": "\\\\." }
573
+ { "name": "invalid.illegal.escape.k", "match": "\\\\." }
212
574
  ]
213
575
  },
214
-
215
576
  "string-single": {
216
577
  "name": "string.quoted.single.k",
217
578
  "begin": "'",
218
579
  "end": "'",
219
580
  "patterns": [
220
581
  { "name": "constant.character.escape.k", "match": "\\\\(?:['\\\\/bfnrt]|u[0-9a-fA-F]{4})" },
221
- { "name": "invalid.illegal.escape.k", "match": "\\\\." }
582
+ { "name": "invalid.illegal.escape.k", "match": "\\\\." }
222
583
  ]
223
584
  },
224
-
225
585
  "dots": {
226
- "comment": "... — the any/open pattern (unconstrained position)",
227
- "name": "constant.language.k",
586
+ "comment": "... is the any/open pattern marker",
587
+ "name": "constant.language.any.k",
228
588
  "match": "\\.\\.\\."
229
589
  },
230
-
231
- "operators": {
232
- "comment": "= ; , : ~ — structural separators and definition operators",
590
+ "separator": {
233
591
  "name": "punctuation.separator.k",
234
- "match": "[=;,:]|~"
592
+ "match": "[=;,:~]"
235
593
  },
236
-
237
594
  "brackets": {
238
- "comment": "{ } ( ) < > — grouping and combinator delimiters",
239
595
  "name": "punctuation.brackets.k",
240
596
  "match": "[{}()<>]"
241
597
  }