@xnoxs/flux-lang 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/CHANGELOG.md +103 -0
  2. package/README.md +1089 -0
  3. package/bin/flux.js +1397 -0
  4. package/dist/flux.cjs.js +6664 -0
  5. package/dist/flux.esm.js +6674 -0
  6. package/dist/flux.min.js +263 -0
  7. package/index.d.ts +202 -0
  8. package/index.js +26 -0
  9. package/package.json +77 -0
  10. package/scripts/build.js +76 -0
  11. package/src/bundler.js +216 -0
  12. package/src/checker.js +322 -0
  13. package/src/codegen.js +785 -0
  14. package/src/css-preprocessor.js +399 -0
  15. package/src/formatter.js +140 -0
  16. package/src/jsx.js +480 -0
  17. package/src/lexer.js +518 -0
  18. package/src/linter.js +758 -0
  19. package/src/mangler.js +280 -0
  20. package/src/parser.js +1671 -0
  21. package/src/self/bundler.flux +167 -0
  22. package/src/self/bundler.js +187 -0
  23. package/src/self/checker.flux +249 -0
  24. package/src/self/checker.js +338 -0
  25. package/src/self/codegen.flux +555 -0
  26. package/src/self/codegen.js +784 -0
  27. package/src/self/css-preprocessor.flux +373 -0
  28. package/src/self/css-preprocessor.js +387 -0
  29. package/src/self/formatter.flux +93 -0
  30. package/src/self/formatter.js +114 -0
  31. package/src/self/jsx.flux +430 -0
  32. package/src/self/jsx.js +396 -0
  33. package/src/self/lexer.flux +529 -0
  34. package/src/self/lexer.js +709 -0
  35. package/src/self/lexer.stage2.js +700 -0
  36. package/src/self/linter.flux +515 -0
  37. package/src/self/linter.js +804 -0
  38. package/src/self/mangler.flux +253 -0
  39. package/src/self/mangler.js +348 -0
  40. package/src/self/parser.flux +1146 -0
  41. package/src/self/parser.js +1571 -0
  42. package/src/self/sourcemap.flux +66 -0
  43. package/src/self/sourcemap.js +72 -0
  44. package/src/self/stdlib.flux +356 -0
  45. package/src/self/stdlib.js +396 -0
  46. package/src/self/test-runner.flux +201 -0
  47. package/src/self/test-runner.js +132 -0
  48. package/src/self/transpiler.flux +123 -0
  49. package/src/self/transpiler.js +83 -0
  50. package/src/self/type-checker.flux +821 -0
  51. package/src/self/type-checker.js +1106 -0
  52. package/src/sourcemap.js +82 -0
  53. package/src/stdlib.js +436 -0
  54. package/src/test-runner.js +239 -0
  55. package/src/transpiler.js +172 -0
  56. package/src/type-checker.js +1206 -0
@@ -0,0 +1,709 @@
1
+ // ── Flux stdlib ──
2
+
3
+ function map(arr, fn) { return arr.map(fn); }
4
+
5
+ function some(arr, fn) { return arr.some(fn); }
6
+
7
+ function join(arr, sep) { return arr.join(sep != null ? sep : ','); }
8
+ // ── end stdlib ──
9
+
10
+ // Generated by Flux Transpiler v3.1.0
11
+ "use strict";
12
+
13
+ const T = { NUMBER: "NUMBER", STRING: "STRING", BOOL: "BOOL", NULL: "NULL", IDENT: "IDENT", VAR: "VAR", VAL: "VAL", FN: "FN", RETURN: "RETURN", IF: "IF", ELSE: "ELSE", FOR: "FOR", IN: "IN", WHILE: "WHILE", BREAK: "BREAK", CONTINUE: "CONTINUE", DO: "DO", CLASS: "CLASS", EXTENDS: "EXTENDS", SELF: "SELF", NEW: "NEW", INTERFACE: "INTERFACE", IMPLEMENTS: "IMPLEMENTS", PRIVATE: "PRIVATE", PUBLIC: "PUBLIC", PROTECTED: "PROTECTED", READONLY: "READONLY", STATIC: "STATIC", ABSTRACT: "ABSTRACT", OVERRIDE: "OVERRIDE", MATCH: "MATCH", WHEN: "WHEN", IMPORT: "IMPORT", EXPORT: "EXPORT", FROM: "FROM", AS: "AS", DEFAULT: "DEFAULT", AND: "AND", OR: "OR", NOT: "NOT", ASYNC: "ASYNC", AWAIT: "AWAIT", TRY: "TRY", CATCH: "CATCH", FINALLY: "FINALLY", THROW: "THROW", TYPEOF: "TYPEOF", INSTANCEOF: "INSTANCEOF", TYPE: "TYPE", ENUM: "ENUM", SATISFIES: "SATISFIES", IS: "IS", CONST: "CONST", PLUS: "PLUS", MINUS: "MINUS", STAR: "STAR", SLASH: "SLASH", PERCENT: "PERCENT", REGEX: "REGEX", STARSTAR: "STARSTAR", EQ: "EQ", EQEQ: "EQEQ", NEQ: "NEQ", EQEQEQ: "EQEQEQ", NEQEQ: "NEQEQ", LT: "LT", LTE: "LTE", GT: "GT", GTE: "GTE", PLUSEQ: "PLUSEQ", MINUSEQ: "MINUSEQ", STAREQ: "STAREQ", SLASHEQ: "SLASHEQ", PERCENTEQ: "PERCENTEQ", PLUSPLUS: "PLUSPLUS", MINUSMINUS: "MINUSMINUS", AMPERSAND: "AMPERSAND", ANDAND: "ANDAND", PIPEB: "PIPEB", OROR: "OROR", CARET: "CARET", TILDE: "TILDE", LSHIFT: "LSHIFT", RSHIFT: "RSHIFT", ARROW: "ARROW", FATARROW: "FATARROW", PIPE: "PIPE", DOTDOT: "DOTDOT", DOTDOTDOT: "DOTDOTDOT", WILDCARD: "WILDCARD", NULLISH: "NULLISH", QUESTIONDOT: "QUESTIONDOT", BANG: "BANG", AT: "AT", LPAREN: "LPAREN", RPAREN: "RPAREN", LBRACKET: "LBRACKET", RBRACKET: "RBRACKET", LBRACE: "LBRACE", RBRACE: "RBRACE", COMMA: "COMMA", DOT: "DOT", COLON: "COLON", QUESTION: "QUESTION", NEWLINE: "NEWLINE", INDENT: "INDENT", DEDENT: "DEDENT", EOF: "EOF" };
14
+ module.exports.T = T;
15
+ const TokenType = T;
16
+ module.exports.TokenType = TokenType;
17
+ const KEYWORDS = { var: "VAR", val: "VAL", fn: "FN", return: "RETURN", if: "IF", else: "ELSE", for: "FOR", in: "IN", while: "WHILE", break: "BREAK", continue: "CONTINUE", do: "DO", class: "CLASS", extends: "EXTENDS", self: "SELF", new: "NEW", interface: "INTERFACE", implements: "IMPLEMENTS", private: "PRIVATE", public: "PUBLIC", protected: "PROTECTED", readonly: "READONLY", static: "STATIC", abstract: "ABSTRACT", override: "OVERRIDE", match: "MATCH", when: "WHEN", import: "IMPORT", export: "EXPORT", from: "FROM", as: "AS", default: "DEFAULT", and: "AND", or: "OR", not: "NOT", async: "ASYNC", await: "AWAIT", try: "TRY", catch: "CATCH", finally: "FINALLY", throw: "THROW", typeof: "TYPEOF", instanceof: "INSTANCEOF", type: "TYPE", enum: "ENUM", satisfies: "SATISFIES", is: "IS", const: "CONST", true: "__TRUE__", false: "__FALSE__", null: "__NULL__" };
18
+ class Lexer {
19
+ constructor(src, pos, line, col, tokens, indentStack, nestDepth) {
20
+ this.src = src;
21
+ this.pos = pos;
22
+ this.line = line;
23
+ this.col = col;
24
+ this.tokens = tokens;
25
+ this.indentStack = indentStack;
26
+ this.nestDepth = nestDepth;
27
+ }
28
+
29
+ err(msg) {
30
+ throw new Error(`[Lexer ${this.line}:${this.col}] ${msg}`);
31
+ }
32
+
33
+ ch(n = 0) {
34
+ return (this.src[(this.pos + n)] ?? "");
35
+ }
36
+
37
+ adv() {
38
+ const c = this.src[this.pos];
39
+ this.pos = (this.pos + 1);
40
+ if ((c == "\n")) {
41
+ this.line = (this.line + 1);
42
+ this.col = 1;
43
+ }
44
+ else {
45
+ this.col = (this.col + 1);
46
+ }
47
+ return c;
48
+ }
49
+
50
+ tok(typ, value, l, c) {
51
+ const v = ((value != undefined) ? value : typ);
52
+ const ln = ((l != undefined) ? l : this.line);
53
+ const co = ((c != undefined) ? c : this.col);
54
+ this.tokens.push({ type: typ, value: v, line: ln, col: co });
55
+ }
56
+
57
+ applyIndent(indent) {
58
+ if ((this.nestDepth > 0)) {
59
+ return;
60
+ }
61
+ const top = this.indentStack[(this.indentStack.length - 1)];
62
+ if ((indent > top)) {
63
+ this.indentStack.push(indent);
64
+ this.tok(T.INDENT, indent, this.line, 1);
65
+ }
66
+ else if ((indent < top)) {
67
+ while (((this.indentStack.length > 1) && (this.indentStack[(this.indentStack.length - 1)] > indent))) {
68
+ this.indentStack.pop();
69
+ this.tok(T.DEDENT, null, this.line, 1);
70
+ }
71
+ if ((this.indentStack[(this.indentStack.length - 1)] != indent)) {
72
+ this.err(`Inconsistent indentation (${indent} spaces)`);
73
+ }
74
+ }
75
+ }
76
+
77
+ scanBacktick(l, c) {
78
+ this.adv();
79
+ let s = "";
80
+ while (((this.pos < this.src.length) && (this.ch() != "`"))) {
81
+ if ((this.ch() == "\\")) {
82
+ this.adv();
83
+ const e = this.adv();
84
+ if ((e == "n")) {
85
+ s += "\n";
86
+ }
87
+ else if ((e == "t")) {
88
+ s += "\t";
89
+ }
90
+ else if ((e == "`")) {
91
+ s += "`";
92
+ }
93
+ else if ((e == "\\")) {
94
+ s += "\\";
95
+ }
96
+ else {
97
+ s += ("\\" + e);
98
+ }
99
+ }
100
+ else {
101
+ s += this.adv();
102
+ }
103
+ }
104
+ if ((this.ch() != "`")) {
105
+ this.err("Unterminated backtick string");
106
+ }
107
+ this.adv();
108
+ const rawLines = s.split("\n");
109
+ const trimmed = rawLines.map((ln) => ln.trimEnd());
110
+ while ((trimmed.length && !trimmed[0].trim())) {
111
+ trimmed.shift();
112
+ }
113
+ while ((trimmed.length && !trimmed[(trimmed.length - 1)].trim())) {
114
+ trimmed.pop();
115
+ }
116
+ let minIndent = 999999;
117
+ for (const ln of trimmed) {
118
+ if (ln.trim()) {
119
+ const m = ln.match(/^(\s*)/);
120
+ const ind = m[1].length;
121
+ if ((ind < minIndent)) {
122
+ minIndent = ind;
123
+ }
124
+ }
125
+ }
126
+ if ((minIndent == 999999)) {
127
+ minIndent = 0;
128
+ }
129
+ const dedented = trimmed.map((ln) => ln.slice(minIndent));
130
+ this.tok(T.STRING, dedented.join("\n"), l, c);
131
+ }
132
+
133
+ scanStr(l, c) {
134
+ this.adv();
135
+ const parts = [];
136
+ let text = "";
137
+ while (((this.pos < this.src.length) && (this.ch() != "\""))) {
138
+ if ((this.ch() == "\\")) {
139
+ this.adv();
140
+ const e = this.adv();
141
+ if ((e == "n")) {
142
+ text += "\n";
143
+ }
144
+ else if ((e == "t")) {
145
+ text += "\t";
146
+ }
147
+ else if ((e == "\"")) {
148
+ text += "\"";
149
+ }
150
+ else if ((e == "'")) {
151
+ text += "'";
152
+ }
153
+ else if ((e == "\\")) {
154
+ text += "\\";
155
+ }
156
+ else if ((e == "{")) {
157
+ text += "{";
158
+ }
159
+ else if ((e == "}")) {
160
+ text += "}";
161
+ }
162
+ else {
163
+ text += ("\\" + e);
164
+ }
165
+ }
166
+ else if ((this.ch() == "{")) {
167
+ parts.push({ type: "text", value: text });
168
+ text = "";
169
+ this.adv();
170
+ let depth = 1;
171
+ let expr = "";
172
+ while ((this.pos < this.src.length)) {
173
+ const cc = this.ch();
174
+ if ((cc == "{")) {
175
+ depth = (depth + 1);
176
+ }
177
+ if ((cc == "}")) {
178
+ depth = (depth - 1);
179
+ if ((depth == 0)) {
180
+ break;
181
+ }
182
+ }
183
+ if (((cc == "\\") && ((this.src[(this.pos + 1)] == "\"") || (this.src[(this.pos + 1)] == "'")))) {
184
+ this.adv();
185
+ expr += this.adv();
186
+ }
187
+ else {
188
+ expr += this.adv();
189
+ }
190
+ }
191
+ if ((this.ch() != "}")) {
192
+ this.err("Unclosed string interpolation");
193
+ }
194
+ this.adv();
195
+ parts.push({ type: "expr", value: expr.trim() });
196
+ }
197
+ else {
198
+ text += this.adv();
199
+ }
200
+ }
201
+ if ((this.ch() != "\"")) {
202
+ this.err("Unterminated string");
203
+ }
204
+ this.adv();
205
+ parts.push({ type: "text", value: text });
206
+ if (parts.some((p) => (p.type == "expr"))) {
207
+ this.tok(T.STRING, { template: true, parts }, l, c);
208
+ }
209
+ else {
210
+ this.tok(T.STRING, parts.map((p) => p.value).join(""), l, c);
211
+ }
212
+ }
213
+
214
+ scanRegexBody(l, c) {
215
+ let pattern = "";
216
+ let inClass = false;
217
+ while ((this.pos < this.src.length)) {
218
+ const ch = this.ch();
219
+ if ((ch == "\n")) {
220
+ this.err("Unterminated regex literal");
221
+ }
222
+ if ((ch == "\\")) {
223
+ pattern += this.adv();
224
+ if ((this.pos < this.src.length)) {
225
+ pattern += this.adv();
226
+ }
227
+ continue;
228
+ }
229
+ if ((ch == "[")) {
230
+ inClass = true;
231
+ pattern += this.adv();
232
+ continue;
233
+ }
234
+ if ((ch == "]")) {
235
+ inClass = false;
236
+ pattern += this.adv();
237
+ continue;
238
+ }
239
+ if (((ch == "/") && !inClass)) {
240
+ break;
241
+ }
242
+ pattern += this.adv();
243
+ }
244
+ if ((this.ch() != "/")) {
245
+ this.err("Unterminated regex literal");
246
+ }
247
+ this.adv();
248
+ let flags = "";
249
+ while (/[gimsuy]/.test(this.ch())) {
250
+ flags += this.adv();
251
+ }
252
+ this.tok(T.REGEX, { pattern, flags }, l, c);
253
+ }
254
+
255
+ scanBlockComment() {
256
+ this.adv();
257
+ this.adv();
258
+ while ((this.pos < this.src.length)) {
259
+ if (((this.ch() == "*") && (this.ch(1) == "/"))) {
260
+ this.adv();
261
+ this.adv();
262
+ return;
263
+ }
264
+ this.adv();
265
+ }
266
+ this.err("Unterminated block comment");
267
+ }
268
+
269
+ tokenize() {
270
+ let bol = true;
271
+ while ((this.pos < this.src.length)) {
272
+ if (bol) {
273
+ bol = false;
274
+ let indent = 0;
275
+ while (((this.ch() == " ") || (this.ch() == "\t"))) {
276
+ if ((this.ch() == "\t")) {
277
+ indent = (indent + 4);
278
+ }
279
+ else {
280
+ indent = (indent + 1);
281
+ }
282
+ this.adv();
283
+ }
284
+ if (((this.ch() == "\n") || !this.ch())) {
285
+ if ((this.ch() == "\n")) {
286
+ this.adv();
287
+ bol = true;
288
+ }
289
+ continue;
290
+ }
291
+ if (((this.ch() == "/") && (this.ch(1) == "/"))) {
292
+ while (((this.pos < this.src.length) && (this.ch() != "\n"))) {
293
+ this.adv();
294
+ }
295
+ if ((this.ch() == "\n")) {
296
+ this.adv();
297
+ bol = true;
298
+ }
299
+ continue;
300
+ }
301
+ if (((this.ch() == "/") && (this.ch(1) == "*"))) {
302
+ this.scanBlockComment();
303
+ continue;
304
+ }
305
+ const isContinuation = ((((this.ch() == "|") && (this.ch(1) == ">")) || (this.ch() == ".")) || ((this.ch() == "?") && (this.ch(1) == ".")));
306
+ if (isContinuation) {
307
+ const lastTok = this.tokens[(this.tokens.length - 1)];
308
+ if ((lastTok && (lastTok.type == T.NEWLINE))) {
309
+ this.tokens.pop();
310
+ }
311
+ }
312
+ else {
313
+ this.applyIndent(indent);
314
+ }
315
+ }
316
+ const l = this.line;
317
+ const c = this.col;
318
+ const cur = this.ch();
319
+ if ((cur == "\n")) {
320
+ this.adv();
321
+ bol = true;
322
+ if ((this.nestDepth == 0)) {
323
+ const lastTok = this.tokens[(this.tokens.length - 1)];
324
+ if ((((lastTok && (lastTok.type != T.NEWLINE)) && (lastTok.type != T.INDENT)) && (lastTok.type != T.DEDENT))) {
325
+ this.tok(T.NEWLINE, null, l, c);
326
+ }
327
+ }
328
+ continue;
329
+ }
330
+ if (((cur == " ") || (cur == "\t"))) {
331
+ this.adv();
332
+ continue;
333
+ }
334
+ if (((cur == "/") && (this.ch(1) == "/"))) {
335
+ while (((this.pos < this.src.length) && (this.ch() != "\n"))) {
336
+ this.adv();
337
+ }
338
+ continue;
339
+ }
340
+ if (((cur == "/") && (this.ch(1) == "*"))) {
341
+ this.scanBlockComment();
342
+ continue;
343
+ }
344
+ if (((cur >= "0") && (cur <= "9"))) {
345
+ if (((cur == "0") && ((this.ch(1) == "x") || (this.ch(1) == "X")))) {
346
+ this.adv();
347
+ this.adv();
348
+ let h = "";
349
+ while (/[0-9a-fA-F_]/.test(this.ch())) {
350
+ const hc = this.adv();
351
+ if ((hc != "_")) {
352
+ h += hc;
353
+ }
354
+ }
355
+ this.tok(T.NUMBER, parseInt(((h.length > 0) ? h : "0"), 16), l, c);
356
+ continue;
357
+ }
358
+ if (((cur == "0") && ((this.ch(1) == "b") || (this.ch(1) == "B")))) {
359
+ this.adv();
360
+ this.adv();
361
+ let b = "";
362
+ while (/[01_]/.test(this.ch())) {
363
+ const bc = this.adv();
364
+ if ((bc != "_")) {
365
+ b += bc;
366
+ }
367
+ }
368
+ this.tok(T.NUMBER, parseInt(((b.length > 0) ? b : "0"), 2), l, c);
369
+ continue;
370
+ }
371
+ let numStr = "";
372
+ while ((this.pos < this.src.length)) {
373
+ if (((this.ch() == ".") && (this.ch(1) == "."))) {
374
+ break;
375
+ }
376
+ if ((((this.ch() >= "0") && (this.ch() <= "9")) || (this.ch() == "."))) {
377
+ numStr += this.adv();
378
+ }
379
+ else if ((this.ch() == "_")) {
380
+ this.adv();
381
+ }
382
+ else if ((((this.ch() == "e") || (this.ch() == "E")) && (numStr.length > 0))) {
383
+ numStr += this.adv();
384
+ if (((this.ch() == "+") || (this.ch() == "-"))) {
385
+ numStr += this.adv();
386
+ }
387
+ while (((this.ch() >= "0") && (this.ch() <= "9"))) {
388
+ numStr += this.adv();
389
+ }
390
+ break;
391
+ }
392
+ else {
393
+ break;
394
+ }
395
+ }
396
+ this.tok(T.NUMBER, parseFloat(numStr), l, c);
397
+ continue;
398
+ }
399
+ if ((cur == "\"")) {
400
+ this.scanStr(l, c);
401
+ continue;
402
+ }
403
+ if ((cur == "`")) {
404
+ this.scanBacktick(l, c);
405
+ continue;
406
+ }
407
+ if ((cur == "'")) {
408
+ this.adv();
409
+ let sq = "";
410
+ while (((this.pos < this.src.length) && (this.ch() != "'"))) {
411
+ if ((this.ch() == "\\")) {
412
+ this.adv();
413
+ const e = this.adv();
414
+ if ((e == "n")) {
415
+ sq += "\n";
416
+ }
417
+ else if ((e == "t")) {
418
+ sq += "\t";
419
+ }
420
+ else if ((e == "r")) {
421
+ sq += "\r";
422
+ }
423
+ else if ((e == "'")) {
424
+ sq += "'";
425
+ }
426
+ else if ((e == "\\")) {
427
+ sq += "\\";
428
+ }
429
+ else {
430
+ sq += ("\\" + e);
431
+ }
432
+ }
433
+ else {
434
+ sq += this.adv();
435
+ }
436
+ }
437
+ if ((this.ch() != "'")) {
438
+ this.err("Unterminated string");
439
+ }
440
+ this.adv();
441
+ this.tok(T.STRING, sq, l, c);
442
+ continue;
443
+ }
444
+ if (((((cur >= "a") && (cur <= "z")) || ((cur >= "A") && (cur <= "Z"))) || (cur == "_"))) {
445
+ let word = "";
446
+ while (/[a-zA-Z0-9_]/.test(this.ch())) {
447
+ word += this.adv();
448
+ }
449
+ if (((word == "_") && !/[a-zA-Z0-9_]/.test(this.ch()))) {
450
+ this.tok(T.WILDCARD, "_", l, c);
451
+ continue;
452
+ }
453
+ const kw = KEYWORDS[word];
454
+ if ((kw == "__TRUE__")) {
455
+ this.tok(T.BOOL, true, l, c);
456
+ }
457
+ else if ((kw == "__FALSE__")) {
458
+ this.tok(T.BOOL, false, l, c);
459
+ }
460
+ else if ((kw == "__NULL__")) {
461
+ this.tok(T.NULL, null, l, c);
462
+ }
463
+ else if ((kw != undefined)) {
464
+ this.tok(kw, word, l, c);
465
+ }
466
+ else {
467
+ this.tok(T.IDENT, word, l, c);
468
+ }
469
+ continue;
470
+ }
471
+ this.adv();
472
+ if ((cur == "+")) {
473
+ if ((this.ch() == "+")) {
474
+ this.adv();
475
+ this.tok(T.PLUSPLUS, "++", l, c);
476
+ }
477
+ else if ((this.ch() == "=")) {
478
+ this.adv();
479
+ this.tok(T.PLUSEQ, "+=", l, c);
480
+ }
481
+ else {
482
+ this.tok(T.PLUS, "+", l, c);
483
+ }
484
+ }
485
+ else if ((cur == "-")) {
486
+ if ((this.ch() == "-")) {
487
+ this.adv();
488
+ this.tok(T.MINUSMINUS, "--", l, c);
489
+ }
490
+ else if ((this.ch() == ">")) {
491
+ this.adv();
492
+ this.tok(T.ARROW, "->", l, c);
493
+ }
494
+ else if ((this.ch() == "=")) {
495
+ this.adv();
496
+ this.tok(T.MINUSEQ, "-=", l, c);
497
+ }
498
+ else {
499
+ this.tok(T.MINUS, "-", l, c);
500
+ }
501
+ }
502
+ else if ((cur == "*")) {
503
+ if ((this.ch() == "*")) {
504
+ this.adv();
505
+ this.tok(T.STARSTAR, "**", l, c);
506
+ }
507
+ else if ((this.ch() == "=")) {
508
+ this.adv();
509
+ this.tok(T.STAREQ, "*=", l, c);
510
+ }
511
+ else {
512
+ this.tok(T.STAR, "*", l, c);
513
+ }
514
+ }
515
+ else if ((cur == "/")) {
516
+ if ((this.ch() == "=")) {
517
+ this.adv();
518
+ this.tok(T.SLASHEQ, "/=", l, c);
519
+ }
520
+ else {
521
+ const lastTok = this.tokens[(this.tokens.length - 1)];
522
+ const afterVal = ((lastTok != null) && (((((((((((lastTok.type == T.IDENT) || (lastTok.type == T.NUMBER)) || (lastTok.type == T.STRING)) || (lastTok.type == T.BOOL)) || (lastTok.type == T.NULL)) || (lastTok.type == T.REGEX)) || (lastTok.type == T.RPAREN)) || (lastTok.type == T.RBRACKET)) || (lastTok.type == T.PLUSPLUS)) || (lastTok.type == T.MINUSMINUS)) || (lastTok.type == T.BANG)));
523
+ if (afterVal) {
524
+ this.tok(T.SLASH, "/", l, c);
525
+ }
526
+ else {
527
+ this.scanRegexBody(l, c);
528
+ }
529
+ }
530
+ }
531
+ else if ((cur == "%")) {
532
+ if ((this.ch() == "=")) {
533
+ this.adv();
534
+ this.tok(T.PERCENTEQ, "%=", l, c);
535
+ }
536
+ else {
537
+ this.tok(T.PERCENT, "%", l, c);
538
+ }
539
+ }
540
+ else if ((cur == "=")) {
541
+ if (((this.ch() == "=") && (this.src[(this.pos + 1)] == "="))) {
542
+ this.adv();
543
+ this.adv();
544
+ this.tok(T.EQEQEQ, "===", l, c);
545
+ }
546
+ else if ((this.ch() == "=")) {
547
+ this.adv();
548
+ this.tok(T.EQEQ, "==", l, c);
549
+ }
550
+ else if ((this.ch() == ">")) {
551
+ this.adv();
552
+ this.tok(T.FATARROW, "=>", l, c);
553
+ }
554
+ else {
555
+ this.tok(T.EQ, "=", l, c);
556
+ }
557
+ }
558
+ else if ((cur == "!")) {
559
+ if (((this.ch() == "=") && (this.src[(this.pos + 1)] == "="))) {
560
+ this.adv();
561
+ this.adv();
562
+ this.tok(T.NEQEQ, "!==", l, c);
563
+ }
564
+ else if ((this.ch() == "=")) {
565
+ this.adv();
566
+ this.tok(T.NEQ, "!=", l, c);
567
+ }
568
+ else {
569
+ this.tok(T.BANG, "!", l, c);
570
+ }
571
+ }
572
+ else if ((cur == "<")) {
573
+ if ((this.ch() == "<")) {
574
+ this.adv();
575
+ this.tok(T.LSHIFT, "<<", l, c);
576
+ }
577
+ else if ((this.ch() == "=")) {
578
+ this.adv();
579
+ this.tok(T.LTE, "<=", l, c);
580
+ }
581
+ else {
582
+ this.tok(T.LT, "<", l, c);
583
+ }
584
+ }
585
+ else if ((cur == ">")) {
586
+ if ((this.ch() == ">")) {
587
+ this.adv();
588
+ this.tok(T.RSHIFT, ">>", l, c);
589
+ }
590
+ else if ((this.ch() == "=")) {
591
+ this.adv();
592
+ this.tok(T.GTE, ">=", l, c);
593
+ }
594
+ else {
595
+ this.tok(T.GT, ">", l, c);
596
+ }
597
+ }
598
+ else if ((cur == ".")) {
599
+ if (((this.ch() == ".") && (this.src[(this.pos + 1)] == "."))) {
600
+ this.adv();
601
+ this.adv();
602
+ this.tok(T.DOTDOTDOT, "...", l, c);
603
+ }
604
+ else if ((this.ch() == ".")) {
605
+ this.adv();
606
+ this.tok(T.DOTDOT, "..", l, c);
607
+ }
608
+ else {
609
+ this.tok(T.DOT, ".", l, c);
610
+ }
611
+ }
612
+ else if ((cur == "?")) {
613
+ if ((this.ch() == ".")) {
614
+ this.adv();
615
+ this.tok(T.QUESTIONDOT, "?.", l, c);
616
+ }
617
+ else if ((this.ch() == "?")) {
618
+ this.adv();
619
+ this.tok(T.NULLISH, "??", l, c);
620
+ }
621
+ else {
622
+ this.tok(T.QUESTION, "?", l, c);
623
+ }
624
+ }
625
+ else if ((cur == "|")) {
626
+ if ((this.ch() == ">")) {
627
+ this.adv();
628
+ this.tok(T.PIPE, "|>", l, c);
629
+ }
630
+ else if ((this.ch() == "|")) {
631
+ this.adv();
632
+ this.tok(T.OROR, "||", l, c);
633
+ }
634
+ else {
635
+ this.tok(T.PIPEB, "|", l, c);
636
+ }
637
+ }
638
+ else if ((cur == "&")) {
639
+ if ((this.ch() == "&")) {
640
+ this.adv();
641
+ this.tok(T.ANDAND, "&&", l, c);
642
+ }
643
+ else {
644
+ this.tok(T.AMPERSAND, "&", l, c);
645
+ }
646
+ }
647
+ else if ((cur == "^")) {
648
+ this.tok(T.CARET, "^", l, c);
649
+ }
650
+ else if ((cur == "~")) {
651
+ this.tok(T.TILDE, "~", l, c);
652
+ }
653
+ else if ((cur == "@")) {
654
+ this.tok(T.AT, "@", l, c);
655
+ }
656
+ else if ((cur == "(")) {
657
+ this.nestDepth = (this.nestDepth + 1);
658
+ this.tok(T.LPAREN, "(", l, c);
659
+ }
660
+ else if ((cur == ")")) {
661
+ this.nestDepth = (this.nestDepth - 1);
662
+ this.tok(T.RPAREN, ")", l, c);
663
+ }
664
+ else if ((cur == "[")) {
665
+ this.nestDepth = (this.nestDepth + 1);
666
+ this.tok(T.LBRACKET, "[", l, c);
667
+ }
668
+ else if ((cur == "]")) {
669
+ this.nestDepth = (this.nestDepth - 1);
670
+ this.tok(T.RBRACKET, "]", l, c);
671
+ }
672
+ else if ((cur == "{")) {
673
+ this.nestDepth = (this.nestDepth + 1);
674
+ this.tok(T.LBRACE, "{", l, c);
675
+ }
676
+ else if ((cur == "}")) {
677
+ this.nestDepth = (this.nestDepth - 1);
678
+ this.tok(T.RBRACE, "}", l, c);
679
+ }
680
+ else if ((cur == ",")) {
681
+ this.tok(T.COMMA, ",", l, c);
682
+ }
683
+ else if ((cur == ":")) {
684
+ this.tok(T.COLON, ":", l, c);
685
+ }
686
+ else if ((cur != ";")) {
687
+ this.err(`Unknown character: '${cur}'`);
688
+ }
689
+ }
690
+ while ((this.indentStack.length > 1)) {
691
+ this.indentStack.pop();
692
+ this.tok(T.DEDENT, null, this.line, 1);
693
+ }
694
+ const lastTok = this.tokens[(this.tokens.length - 1)];
695
+ if (((lastTok && (lastTok.type != T.NEWLINE)) && (lastTok.type != T.DEDENT))) {
696
+ this.tok(T.NEWLINE, null, this.line, this.col);
697
+ }
698
+ this.tok(T.EOF, null, this.line, this.col);
699
+ return this.tokens;
700
+ }
701
+
702
+ }
703
+
704
+ module.exports.Lexer = Lexer;
705
+ function lexerize(source) {
706
+ const processed = source.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
707
+ return new Lexer(processed, 0, 1, 1, [], [0], 0);
708
+ }
709
+ module.exports.lexerize = lexerize;