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