@bearcove/monaco-lang-styx 0.1.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.
- package/dist/index.cjs +507 -0
- package/dist/index.d.cts +103 -0
- package/dist/index.d.ts +103 -0
- package/dist/index.js +476 -0
- package/package.json +51 -0
- package/src/index.ts +106 -0
- package/src/theme.ts +115 -0
- package/src/tokenizer.ts +496 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
StyxTokensProvider: () => StyxTokensProvider,
|
|
24
|
+
catppuccinMocha: () => catppuccinMocha,
|
|
25
|
+
mocha: () => mocha,
|
|
26
|
+
registerStyxLanguage: () => registerStyxLanguage,
|
|
27
|
+
styxLanguageConfig: () => styxLanguageConfig
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(index_exports);
|
|
30
|
+
|
|
31
|
+
// src/tokenizer.ts
|
|
32
|
+
function createInitialState() {
|
|
33
|
+
return {
|
|
34
|
+
contextStack: ["object"],
|
|
35
|
+
// document is implicit root object
|
|
36
|
+
entryPhase: "key",
|
|
37
|
+
heredoc: null,
|
|
38
|
+
rawStringHashes: null,
|
|
39
|
+
inString: false,
|
|
40
|
+
stringIsKey: false,
|
|
41
|
+
clone() {
|
|
42
|
+
return {
|
|
43
|
+
contextStack: [...this.contextStack],
|
|
44
|
+
entryPhase: this.entryPhase,
|
|
45
|
+
heredoc: this.heredoc ? { ...this.heredoc } : null,
|
|
46
|
+
rawStringHashes: this.rawStringHashes,
|
|
47
|
+
inString: this.inString,
|
|
48
|
+
stringIsKey: this.stringIsKey,
|
|
49
|
+
clone: this.clone,
|
|
50
|
+
equals: this.equals
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
equals(other) {
|
|
54
|
+
const o = other;
|
|
55
|
+
return this.contextStack.length === o.contextStack.length && this.contextStack.every((v, i) => v === o.contextStack[i]) && this.entryPhase === o.entryPhase && JSON.stringify(this.heredoc) === JSON.stringify(o.heredoc) && this.rawStringHashes === o.rawStringHashes && this.inString === o.inString && this.stringIsKey === o.stringIsKey;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function currentContext(state) {
|
|
60
|
+
return state.contextStack[state.contextStack.length - 1] || "object";
|
|
61
|
+
}
|
|
62
|
+
function isInObjectContext(state) {
|
|
63
|
+
return currentContext(state) === "object";
|
|
64
|
+
}
|
|
65
|
+
var TOKEN = {
|
|
66
|
+
WHITE: "white",
|
|
67
|
+
COMMENT: "comment",
|
|
68
|
+
COMMENT_DOC: "comment.doc",
|
|
69
|
+
KEY: "key",
|
|
70
|
+
STRING_KEY: "string.key",
|
|
71
|
+
TAG_KEY: "tag.key",
|
|
72
|
+
VALUE: "value",
|
|
73
|
+
TAG: "tag",
|
|
74
|
+
STRING: "string",
|
|
75
|
+
STRING_HEREDOC: "string.heredoc",
|
|
76
|
+
STRING_ESCAPE: "string.escape",
|
|
77
|
+
DELIMITER_CURLY: "delimiter.curly",
|
|
78
|
+
DELIMITER_PAREN: "delimiter.parenthesis",
|
|
79
|
+
DELIMITER_COMMA: "delimiter.comma",
|
|
80
|
+
INVALID: "invalid"
|
|
81
|
+
};
|
|
82
|
+
var WHITESPACE = /^[ \t]+/;
|
|
83
|
+
var DOC_COMMENT = /^\/\/\/.*/;
|
|
84
|
+
var LINE_COMMENT = /^\/\/.*/;
|
|
85
|
+
var TAG_IDENT = /^@[A-Za-z_][A-Za-z0-9_-]*/;
|
|
86
|
+
var UNIT = /^@(?![A-Za-z_])/;
|
|
87
|
+
var HEREDOC_START = /^<<([A-Z][A-Z0-9_]*)(?:,([a-z][a-z0-9_.-]*))?/;
|
|
88
|
+
var RAW_STRING_START = /^r(#+)"/;
|
|
89
|
+
var BARE_FIRST_CHAR = /^[^\s{}()\,\"=@>\r\n]/;
|
|
90
|
+
var BARE_CONT_CHAR = /^[^\s{}()\,\">\r\n]/;
|
|
91
|
+
var StyxTokensProvider = class {
|
|
92
|
+
/**
|
|
93
|
+
* @param monacoEditor Optional monaco.editor reference for embedded language tokenization.
|
|
94
|
+
* If not provided, heredocs will be styled as plain heredoc strings.
|
|
95
|
+
*/
|
|
96
|
+
constructor(monacoEditor) {
|
|
97
|
+
this.monacoEditor = monacoEditor;
|
|
98
|
+
}
|
|
99
|
+
getInitialState() {
|
|
100
|
+
return createInitialState();
|
|
101
|
+
}
|
|
102
|
+
tokenize(line, inputState) {
|
|
103
|
+
const state = inputState.clone();
|
|
104
|
+
const tokens = [];
|
|
105
|
+
let pos = 0;
|
|
106
|
+
const addToken = (start, type) => {
|
|
107
|
+
tokens.push({ startIndex: start, scopes: type });
|
|
108
|
+
};
|
|
109
|
+
const atomType = (isTag) => {
|
|
110
|
+
if (!isInObjectContext(state)) {
|
|
111
|
+
return isTag ? TOKEN.TAG : TOKEN.VALUE;
|
|
112
|
+
}
|
|
113
|
+
if (state.entryPhase === "key") {
|
|
114
|
+
return isTag ? TOKEN.TAG_KEY : TOKEN.KEY;
|
|
115
|
+
}
|
|
116
|
+
return isTag ? TOKEN.TAG : TOKEN.VALUE;
|
|
117
|
+
};
|
|
118
|
+
const stringType = () => {
|
|
119
|
+
if (!isInObjectContext(state)) {
|
|
120
|
+
return TOKEN.STRING;
|
|
121
|
+
}
|
|
122
|
+
return state.entryPhase === "key" ? TOKEN.STRING_KEY : TOKEN.STRING;
|
|
123
|
+
};
|
|
124
|
+
const afterAtom = () => {
|
|
125
|
+
if (isInObjectContext(state)) {
|
|
126
|
+
if (state.entryPhase === "key") {
|
|
127
|
+
state.entryPhase = "value";
|
|
128
|
+
} else {
|
|
129
|
+
state.entryPhase = "key";
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
if (state.heredoc) {
|
|
134
|
+
const delim = state.heredoc.delimiter;
|
|
135
|
+
const closeMatch = line.match(new RegExp(`^(\\s*)(${delim})\\s*$`));
|
|
136
|
+
if (closeMatch) {
|
|
137
|
+
addToken(0, TOKEN.STRING_HEREDOC);
|
|
138
|
+
state.heredoc = null;
|
|
139
|
+
afterAtom();
|
|
140
|
+
return { tokens, endState: state };
|
|
141
|
+
}
|
|
142
|
+
const lang = state.heredoc.language;
|
|
143
|
+
if (lang && this.monacoEditor) {
|
|
144
|
+
try {
|
|
145
|
+
const embeddedTokens = this.monacoEditor.tokenize(line, lang);
|
|
146
|
+
if (embeddedTokens.length > 0 && embeddedTokens[0].length > 0) {
|
|
147
|
+
for (const token of embeddedTokens[0]) {
|
|
148
|
+
tokens.push({
|
|
149
|
+
startIndex: token.offset,
|
|
150
|
+
scopes: token.type
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
return { tokens, endState: state };
|
|
154
|
+
}
|
|
155
|
+
} catch {
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
addToken(0, TOKEN.STRING_HEREDOC);
|
|
159
|
+
return { tokens, endState: state };
|
|
160
|
+
}
|
|
161
|
+
if (state.inString) {
|
|
162
|
+
const tokenType = state.stringIsKey ? TOKEN.STRING_KEY : TOKEN.STRING;
|
|
163
|
+
while (pos < line.length) {
|
|
164
|
+
const ch = line[pos];
|
|
165
|
+
if (ch === "\\" && pos + 1 < line.length) {
|
|
166
|
+
if (tokens.length === 0 || tokens[tokens.length - 1].startIndex !== pos) {
|
|
167
|
+
addToken(pos, TOKEN.STRING_ESCAPE);
|
|
168
|
+
}
|
|
169
|
+
pos += 2;
|
|
170
|
+
if (pos < line.length) {
|
|
171
|
+
addToken(pos, tokenType);
|
|
172
|
+
}
|
|
173
|
+
} else if (ch === '"') {
|
|
174
|
+
addToken(pos, tokenType);
|
|
175
|
+
pos++;
|
|
176
|
+
state.inString = false;
|
|
177
|
+
afterAtom();
|
|
178
|
+
break;
|
|
179
|
+
} else {
|
|
180
|
+
if (tokens.length === 0) {
|
|
181
|
+
addToken(pos, tokenType);
|
|
182
|
+
}
|
|
183
|
+
pos++;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (pos >= line.length && state.inString) {
|
|
187
|
+
if (tokens.length === 0) {
|
|
188
|
+
addToken(0, tokenType);
|
|
189
|
+
}
|
|
190
|
+
return { tokens, endState: state };
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (state.rawStringHashes !== null) {
|
|
194
|
+
const hashes = state.rawStringHashes;
|
|
195
|
+
const tokenType = state.stringIsKey ? TOKEN.STRING_KEY : TOKEN.STRING;
|
|
196
|
+
const closePattern = '"' + "#".repeat(hashes);
|
|
197
|
+
while (pos < line.length) {
|
|
198
|
+
const idx = line.indexOf(closePattern, pos);
|
|
199
|
+
if (idx >= 0) {
|
|
200
|
+
addToken(pos, tokenType);
|
|
201
|
+
pos = idx + closePattern.length;
|
|
202
|
+
state.rawStringHashes = null;
|
|
203
|
+
afterAtom();
|
|
204
|
+
break;
|
|
205
|
+
} else {
|
|
206
|
+
addToken(pos, tokenType);
|
|
207
|
+
return { tokens, endState: state };
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
while (pos < line.length) {
|
|
212
|
+
const rest = line.slice(pos);
|
|
213
|
+
let match;
|
|
214
|
+
if (match = rest.match(WHITESPACE)) {
|
|
215
|
+
addToken(pos, TOKEN.WHITE);
|
|
216
|
+
pos += match[0].length;
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
if (match = rest.match(DOC_COMMENT)) {
|
|
220
|
+
addToken(pos, TOKEN.COMMENT_DOC);
|
|
221
|
+
pos += match[0].length;
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
if (match = rest.match(LINE_COMMENT)) {
|
|
225
|
+
addToken(pos, TOKEN.COMMENT);
|
|
226
|
+
pos += match[0].length;
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
if (rest[0] === "{") {
|
|
230
|
+
addToken(pos, TOKEN.DELIMITER_CURLY);
|
|
231
|
+
pos++;
|
|
232
|
+
state.contextStack.push("object");
|
|
233
|
+
state.entryPhase = "key";
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
if (rest[0] === "}") {
|
|
237
|
+
addToken(pos, TOKEN.DELIMITER_CURLY);
|
|
238
|
+
pos++;
|
|
239
|
+
state.contextStack.pop();
|
|
240
|
+
if (isInObjectContext(state) && state.entryPhase === "value") {
|
|
241
|
+
state.entryPhase = "key";
|
|
242
|
+
}
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
if (rest[0] === "(") {
|
|
246
|
+
addToken(pos, TOKEN.DELIMITER_PAREN);
|
|
247
|
+
pos++;
|
|
248
|
+
state.contextStack.push("sequence");
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
if (rest[0] === ")") {
|
|
252
|
+
addToken(pos, TOKEN.DELIMITER_PAREN);
|
|
253
|
+
pos++;
|
|
254
|
+
state.contextStack.pop();
|
|
255
|
+
if (isInObjectContext(state) && state.entryPhase === "value") {
|
|
256
|
+
state.entryPhase = "key";
|
|
257
|
+
}
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
if (rest[0] === ",") {
|
|
261
|
+
addToken(pos, TOKEN.DELIMITER_COMMA);
|
|
262
|
+
pos++;
|
|
263
|
+
if (isInObjectContext(state)) {
|
|
264
|
+
state.entryPhase = "key";
|
|
265
|
+
}
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
if (match = rest.match(HEREDOC_START)) {
|
|
269
|
+
addToken(pos, TOKEN.STRING_HEREDOC);
|
|
270
|
+
pos += match[0].length;
|
|
271
|
+
state.heredoc = {
|
|
272
|
+
delimiter: match[1],
|
|
273
|
+
language: match[2] || null,
|
|
274
|
+
indentation: null
|
|
275
|
+
};
|
|
276
|
+
return { tokens, endState: state };
|
|
277
|
+
}
|
|
278
|
+
if (match = rest.match(RAW_STRING_START)) {
|
|
279
|
+
const hashes = match[1].length;
|
|
280
|
+
const isKey = isInObjectContext(state) && state.entryPhase === "key";
|
|
281
|
+
addToken(pos, isKey ? TOKEN.STRING_KEY : TOKEN.STRING);
|
|
282
|
+
pos += match[0].length;
|
|
283
|
+
const closePattern = '"' + "#".repeat(hashes);
|
|
284
|
+
const closeIdx = line.indexOf(closePattern, pos);
|
|
285
|
+
if (closeIdx >= 0) {
|
|
286
|
+
pos = closeIdx + closePattern.length;
|
|
287
|
+
afterAtom();
|
|
288
|
+
} else {
|
|
289
|
+
state.rawStringHashes = hashes;
|
|
290
|
+
state.stringIsKey = isKey;
|
|
291
|
+
return { tokens, endState: state };
|
|
292
|
+
}
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
if (rest[0] === '"') {
|
|
296
|
+
const isKey = isInObjectContext(state) && state.entryPhase === "key";
|
|
297
|
+
const tokenType = isKey ? TOKEN.STRING_KEY : TOKEN.STRING;
|
|
298
|
+
addToken(pos, tokenType);
|
|
299
|
+
pos++;
|
|
300
|
+
while (pos < line.length) {
|
|
301
|
+
const ch = line[pos];
|
|
302
|
+
if (ch === "\\" && pos + 1 < line.length) {
|
|
303
|
+
addToken(pos, TOKEN.STRING_ESCAPE);
|
|
304
|
+
pos += 2;
|
|
305
|
+
if (pos < line.length && line[pos] !== '"') {
|
|
306
|
+
addToken(pos, tokenType);
|
|
307
|
+
}
|
|
308
|
+
} else if (ch === '"') {
|
|
309
|
+
addToken(pos, tokenType);
|
|
310
|
+
pos++;
|
|
311
|
+
afterAtom();
|
|
312
|
+
break;
|
|
313
|
+
} else {
|
|
314
|
+
pos++;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
if (pos >= line.length && line[line.length - 1] !== '"') {
|
|
318
|
+
state.inString = true;
|
|
319
|
+
state.stringIsKey = isKey;
|
|
320
|
+
}
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
if (match = rest.match(UNIT)) {
|
|
324
|
+
addToken(pos, atomType(true));
|
|
325
|
+
pos += match[0].length;
|
|
326
|
+
afterAtom();
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
if (match = rest.match(TAG_IDENT)) {
|
|
330
|
+
addToken(pos, atomType(true));
|
|
331
|
+
pos += match[0].length;
|
|
332
|
+
const afterTag = line.slice(pos);
|
|
333
|
+
if (afterTag[0] === "{" || afterTag[0] === "(") {
|
|
334
|
+
continue;
|
|
335
|
+
} else if (afterTag[0] === '"' || afterTag.match(/^r#+"/)) {
|
|
336
|
+
continue;
|
|
337
|
+
} else if (afterTag.match(/^<<[A-Z]/)) {
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
afterAtom();
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
if (rest.match(BARE_FIRST_CHAR)) {
|
|
344
|
+
const startPos = pos;
|
|
345
|
+
pos++;
|
|
346
|
+
while (pos < line.length && line.slice(pos).match(BARE_CONT_CHAR)) {
|
|
347
|
+
pos++;
|
|
348
|
+
}
|
|
349
|
+
addToken(startPos, atomType(false));
|
|
350
|
+
afterAtom();
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
addToken(pos, TOKEN.INVALID);
|
|
354
|
+
pos++;
|
|
355
|
+
}
|
|
356
|
+
if (isInObjectContext(state)) {
|
|
357
|
+
state.entryPhase = "key";
|
|
358
|
+
}
|
|
359
|
+
return { tokens, endState: state };
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
// src/theme.ts
|
|
364
|
+
var mocha = {
|
|
365
|
+
rosewater: "f5e0dc",
|
|
366
|
+
flamingo: "f2cdcd",
|
|
367
|
+
pink: "f5c2e7",
|
|
368
|
+
mauve: "cba6f7",
|
|
369
|
+
red: "f38ba8",
|
|
370
|
+
maroon: "eba0ac",
|
|
371
|
+
peach: "fab387",
|
|
372
|
+
yellow: "f9e2af",
|
|
373
|
+
green: "a6e3a1",
|
|
374
|
+
teal: "94e2d5",
|
|
375
|
+
sky: "89dceb",
|
|
376
|
+
sapphire: "74c7ec",
|
|
377
|
+
blue: "89b4fa",
|
|
378
|
+
lavender: "b4befe",
|
|
379
|
+
text: "cdd6f4",
|
|
380
|
+
subtext1: "bac2de",
|
|
381
|
+
subtext0: "a6adc8",
|
|
382
|
+
overlay2: "9399b2",
|
|
383
|
+
overlay1: "7f849c",
|
|
384
|
+
overlay0: "6c7086",
|
|
385
|
+
surface2: "585b70",
|
|
386
|
+
surface1: "45475a",
|
|
387
|
+
surface0: "313244",
|
|
388
|
+
base: "1e1e2e",
|
|
389
|
+
mantle: "181825",
|
|
390
|
+
crust: "11111b"
|
|
391
|
+
};
|
|
392
|
+
var catppuccinMocha = {
|
|
393
|
+
base: "vs-dark",
|
|
394
|
+
inherit: true,
|
|
395
|
+
rules: [
|
|
396
|
+
// Comments
|
|
397
|
+
{ token: "comment", foreground: mocha.overlay1, fontStyle: "italic" },
|
|
398
|
+
{ token: "comment.doc", foreground: mocha.overlay2, fontStyle: "italic" },
|
|
399
|
+
// Keys - pink/flamingo for that warm feel
|
|
400
|
+
{ token: "key", foreground: mocha.flamingo },
|
|
401
|
+
{ token: "string.key", foreground: mocha.flamingo },
|
|
402
|
+
{ token: "tag.key", foreground: mocha.mauve },
|
|
403
|
+
// Values - sapphire/blue
|
|
404
|
+
{ token: "value", foreground: mocha.sapphire },
|
|
405
|
+
// Tags - mauve (purple)
|
|
406
|
+
{ token: "tag", foreground: mocha.mauve },
|
|
407
|
+
// Strings - green
|
|
408
|
+
{ token: "string", foreground: mocha.green },
|
|
409
|
+
{ token: "string.heredoc", foreground: mocha.green },
|
|
410
|
+
{ token: "string.escape", foreground: mocha.peach },
|
|
411
|
+
// Delimiters
|
|
412
|
+
{ token: "delimiter.curly", foreground: mocha.yellow },
|
|
413
|
+
{ token: "delimiter.parenthesis", foreground: mocha.pink },
|
|
414
|
+
{ token: "delimiter.comma", foreground: mocha.overlay2 },
|
|
415
|
+
// Invalid
|
|
416
|
+
{ token: "invalid", foreground: mocha.red },
|
|
417
|
+
// Additional token types for embedded languages
|
|
418
|
+
{ token: "keyword", foreground: mocha.mauve },
|
|
419
|
+
{ token: "keyword.sql", foreground: mocha.mauve },
|
|
420
|
+
{ token: "operator", foreground: mocha.sky },
|
|
421
|
+
{ token: "operator.sql", foreground: mocha.sky },
|
|
422
|
+
{ token: "number", foreground: mocha.peach },
|
|
423
|
+
{ token: "number.json", foreground: mocha.peach },
|
|
424
|
+
{ token: "identifier", foreground: mocha.text },
|
|
425
|
+
{ token: "type", foreground: mocha.yellow },
|
|
426
|
+
{ token: "type.identifier.json", foreground: mocha.blue },
|
|
427
|
+
{ token: "predefined", foreground: mocha.blue },
|
|
428
|
+
{ token: "predefined.sql", foreground: mocha.blue },
|
|
429
|
+
// JSON specific
|
|
430
|
+
{ token: "string.key.json", foreground: mocha.flamingo },
|
|
431
|
+
{ token: "string.value.json", foreground: mocha.green },
|
|
432
|
+
{ token: "keyword.json", foreground: mocha.mauve },
|
|
433
|
+
{ token: "delimiter.bracket.json", foreground: mocha.overlay2 },
|
|
434
|
+
{ token: "delimiter.array.json", foreground: mocha.pink },
|
|
435
|
+
{ token: "delimiter.colon.json", foreground: mocha.overlay2 },
|
|
436
|
+
{ token: "delimiter.comma.json", foreground: mocha.overlay2 }
|
|
437
|
+
],
|
|
438
|
+
colors: {
|
|
439
|
+
"editor.background": "#" + mocha.base,
|
|
440
|
+
"editor.foreground": "#" + mocha.text,
|
|
441
|
+
"editor.lineHighlightBackground": "#" + mocha.surface0,
|
|
442
|
+
"editorCursor.foreground": "#" + mocha.rosewater,
|
|
443
|
+
"editor.selectionBackground": "#" + mocha.surface2 + "80",
|
|
444
|
+
"editorLineNumber.foreground": "#" + mocha.surface2,
|
|
445
|
+
"editorLineNumber.activeForeground": "#" + mocha.lavender,
|
|
446
|
+
"editorIndentGuide.background": "#" + mocha.surface1,
|
|
447
|
+
"editorIndentGuide.activeBackground": "#" + mocha.surface2,
|
|
448
|
+
"editorBracketMatch.background": "#" + mocha.surface2 + "80",
|
|
449
|
+
"editorBracketMatch.border": "#" + mocha.mauve,
|
|
450
|
+
"editor.findMatchBackground": "#" + mocha.peach + "40",
|
|
451
|
+
"editor.findMatchHighlightBackground": "#" + mocha.yellow + "30",
|
|
452
|
+
"editorWidget.background": "#" + mocha.mantle,
|
|
453
|
+
"editorWidget.border": "#" + mocha.surface1,
|
|
454
|
+
"input.background": "#" + mocha.surface0,
|
|
455
|
+
"input.border": "#" + mocha.surface1,
|
|
456
|
+
"input.foreground": "#" + mocha.text,
|
|
457
|
+
"scrollbarSlider.background": "#" + mocha.surface1 + "80",
|
|
458
|
+
"scrollbarSlider.hoverBackground": "#" + mocha.surface2 + "80",
|
|
459
|
+
"scrollbarSlider.activeBackground": "#" + mocha.surface2
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
// src/index.ts
|
|
464
|
+
var styxLanguageConfig = {
|
|
465
|
+
comments: { lineComment: "//" },
|
|
466
|
+
brackets: [
|
|
467
|
+
["{", "}"],
|
|
468
|
+
["(", ")"]
|
|
469
|
+
],
|
|
470
|
+
autoClosingPairs: [
|
|
471
|
+
{ open: "{", close: "}" },
|
|
472
|
+
{ open: "(", close: ")" },
|
|
473
|
+
{ open: '"', close: '"' }
|
|
474
|
+
],
|
|
475
|
+
surroundingPairs: [
|
|
476
|
+
{ open: "{", close: "}" },
|
|
477
|
+
{ open: "(", close: ")" },
|
|
478
|
+
{ open: '"', close: '"' }
|
|
479
|
+
]
|
|
480
|
+
};
|
|
481
|
+
function registerStyxLanguage(monacoInstance, embeddedLanguages, options = {}) {
|
|
482
|
+
const { defineTheme = true, registerEmbeddedLanguages = true } = options;
|
|
483
|
+
if (registerEmbeddedLanguages && embeddedLanguages) {
|
|
484
|
+
for (const { id, def } of embeddedLanguages) {
|
|
485
|
+
const existing = monacoInstance.languages.getLanguages().find((l) => l.id === id);
|
|
486
|
+
if (!existing) {
|
|
487
|
+
monacoInstance.languages.register({ id });
|
|
488
|
+
}
|
|
489
|
+
monacoInstance.languages.setMonarchTokensProvider(id, def.language);
|
|
490
|
+
monacoInstance.languages.setLanguageConfiguration(id, def.conf);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
monacoInstance.languages.register({ id: "styx" });
|
|
494
|
+
monacoInstance.languages.setTokensProvider("styx", new StyxTokensProvider(monacoInstance.editor));
|
|
495
|
+
monacoInstance.languages.setLanguageConfiguration("styx", styxLanguageConfig);
|
|
496
|
+
if (defineTheme) {
|
|
497
|
+
monacoInstance.editor.defineTheme("catppuccin-mocha", catppuccinMocha);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
501
|
+
0 && (module.exports = {
|
|
502
|
+
StyxTokensProvider,
|
|
503
|
+
catppuccinMocha,
|
|
504
|
+
mocha,
|
|
505
|
+
registerStyxLanguage,
|
|
506
|
+
styxLanguageConfig
|
|
507
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import * as monaco from 'monaco-editor';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Monaco tokens provider for Styx language.
|
|
5
|
+
* Handles context-aware tokenization including heredocs and embedded language injection.
|
|
6
|
+
*/
|
|
7
|
+
declare class StyxTokensProvider implements monaco.languages.TokensProvider {
|
|
8
|
+
private monacoEditor;
|
|
9
|
+
/**
|
|
10
|
+
* @param monacoEditor Optional monaco.editor reference for embedded language tokenization.
|
|
11
|
+
* If not provided, heredocs will be styled as plain heredoc strings.
|
|
12
|
+
*/
|
|
13
|
+
constructor(monacoEditor?: typeof monaco.editor);
|
|
14
|
+
getInitialState(): monaco.languages.IState;
|
|
15
|
+
tokenize(line: string, inputState: monaco.languages.IState): monaco.languages.ILineTokens;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
declare const mocha: {
|
|
19
|
+
rosewater: string;
|
|
20
|
+
flamingo: string;
|
|
21
|
+
pink: string;
|
|
22
|
+
mauve: string;
|
|
23
|
+
red: string;
|
|
24
|
+
maroon: string;
|
|
25
|
+
peach: string;
|
|
26
|
+
yellow: string;
|
|
27
|
+
green: string;
|
|
28
|
+
teal: string;
|
|
29
|
+
sky: string;
|
|
30
|
+
sapphire: string;
|
|
31
|
+
blue: string;
|
|
32
|
+
lavender: string;
|
|
33
|
+
text: string;
|
|
34
|
+
subtext1: string;
|
|
35
|
+
subtext0: string;
|
|
36
|
+
overlay2: string;
|
|
37
|
+
overlay1: string;
|
|
38
|
+
overlay0: string;
|
|
39
|
+
surface2: string;
|
|
40
|
+
surface1: string;
|
|
41
|
+
surface0: string;
|
|
42
|
+
base: string;
|
|
43
|
+
mantle: string;
|
|
44
|
+
crust: string;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Catppuccin Mocha theme for Monaco editor.
|
|
48
|
+
* A dark theme with warm, readable colors optimized for Styx syntax highlighting.
|
|
49
|
+
*/
|
|
50
|
+
declare const catppuccinMocha: monaco.editor.IStandaloneThemeData;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Styx language configuration for Monaco editor.
|
|
54
|
+
* Defines brackets, comments, and auto-closing pairs.
|
|
55
|
+
*/
|
|
56
|
+
declare const styxLanguageConfig: monaco.languages.LanguageConfiguration;
|
|
57
|
+
/**
|
|
58
|
+
* Options for registering the Styx language.
|
|
59
|
+
*/
|
|
60
|
+
interface RegisterStyxOptions {
|
|
61
|
+
/**
|
|
62
|
+
* Whether to define the Catppuccin Mocha theme.
|
|
63
|
+
* @default true
|
|
64
|
+
*/
|
|
65
|
+
defineTheme?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Whether to register embedded languages for heredoc injection (SQL, JavaScript, etc.)
|
|
68
|
+
* @default true
|
|
69
|
+
*/
|
|
70
|
+
registerEmbeddedLanguages?: boolean;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Language definitions for embedded language support in heredocs.
|
|
74
|
+
*/
|
|
75
|
+
interface EmbeddedLanguage {
|
|
76
|
+
id: string;
|
|
77
|
+
def: {
|
|
78
|
+
conf: monaco.languages.LanguageConfiguration;
|
|
79
|
+
language: monaco.languages.IMonarchLanguage;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Register the Styx language with Monaco editor.
|
|
84
|
+
*
|
|
85
|
+
* @param monacoInstance - The monaco module
|
|
86
|
+
* @param embeddedLanguages - Optional array of embedded languages for heredoc injection.
|
|
87
|
+
* These are the monaco basic language definitions (sql, javascript, etc.)
|
|
88
|
+
* @param options - Registration options
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* import * as monaco from 'monaco-editor';
|
|
93
|
+
* import * as sqlLang from 'monaco-editor/esm/vs/basic-languages/sql/sql';
|
|
94
|
+
* import { registerStyxLanguage } from '@bearcove/monaco-lang-styx';
|
|
95
|
+
*
|
|
96
|
+
* registerStyxLanguage(monaco, [
|
|
97
|
+
* { id: 'sql', def: sqlLang },
|
|
98
|
+
* ]);
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
declare function registerStyxLanguage(monacoInstance: typeof monaco, embeddedLanguages?: EmbeddedLanguage[], options?: RegisterStyxOptions): void;
|
|
102
|
+
|
|
103
|
+
export { type RegisterStyxOptions, StyxTokensProvider, catppuccinMocha, mocha, registerStyxLanguage, styxLanguageConfig };
|