xmlui 0.9.1 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{apiInterceptorWorker-230V_-Ds.mjs → apiInterceptorWorker-DJ_oGB-F.mjs} +1 -1
- package/dist/{index-DUwwx3L4.mjs → index-2qtmUAFJ.mjs} +11 -11
- package/dist/index.css +12 -14
- package/dist/scripts/bin/vite-xmlui-plugin.js +1 -1
- package/dist/scripts/src/abstractions/scripting/ScriptingSourceTree.js +48 -0
- package/dist/scripts/src/components/Markdown/MarkdownNative.js +2 -2
- package/dist/scripts/src/components-core/RestApiProxy.js +2 -2
- package/dist/scripts/src/components-core/rendering/Container.js +3 -3
- package/dist/scripts/src/components-core/rendering/StateContainer.js +3 -3
- package/dist/scripts/src/components-core/script-runner/ParameterParser.js +1 -1
- package/dist/scripts/src/components-core/script-runner/eval-tree-async.js +37 -37
- package/dist/scripts/src/components-core/script-runner/eval-tree-common.js +8 -8
- package/dist/scripts/src/components-core/script-runner/eval-tree-sync.js +37 -37
- package/dist/scripts/src/components-core/script-runner/process-statement-async.js +29 -29
- package/dist/scripts/src/components-core/script-runner/process-statement-common.js +5 -5
- package/dist/scripts/src/components-core/script-runner/process-statement-sync.js +29 -29
- package/dist/scripts/src/components-core/script-runner/visitors.js +47 -47
- package/dist/scripts/src/components-core/theming/ThemeProvider.js +2 -2
- package/dist/scripts/src/components-core/theming/themes/root.js +1 -1
- package/dist/scripts/src/components-core/utils/statementUtils.js +32 -32
- package/dist/scripts/src/parsers/scripting/Lexer.js +166 -178
- package/dist/scripts/src/parsers/scripting/Parser.js +555 -701
- package/dist/scripts/src/parsers/scripting/ParserError.js +3 -3
- package/dist/scripts/src/parsers/scripting/TokenTrait.js +103 -105
- package/dist/scripts/src/parsers/{scripting-exp → scripting}/code-behind-collect.js +4 -4
- package/dist/scripts/src/parsers/{scripting-exp → scripting}/modules.js +2 -2
- package/dist/scripts/src/parsers/{scripting-exp → scripting}/tree-visitor.js +45 -45
- package/dist/scripts/src/parsers/xmlui-parser/transform.js +2 -2
- package/dist/style.css +12 -14
- package/dist/xmlui-metadata.mjs +1 -1
- package/dist/xmlui-metadata.umd.js +1 -1
- package/dist/xmlui-parser.d.ts +1 -11
- package/dist/xmlui-standalone.umd.js +25 -27
- package/dist/xmlui.d.ts +2 -75
- package/dist/xmlui.mjs +1 -1
- package/package.json +3 -3
- package/dist/scripts/src/abstractions/scripting/ScriptingSourceTreeExp.js +0 -50
- package/dist/scripts/src/abstractions/scripting/Token.js +0 -112
- package/dist/scripts/src/components-core/theming/abstractions.js +0 -11
- package/dist/scripts/src/parsers/scripting-exp/Lexer.js +0 -1092
- package/dist/scripts/src/parsers/scripting-exp/Parser.js +0 -2635
- package/dist/scripts/src/parsers/scripting-exp/ParserError.js +0 -47
- package/dist/scripts/src/parsers/scripting-exp/TokenTrait.js +0 -109
- /package/dist/scripts/src/abstractions/scripting/{LogicalThreadExp.js → LogicalThread.js} +0 -0
- /package/dist/scripts/src/parsers/{scripting-exp → scripting}/TokenType.js +0 -0
|
@@ -1,1092 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Lexer = void 0;
|
|
4
|
-
const regexpp_1 = require("@eslint-community/regexpp");
|
|
5
|
-
const TokenType_1 = require("./TokenType");
|
|
6
|
-
/**
|
|
7
|
-
* This enum indicates the current lexer phase
|
|
8
|
-
*/
|
|
9
|
-
var LexerPhase;
|
|
10
|
-
(function (LexerPhase) {
|
|
11
|
-
// Start getting a token
|
|
12
|
-
LexerPhase[LexerPhase["Start"] = 0] = "Start";
|
|
13
|
-
// Collecting whitespace
|
|
14
|
-
LexerPhase[LexerPhase["InWhiteSpace"] = 1] = "InWhiteSpace";
|
|
15
|
-
// Comment phases
|
|
16
|
-
LexerPhase[LexerPhase["InlineCommentTrail"] = 2] = "InlineCommentTrail";
|
|
17
|
-
LexerPhase[LexerPhase["BlockCommentTrail1"] = 3] = "BlockCommentTrail1";
|
|
18
|
-
LexerPhase[LexerPhase["BlockCommentTrail2"] = 4] = "BlockCommentTrail2";
|
|
19
|
-
// Multi-char tokens
|
|
20
|
-
LexerPhase[LexerPhase["Slash"] = 5] = "Slash";
|
|
21
|
-
LexerPhase[LexerPhase["Dollar"] = 6] = "Dollar";
|
|
22
|
-
LexerPhase[LexerPhase["Or"] = 7] = "Or";
|
|
23
|
-
LexerPhase[LexerPhase["Asterisk"] = 8] = "Asterisk";
|
|
24
|
-
LexerPhase[LexerPhase["Ampersand"] = 9] = "Ampersand";
|
|
25
|
-
LexerPhase[LexerPhase["Equal"] = 10] = "Equal";
|
|
26
|
-
LexerPhase[LexerPhase["DoubleEqual"] = 11] = "DoubleEqual";
|
|
27
|
-
LexerPhase[LexerPhase["NotEqual"] = 12] = "NotEqual";
|
|
28
|
-
LexerPhase[LexerPhase["Exclamation"] = 13] = "Exclamation";
|
|
29
|
-
LexerPhase[LexerPhase["AngleLeft"] = 14] = "AngleLeft";
|
|
30
|
-
LexerPhase[LexerPhase["AngleRight"] = 15] = "AngleRight";
|
|
31
|
-
LexerPhase[LexerPhase["SignedShiftRight"] = 16] = "SignedShiftRight";
|
|
32
|
-
LexerPhase[LexerPhase["IdTail"] = 17] = "IdTail";
|
|
33
|
-
LexerPhase[LexerPhase["Dot"] = 18] = "Dot";
|
|
34
|
-
LexerPhase[LexerPhase["DotDot"] = 19] = "DotDot";
|
|
35
|
-
LexerPhase[LexerPhase["Colon"] = 20] = "Colon";
|
|
36
|
-
LexerPhase[LexerPhase["Zero"] = 21] = "Zero";
|
|
37
|
-
LexerPhase[LexerPhase["QuestionMark"] = 22] = "QuestionMark";
|
|
38
|
-
LexerPhase[LexerPhase["HexaFirst"] = 23] = "HexaFirst";
|
|
39
|
-
LexerPhase[LexerPhase["HexaTail"] = 24] = "HexaTail";
|
|
40
|
-
LexerPhase[LexerPhase["BinaryFirst"] = 25] = "BinaryFirst";
|
|
41
|
-
LexerPhase[LexerPhase["BinaryTail"] = 26] = "BinaryTail";
|
|
42
|
-
LexerPhase[LexerPhase["DecimalOrReal"] = 27] = "DecimalOrReal";
|
|
43
|
-
LexerPhase[LexerPhase["RealFractionalFirst"] = 28] = "RealFractionalFirst";
|
|
44
|
-
LexerPhase[LexerPhase["RealFractionalTail"] = 29] = "RealFractionalTail";
|
|
45
|
-
LexerPhase[LexerPhase["RealExponent"] = 30] = "RealExponent";
|
|
46
|
-
LexerPhase[LexerPhase["RealExponentSign"] = 31] = "RealExponentSign";
|
|
47
|
-
LexerPhase[LexerPhase["RealExponentTail"] = 32] = "RealExponentTail";
|
|
48
|
-
LexerPhase[LexerPhase["StringTemplateLiteralBackSlash"] = 33] = "StringTemplateLiteralBackSlash";
|
|
49
|
-
LexerPhase[LexerPhase["StringTemplateLiteral"] = 34] = "StringTemplateLiteral";
|
|
50
|
-
LexerPhase[LexerPhase["String"] = 35] = "String";
|
|
51
|
-
LexerPhase[LexerPhase["StringBackSlash"] = 36] = "StringBackSlash";
|
|
52
|
-
LexerPhase[LexerPhase["StringHexa1"] = 37] = "StringHexa1";
|
|
53
|
-
LexerPhase[LexerPhase["StringHexa2"] = 38] = "StringHexa2";
|
|
54
|
-
LexerPhase[LexerPhase["StringUHexa1"] = 39] = "StringUHexa1";
|
|
55
|
-
LexerPhase[LexerPhase["StringUHexa2"] = 40] = "StringUHexa2";
|
|
56
|
-
LexerPhase[LexerPhase["StringUHexa3"] = 41] = "StringUHexa3";
|
|
57
|
-
LexerPhase[LexerPhase["StringUHexa4"] = 42] = "StringUHexa4";
|
|
58
|
-
LexerPhase[LexerPhase["StringUcp1"] = 43] = "StringUcp1";
|
|
59
|
-
LexerPhase[LexerPhase["StringUcp2"] = 44] = "StringUcp2";
|
|
60
|
-
LexerPhase[LexerPhase["StringUcp3"] = 45] = "StringUcp3";
|
|
61
|
-
LexerPhase[LexerPhase["StringUcp4"] = 46] = "StringUcp4";
|
|
62
|
-
LexerPhase[LexerPhase["StringUcp5"] = 47] = "StringUcp5";
|
|
63
|
-
LexerPhase[LexerPhase["StringUcp6"] = 48] = "StringUcp6";
|
|
64
|
-
LexerPhase[LexerPhase["StringUcpTail"] = 49] = "StringUcpTail";
|
|
65
|
-
// --- Assignments
|
|
66
|
-
LexerPhase[LexerPhase["Exponent"] = 50] = "Exponent";
|
|
67
|
-
LexerPhase[LexerPhase["Plus"] = 51] = "Plus";
|
|
68
|
-
LexerPhase[LexerPhase["Minus"] = 52] = "Minus";
|
|
69
|
-
LexerPhase[LexerPhase["Divide"] = 53] = "Divide";
|
|
70
|
-
LexerPhase[LexerPhase["Remainder"] = 54] = "Remainder";
|
|
71
|
-
LexerPhase[LexerPhase["ShiftLeft"] = 55] = "ShiftLeft";
|
|
72
|
-
LexerPhase[LexerPhase["ShiftRight"] = 56] = "ShiftRight";
|
|
73
|
-
LexerPhase[LexerPhase["LogicalAnd"] = 57] = "LogicalAnd";
|
|
74
|
-
LexerPhase[LexerPhase["BitwiseXor"] = 58] = "BitwiseXor";
|
|
75
|
-
LexerPhase[LexerPhase["LogicalOr"] = 59] = "LogicalOr";
|
|
76
|
-
LexerPhase[LexerPhase["NullCoalesce"] = 60] = "NullCoalesce";
|
|
77
|
-
// --- Other
|
|
78
|
-
LexerPhase[LexerPhase["RegEx"] = 61] = "RegEx";
|
|
79
|
-
})(LexerPhase || (LexerPhase = {}));
|
|
80
|
-
/**
|
|
81
|
-
* This class implements the lexer of binding expressions
|
|
82
|
-
*/
|
|
83
|
-
class Lexer {
|
|
84
|
-
/**
|
|
85
|
-
* Initializes the tokenizer with the input stream
|
|
86
|
-
* @param input Input source code stream
|
|
87
|
-
*/
|
|
88
|
-
constructor(input) {
|
|
89
|
-
this.input = input;
|
|
90
|
-
// --- Already fetched tokens
|
|
91
|
-
this._ahead = [];
|
|
92
|
-
// --- Prefetched character (from the next token)
|
|
93
|
-
this._prefetched = null;
|
|
94
|
-
// --- Prefetched character position (from the next token)
|
|
95
|
-
this._prefetchedPos = null;
|
|
96
|
-
// --- Prefetched character column (from the next token)
|
|
97
|
-
this._prefetchedColumn = null;
|
|
98
|
-
// --- input position at the beginning of last fetch
|
|
99
|
-
this._lastFetchPosition = 0;
|
|
100
|
-
this._phaseExternallySet = null;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Fetches the next token without advancing to its position
|
|
104
|
-
* @param ws If true, retrieve whitespaces too
|
|
105
|
-
*/
|
|
106
|
-
peek(ws = false) {
|
|
107
|
-
return this.ahead(0, ws);
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Reads tokens ahead
|
|
111
|
-
* @param n Number of token positions to read ahead
|
|
112
|
-
* @param ws If true, retrieve whitespaces too
|
|
113
|
-
*/
|
|
114
|
-
ahead(n = 1, ws = false) {
|
|
115
|
-
if (n > 16) {
|
|
116
|
-
throw new Error("Cannot look ahead more than 16 tokens");
|
|
117
|
-
}
|
|
118
|
-
// --- Prefetch missing tokens
|
|
119
|
-
while (this._ahead.length <= n) {
|
|
120
|
-
const token = this.fetch();
|
|
121
|
-
if (isEof(token)) {
|
|
122
|
-
return token;
|
|
123
|
-
}
|
|
124
|
-
if (ws || (!ws && !isWs(token))) {
|
|
125
|
-
this._ahead.push(token);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
return this._ahead[n];
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Fetches the next token and advances the stream position
|
|
132
|
-
* @param ws If true, retrieve whitespaces too
|
|
133
|
-
*/
|
|
134
|
-
get(ws = false) {
|
|
135
|
-
if (this._ahead.length > 0) {
|
|
136
|
-
const token = this._ahead.shift();
|
|
137
|
-
if (!token) {
|
|
138
|
-
throw new Error("Token expected");
|
|
139
|
-
}
|
|
140
|
-
return token;
|
|
141
|
-
}
|
|
142
|
-
while (true) {
|
|
143
|
-
const token = this.fetch();
|
|
144
|
-
if (isEof(token) || ws || (!ws && !isWs(token))) {
|
|
145
|
-
return token;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Gets a RegEx from the current position
|
|
151
|
-
*/
|
|
152
|
-
getRegEx() {
|
|
153
|
-
return this.fetchRegEx();
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Gets the remaining characters after the parsing phase
|
|
157
|
-
*/
|
|
158
|
-
getTail() {
|
|
159
|
-
return this._ahead.length > 0
|
|
160
|
-
? this.input.getTail(this._ahead[0].startPosition)
|
|
161
|
-
: this.input.getTail(this._lastFetchPosition);
|
|
162
|
-
}
|
|
163
|
-
/** Parsing template literals requires a context sensitive lexer.
|
|
164
|
-
* This method has to be called by the parser when the lexer needs to scan a string inside a template literal.
|
|
165
|
-
* Call this after the first opening backing and after the parser is done with parsing a placeholder, after the right brace.
|
|
166
|
-
*/
|
|
167
|
-
setStartingPhaseToTemplateLiteral() {
|
|
168
|
-
this._phaseExternallySet = LexerPhase.StringTemplateLiteral;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Fetches the next character from the input stream
|
|
172
|
-
*/
|
|
173
|
-
fetchNextChar() {
|
|
174
|
-
if (!this._prefetched) {
|
|
175
|
-
this._prefetchedPos = this.input.position;
|
|
176
|
-
this._prefetchedColumn = this.input.column;
|
|
177
|
-
this._prefetched = this.input.get();
|
|
178
|
-
}
|
|
179
|
-
return this._prefetched;
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Fetches the next token from the input stream
|
|
183
|
-
*/
|
|
184
|
-
fetch() {
|
|
185
|
-
// --- Captured constants used in nested functions
|
|
186
|
-
const lexer = this;
|
|
187
|
-
const input = this.input;
|
|
188
|
-
const startPos = this._prefetchedPos || input.position;
|
|
189
|
-
const line = input.line;
|
|
190
|
-
const startColumn = this._prefetchedColumn || input.column;
|
|
191
|
-
this._lastFetchPosition = this.input.position;
|
|
192
|
-
// --- State variables
|
|
193
|
-
let stringState = null;
|
|
194
|
-
let text = "";
|
|
195
|
-
let tokenType = TokenType_1.TokenType.Eof;
|
|
196
|
-
let lastEndPos = input.position;
|
|
197
|
-
let lastEndColumn = input.column;
|
|
198
|
-
let ch = null;
|
|
199
|
-
let useResolver = false;
|
|
200
|
-
// --- Start from the beginning
|
|
201
|
-
let phase = this.getStartingPhaseThenReset();
|
|
202
|
-
// --- Process all token characters
|
|
203
|
-
while (true) {
|
|
204
|
-
// --- Get the next character
|
|
205
|
-
ch = this.fetchNextChar();
|
|
206
|
-
// --- In case of EOF, return the current token data
|
|
207
|
-
if (ch === null) {
|
|
208
|
-
return makeToken();
|
|
209
|
-
}
|
|
210
|
-
// --- Set the initial token type to unknown for the other characters
|
|
211
|
-
if (tokenType === TokenType_1.TokenType.Eof) {
|
|
212
|
-
tokenType = TokenType_1.TokenType.Unknown;
|
|
213
|
-
}
|
|
214
|
-
// --- Follow the lexer state machine
|
|
215
|
-
phaseSwitch: switch (phase) {
|
|
216
|
-
// ====================================================================
|
|
217
|
-
// Process the first character
|
|
218
|
-
case LexerPhase.Start:
|
|
219
|
-
switch (ch) {
|
|
220
|
-
// --- Go on with whitespaces
|
|
221
|
-
case " ":
|
|
222
|
-
case "\t":
|
|
223
|
-
case "\n":
|
|
224
|
-
case "\r":
|
|
225
|
-
phase = LexerPhase.InWhiteSpace;
|
|
226
|
-
tokenType = TokenType_1.TokenType.Ws;
|
|
227
|
-
break;
|
|
228
|
-
// --- Divide, BlockComment, or EolComment
|
|
229
|
-
case "/":
|
|
230
|
-
phase = LexerPhase.Slash;
|
|
231
|
-
tokenType = TokenType_1.TokenType.Divide;
|
|
232
|
-
break;
|
|
233
|
-
case "$":
|
|
234
|
-
phase = LexerPhase.Dollar;
|
|
235
|
-
tokenType = TokenType_1.TokenType.Identifier;
|
|
236
|
-
break;
|
|
237
|
-
case "*":
|
|
238
|
-
phase = LexerPhase.Asterisk;
|
|
239
|
-
tokenType = TokenType_1.TokenType.Multiply;
|
|
240
|
-
break;
|
|
241
|
-
case "%":
|
|
242
|
-
phase = LexerPhase.Remainder;
|
|
243
|
-
tokenType = TokenType_1.TokenType.Remainder;
|
|
244
|
-
break;
|
|
245
|
-
case "+":
|
|
246
|
-
phase = LexerPhase.Plus;
|
|
247
|
-
tokenType = TokenType_1.TokenType.Plus;
|
|
248
|
-
break;
|
|
249
|
-
case "-":
|
|
250
|
-
phase = LexerPhase.Minus;
|
|
251
|
-
tokenType = TokenType_1.TokenType.Minus;
|
|
252
|
-
break;
|
|
253
|
-
case "^":
|
|
254
|
-
phase = LexerPhase.BitwiseXor;
|
|
255
|
-
tokenType = TokenType_1.TokenType.BitwiseXor;
|
|
256
|
-
break;
|
|
257
|
-
// --- BitwiseOr, LogicalOr
|
|
258
|
-
case "|":
|
|
259
|
-
phase = LexerPhase.Or;
|
|
260
|
-
tokenType = TokenType_1.TokenType.BitwiseOr;
|
|
261
|
-
break;
|
|
262
|
-
// --- BitwiseAnd, LogicalAnd
|
|
263
|
-
case "&":
|
|
264
|
-
phase = LexerPhase.Ampersand;
|
|
265
|
-
tokenType = TokenType_1.TokenType.BitwiseAnd;
|
|
266
|
-
break;
|
|
267
|
-
// --- "?", "?", or "?."
|
|
268
|
-
case "?":
|
|
269
|
-
phase = LexerPhase.QuestionMark;
|
|
270
|
-
tokenType = TokenType_1.TokenType.QuestionMark;
|
|
271
|
-
break;
|
|
272
|
-
case ";":
|
|
273
|
-
return completeToken(TokenType_1.TokenType.Semicolon);
|
|
274
|
-
case ",":
|
|
275
|
-
return completeToken(TokenType_1.TokenType.Comma);
|
|
276
|
-
case "(":
|
|
277
|
-
return completeToken(TokenType_1.TokenType.LParent);
|
|
278
|
-
case ")":
|
|
279
|
-
return completeToken(TokenType_1.TokenType.RParent);
|
|
280
|
-
// --- ":" or "::"
|
|
281
|
-
case ":":
|
|
282
|
-
phase = LexerPhase.Colon;
|
|
283
|
-
tokenType = TokenType_1.TokenType.Colon;
|
|
284
|
-
break;
|
|
285
|
-
case "`":
|
|
286
|
-
return completeToken(TokenType_1.TokenType.Backtick);
|
|
287
|
-
case "[":
|
|
288
|
-
return completeToken(TokenType_1.TokenType.LSquare);
|
|
289
|
-
case "]":
|
|
290
|
-
return completeToken(TokenType_1.TokenType.RSquare);
|
|
291
|
-
case "~":
|
|
292
|
-
return completeToken(TokenType_1.TokenType.BinaryNot);
|
|
293
|
-
case "{":
|
|
294
|
-
return completeToken(TokenType_1.TokenType.LBrace);
|
|
295
|
-
case "}":
|
|
296
|
-
return completeToken(TokenType_1.TokenType.RBrace);
|
|
297
|
-
// --- "=","==", "===", or "=>"
|
|
298
|
-
case "=":
|
|
299
|
-
phase = LexerPhase.Equal;
|
|
300
|
-
tokenType = TokenType_1.TokenType.Assignment;
|
|
301
|
-
break;
|
|
302
|
-
// --- "!", "!=", or "!=="
|
|
303
|
-
case "!":
|
|
304
|
-
phase = LexerPhase.Exclamation;
|
|
305
|
-
tokenType = TokenType_1.TokenType.LogicalNot;
|
|
306
|
-
break;
|
|
307
|
-
// --- "<", "<=", or "<<"
|
|
308
|
-
case "<":
|
|
309
|
-
phase = LexerPhase.AngleLeft;
|
|
310
|
-
tokenType = TokenType_1.TokenType.LessThan;
|
|
311
|
-
break;
|
|
312
|
-
// --- ">", ">=", ">>", or ">>>"
|
|
313
|
-
case ">":
|
|
314
|
-
phase = LexerPhase.AngleRight;
|
|
315
|
-
tokenType = TokenType_1.TokenType.GreaterThan;
|
|
316
|
-
break;
|
|
317
|
-
// --- Decimal or Real literal
|
|
318
|
-
case "0":
|
|
319
|
-
phase = LexerPhase.Zero;
|
|
320
|
-
tokenType = TokenType_1.TokenType.DecimalLiteral;
|
|
321
|
-
break;
|
|
322
|
-
case ".":
|
|
323
|
-
phase = LexerPhase.Dot;
|
|
324
|
-
tokenType = TokenType_1.TokenType.Dot;
|
|
325
|
-
break;
|
|
326
|
-
// --- String (both " and ' are accepted as string wrappers
|
|
327
|
-
case '"':
|
|
328
|
-
case "'":
|
|
329
|
-
stringState = ch;
|
|
330
|
-
phase = LexerPhase.String;
|
|
331
|
-
break;
|
|
332
|
-
default:
|
|
333
|
-
if (isIdStart(ch)) {
|
|
334
|
-
useResolver = true;
|
|
335
|
-
phase = LexerPhase.IdTail;
|
|
336
|
-
tokenType = TokenType_1.TokenType.Identifier;
|
|
337
|
-
}
|
|
338
|
-
else if (isDecimalDigit(ch)) {
|
|
339
|
-
phase = LexerPhase.DecimalOrReal;
|
|
340
|
-
tokenType = TokenType_1.TokenType.DecimalLiteral;
|
|
341
|
-
}
|
|
342
|
-
else {
|
|
343
|
-
completeToken(TokenType_1.TokenType.Unknown);
|
|
344
|
-
}
|
|
345
|
-
break;
|
|
346
|
-
}
|
|
347
|
-
break;
|
|
348
|
-
// ====================================================================
|
|
349
|
-
// Process comments
|
|
350
|
-
// --- Looking for the end of whitespace
|
|
351
|
-
case LexerPhase.InWhiteSpace:
|
|
352
|
-
if (ch !== " " && ch !== "\t" && ch !== "\r" && ch !== "\n") {
|
|
353
|
-
return makeToken();
|
|
354
|
-
}
|
|
355
|
-
break;
|
|
356
|
-
// --- Wait for an "*" that may complete a block comment
|
|
357
|
-
case LexerPhase.BlockCommentTrail1:
|
|
358
|
-
if (ch === "*") {
|
|
359
|
-
phase = LexerPhase.BlockCommentTrail2;
|
|
360
|
-
}
|
|
361
|
-
break;
|
|
362
|
-
// --- Wait for a "/" that may complete a block comment
|
|
363
|
-
case LexerPhase.BlockCommentTrail2:
|
|
364
|
-
if (ch === "/") {
|
|
365
|
-
return completeToken(TokenType_1.TokenType.BlockComment);
|
|
366
|
-
}
|
|
367
|
-
break;
|
|
368
|
-
case LexerPhase.InlineCommentTrail:
|
|
369
|
-
if (ch === "\n") {
|
|
370
|
-
return completeToken();
|
|
371
|
-
}
|
|
372
|
-
break;
|
|
373
|
-
// ====================================================================
|
|
374
|
-
// Process identifiers
|
|
375
|
-
case LexerPhase.IdTail:
|
|
376
|
-
if (!isIdContinuation(ch)) {
|
|
377
|
-
return makeToken();
|
|
378
|
-
}
|
|
379
|
-
break;
|
|
380
|
-
// ====================================================================
|
|
381
|
-
// Process miscellaneous tokens
|
|
382
|
-
case LexerPhase.Colon:
|
|
383
|
-
return ch === ":" ? completeToken(TokenType_1.TokenType.Global) : makeToken();
|
|
384
|
-
case LexerPhase.Slash:
|
|
385
|
-
if (ch === "*") {
|
|
386
|
-
phase = LexerPhase.BlockCommentTrail1;
|
|
387
|
-
}
|
|
388
|
-
else if (ch === "/") {
|
|
389
|
-
phase = LexerPhase.InlineCommentTrail;
|
|
390
|
-
tokenType = TokenType_1.TokenType.EolComment;
|
|
391
|
-
}
|
|
392
|
-
else if (ch === "=") {
|
|
393
|
-
return completeToken(TokenType_1.TokenType.DivideAssignment);
|
|
394
|
-
}
|
|
395
|
-
else {
|
|
396
|
-
return makeToken();
|
|
397
|
-
}
|
|
398
|
-
break;
|
|
399
|
-
case LexerPhase.Plus:
|
|
400
|
-
if (ch === "+") {
|
|
401
|
-
return completeToken(TokenType_1.TokenType.IncOp);
|
|
402
|
-
}
|
|
403
|
-
return ch === "=" ? completeToken(TokenType_1.TokenType.AddAssignment) : makeToken();
|
|
404
|
-
case LexerPhase.Minus:
|
|
405
|
-
if (ch === "-") {
|
|
406
|
-
return completeToken(TokenType_1.TokenType.DecOp);
|
|
407
|
-
}
|
|
408
|
-
return ch === "=" ? completeToken(TokenType_1.TokenType.SubtractAssignment) : makeToken();
|
|
409
|
-
case LexerPhase.Remainder:
|
|
410
|
-
return ch === "=" ? completeToken(TokenType_1.TokenType.RemainderAssignment) : makeToken();
|
|
411
|
-
case LexerPhase.BitwiseXor:
|
|
412
|
-
return ch === "=" ? completeToken(TokenType_1.TokenType.BitwiseXorAssignment) : makeToken();
|
|
413
|
-
case LexerPhase.Or:
|
|
414
|
-
if (ch === "=") {
|
|
415
|
-
return completeToken(TokenType_1.TokenType.BitwiseOrAssignment);
|
|
416
|
-
}
|
|
417
|
-
if (ch === "|") {
|
|
418
|
-
phase = LexerPhase.LogicalOr;
|
|
419
|
-
tokenType = TokenType_1.TokenType.LogicalOr;
|
|
420
|
-
break;
|
|
421
|
-
}
|
|
422
|
-
return makeToken();
|
|
423
|
-
case LexerPhase.LogicalOr:
|
|
424
|
-
return ch === "=" ? completeToken(TokenType_1.TokenType.LogicalOrAssignment) : makeToken();
|
|
425
|
-
case LexerPhase.Ampersand:
|
|
426
|
-
if (ch === "=") {
|
|
427
|
-
return completeToken(TokenType_1.TokenType.BitwiseAndAssignment);
|
|
428
|
-
}
|
|
429
|
-
if (ch === "&") {
|
|
430
|
-
phase = LexerPhase.LogicalAnd;
|
|
431
|
-
tokenType = TokenType_1.TokenType.LogicalAnd;
|
|
432
|
-
break;
|
|
433
|
-
}
|
|
434
|
-
return makeToken();
|
|
435
|
-
case LexerPhase.LogicalAnd:
|
|
436
|
-
return ch === "=" ? completeToken(TokenType_1.TokenType.LogicalAndAssignment) : makeToken();
|
|
437
|
-
case LexerPhase.Asterisk:
|
|
438
|
-
if (ch === "*") {
|
|
439
|
-
phase = LexerPhase.Exponent;
|
|
440
|
-
tokenType = TokenType_1.TokenType.Exponent;
|
|
441
|
-
break;
|
|
442
|
-
}
|
|
443
|
-
else if (ch === "=") {
|
|
444
|
-
return completeToken(TokenType_1.TokenType.MultiplyAssignment);
|
|
445
|
-
}
|
|
446
|
-
return makeToken();
|
|
447
|
-
case LexerPhase.Exponent:
|
|
448
|
-
return ch === "=" ? completeToken(TokenType_1.TokenType.ExponentAssignment) : makeToken();
|
|
449
|
-
case LexerPhase.QuestionMark:
|
|
450
|
-
if (ch === "?") {
|
|
451
|
-
phase = LexerPhase.NullCoalesce;
|
|
452
|
-
tokenType = TokenType_1.TokenType.NullCoalesce;
|
|
453
|
-
break;
|
|
454
|
-
}
|
|
455
|
-
if (ch === ".") {
|
|
456
|
-
return completeToken(TokenType_1.TokenType.OptionalChaining);
|
|
457
|
-
}
|
|
458
|
-
return makeToken();
|
|
459
|
-
case LexerPhase.NullCoalesce:
|
|
460
|
-
return ch === "=" ? completeToken(TokenType_1.TokenType.NullCoalesceAssignment) : makeToken();
|
|
461
|
-
case LexerPhase.Equal:
|
|
462
|
-
if (ch === ">") {
|
|
463
|
-
return completeToken(TokenType_1.TokenType.Arrow);
|
|
464
|
-
}
|
|
465
|
-
if (ch === "=") {
|
|
466
|
-
phase = LexerPhase.DoubleEqual;
|
|
467
|
-
tokenType = TokenType_1.TokenType.Equal;
|
|
468
|
-
break;
|
|
469
|
-
}
|
|
470
|
-
return makeToken();
|
|
471
|
-
case LexerPhase.DoubleEqual:
|
|
472
|
-
return ch === "=" ? completeToken(TokenType_1.TokenType.StrictEqual) : makeToken();
|
|
473
|
-
case LexerPhase.Exclamation:
|
|
474
|
-
if (ch === "=") {
|
|
475
|
-
phase = LexerPhase.NotEqual;
|
|
476
|
-
tokenType = TokenType_1.TokenType.NotEqual;
|
|
477
|
-
break;
|
|
478
|
-
}
|
|
479
|
-
return makeToken();
|
|
480
|
-
case LexerPhase.NotEqual:
|
|
481
|
-
return ch === "=" ? completeToken(TokenType_1.TokenType.StrictNotEqual) : makeToken();
|
|
482
|
-
case LexerPhase.AngleLeft:
|
|
483
|
-
if (ch === "=") {
|
|
484
|
-
return completeToken(TokenType_1.TokenType.LessThanOrEqual);
|
|
485
|
-
}
|
|
486
|
-
if (ch === "<") {
|
|
487
|
-
phase = LexerPhase.ShiftLeft;
|
|
488
|
-
tokenType = TokenType_1.TokenType.ShiftLeft;
|
|
489
|
-
break;
|
|
490
|
-
}
|
|
491
|
-
return makeToken();
|
|
492
|
-
case LexerPhase.ShiftLeft:
|
|
493
|
-
return ch === "=" ? completeToken(TokenType_1.TokenType.ShiftLeftAssignment) : makeToken();
|
|
494
|
-
case LexerPhase.AngleRight:
|
|
495
|
-
if (ch === "=") {
|
|
496
|
-
return completeToken(TokenType_1.TokenType.GreaterThanOrEqual);
|
|
497
|
-
}
|
|
498
|
-
if (ch === ">") {
|
|
499
|
-
phase = LexerPhase.SignedShiftRight;
|
|
500
|
-
tokenType = TokenType_1.TokenType.SignedShiftRight;
|
|
501
|
-
break;
|
|
502
|
-
}
|
|
503
|
-
return makeToken();
|
|
504
|
-
case LexerPhase.SignedShiftRight:
|
|
505
|
-
if (ch === ">") {
|
|
506
|
-
phase = LexerPhase.ShiftRight;
|
|
507
|
-
tokenType = TokenType_1.TokenType.ShiftRight;
|
|
508
|
-
break;
|
|
509
|
-
}
|
|
510
|
-
if (ch === "=") {
|
|
511
|
-
return completeToken(TokenType_1.TokenType.SignedShiftRightAssignment);
|
|
512
|
-
}
|
|
513
|
-
return makeToken();
|
|
514
|
-
case LexerPhase.ShiftRight:
|
|
515
|
-
return ch === "=" ? completeToken(TokenType_1.TokenType.ShiftRightAssignment) : makeToken();
|
|
516
|
-
// ====================================================================
|
|
517
|
-
// --- Literals
|
|
518
|
-
case LexerPhase.Zero:
|
|
519
|
-
if (ch === "x") {
|
|
520
|
-
phase = LexerPhase.HexaFirst;
|
|
521
|
-
tokenType = TokenType_1.TokenType.Unknown;
|
|
522
|
-
}
|
|
523
|
-
else if (ch === "b") {
|
|
524
|
-
phase = LexerPhase.BinaryFirst;
|
|
525
|
-
tokenType = TokenType_1.TokenType.Unknown;
|
|
526
|
-
}
|
|
527
|
-
else if (isDecimalDigit(ch) || ch === "_") {
|
|
528
|
-
phase = LexerPhase.DecimalOrReal;
|
|
529
|
-
}
|
|
530
|
-
else if (ch === ".") {
|
|
531
|
-
phase = LexerPhase.RealFractionalFirst;
|
|
532
|
-
tokenType = TokenType_1.TokenType.Unknown;
|
|
533
|
-
}
|
|
534
|
-
else if (ch === "e" || ch === "E") {
|
|
535
|
-
phase = LexerPhase.RealExponent;
|
|
536
|
-
tokenType = TokenType_1.TokenType.Unknown;
|
|
537
|
-
}
|
|
538
|
-
else {
|
|
539
|
-
return makeToken();
|
|
540
|
-
}
|
|
541
|
-
break;
|
|
542
|
-
case LexerPhase.Dot:
|
|
543
|
-
if (ch === ".") {
|
|
544
|
-
phase = LexerPhase.DotDot;
|
|
545
|
-
tokenType = TokenType_1.TokenType.Unknown;
|
|
546
|
-
break;
|
|
547
|
-
}
|
|
548
|
-
if (!isDecimalDigit(ch)) {
|
|
549
|
-
return makeToken();
|
|
550
|
-
}
|
|
551
|
-
phase = LexerPhase.RealFractionalTail;
|
|
552
|
-
tokenType = TokenType_1.TokenType.RealLiteral;
|
|
553
|
-
break;
|
|
554
|
-
case LexerPhase.DotDot:
|
|
555
|
-
return ch === "." ? completeToken(TokenType_1.TokenType.Spread) : makeToken();
|
|
556
|
-
case LexerPhase.HexaFirst:
|
|
557
|
-
if (ch === "_") {
|
|
558
|
-
break;
|
|
559
|
-
}
|
|
560
|
-
if (!isHexadecimalDigit(ch)) {
|
|
561
|
-
return makeToken();
|
|
562
|
-
}
|
|
563
|
-
phase = LexerPhase.HexaTail;
|
|
564
|
-
tokenType = TokenType_1.TokenType.HexadecimalLiteral;
|
|
565
|
-
break;
|
|
566
|
-
case LexerPhase.HexaTail:
|
|
567
|
-
if (!isHexadecimalDigit(ch) && ch !== "_") {
|
|
568
|
-
return makeToken();
|
|
569
|
-
}
|
|
570
|
-
break;
|
|
571
|
-
case LexerPhase.BinaryFirst:
|
|
572
|
-
if (ch === "_") {
|
|
573
|
-
break;
|
|
574
|
-
}
|
|
575
|
-
if (!isBinaryDigit(ch)) {
|
|
576
|
-
return makeToken();
|
|
577
|
-
}
|
|
578
|
-
phase = LexerPhase.BinaryTail;
|
|
579
|
-
tokenType = TokenType_1.TokenType.BinaryLiteral;
|
|
580
|
-
break;
|
|
581
|
-
case LexerPhase.BinaryTail:
|
|
582
|
-
if (!isBinaryDigit(ch) && ch !== "_") {
|
|
583
|
-
return makeToken();
|
|
584
|
-
}
|
|
585
|
-
tokenType = TokenType_1.TokenType.BinaryLiteral;
|
|
586
|
-
break;
|
|
587
|
-
case LexerPhase.DecimalOrReal:
|
|
588
|
-
if (isDecimalDigit(ch) || ch === "_") {
|
|
589
|
-
break;
|
|
590
|
-
}
|
|
591
|
-
else if (ch === "." && (this.input.peek() === null || isDecimalDigit(this.input.peek()))) {
|
|
592
|
-
phase = LexerPhase.RealFractionalFirst;
|
|
593
|
-
tokenType = TokenType_1.TokenType.Unknown;
|
|
594
|
-
}
|
|
595
|
-
else if (ch === "e" || ch === "E") {
|
|
596
|
-
phase = LexerPhase.RealExponent;
|
|
597
|
-
tokenType = TokenType_1.TokenType.Unknown;
|
|
598
|
-
}
|
|
599
|
-
else {
|
|
600
|
-
return makeToken();
|
|
601
|
-
}
|
|
602
|
-
break;
|
|
603
|
-
case LexerPhase.RealFractionalFirst:
|
|
604
|
-
if (isDecimalDigit(ch)) {
|
|
605
|
-
phase = LexerPhase.RealFractionalTail;
|
|
606
|
-
tokenType = TokenType_1.TokenType.RealLiteral;
|
|
607
|
-
}
|
|
608
|
-
else if (ch === "e" || ch === "E") {
|
|
609
|
-
phase = LexerPhase.RealExponent;
|
|
610
|
-
}
|
|
611
|
-
else {
|
|
612
|
-
return makeToken();
|
|
613
|
-
}
|
|
614
|
-
break;
|
|
615
|
-
case LexerPhase.RealFractionalTail:
|
|
616
|
-
if (ch === "e" || ch === "E") {
|
|
617
|
-
phase = LexerPhase.RealExponent;
|
|
618
|
-
tokenType = TokenType_1.TokenType.Unknown;
|
|
619
|
-
}
|
|
620
|
-
else if (!isDecimalDigit(ch) && ch !== "_") {
|
|
621
|
-
return makeToken();
|
|
622
|
-
}
|
|
623
|
-
break;
|
|
624
|
-
case LexerPhase.RealExponent:
|
|
625
|
-
if (ch === "+" || ch === "-") {
|
|
626
|
-
phase = LexerPhase.RealExponentSign;
|
|
627
|
-
}
|
|
628
|
-
else if (isDecimalDigit(ch)) {
|
|
629
|
-
phase = LexerPhase.RealExponentTail;
|
|
630
|
-
tokenType = TokenType_1.TokenType.RealLiteral;
|
|
631
|
-
}
|
|
632
|
-
else {
|
|
633
|
-
return makeToken();
|
|
634
|
-
}
|
|
635
|
-
break;
|
|
636
|
-
case LexerPhase.RealExponentSign:
|
|
637
|
-
if (isDecimalDigit(ch)) {
|
|
638
|
-
phase = LexerPhase.RealExponentTail;
|
|
639
|
-
tokenType = TokenType_1.TokenType.RealLiteral;
|
|
640
|
-
}
|
|
641
|
-
else {
|
|
642
|
-
return makeToken();
|
|
643
|
-
}
|
|
644
|
-
break;
|
|
645
|
-
case LexerPhase.RealExponentTail:
|
|
646
|
-
if (!isDecimalDigit(ch)) {
|
|
647
|
-
return makeToken();
|
|
648
|
-
}
|
|
649
|
-
break;
|
|
650
|
-
// A dollar sign is also a valid variable name. When it isn't a dollar left brace, we continue as if it was an identifier
|
|
651
|
-
case LexerPhase.Dollar:
|
|
652
|
-
if (ch === "{") {
|
|
653
|
-
return completeToken(TokenType_1.TokenType.DollarLBrace);
|
|
654
|
-
}
|
|
655
|
-
phase = LexerPhase.IdTail;
|
|
656
|
-
useResolver = true;
|
|
657
|
-
tokenType = TokenType_1.TokenType.Identifier;
|
|
658
|
-
if (!isIdContinuation(ch)) {
|
|
659
|
-
makeToken();
|
|
660
|
-
}
|
|
661
|
-
break;
|
|
662
|
-
case LexerPhase.StringTemplateLiteralBackSlash: {
|
|
663
|
-
phase = LexerPhase.StringTemplateLiteral;
|
|
664
|
-
const charAhead1 = this.input.ahead(0);
|
|
665
|
-
const charAhead2 = this.input.ahead(1);
|
|
666
|
-
if (charAhead1 === "`" || (charAhead1 === "$" && charAhead2 === "{")) {
|
|
667
|
-
return completeToken(TokenType_1.TokenType.StringLiteral);
|
|
668
|
-
}
|
|
669
|
-
break;
|
|
670
|
-
}
|
|
671
|
-
case LexerPhase.StringTemplateLiteral:
|
|
672
|
-
switch (ch) {
|
|
673
|
-
case "\\":
|
|
674
|
-
phase = LexerPhase.StringTemplateLiteralBackSlash;
|
|
675
|
-
tokenType = TokenType_1.TokenType.Unknown;
|
|
676
|
-
break phaseSwitch;
|
|
677
|
-
case "`":
|
|
678
|
-
return completeToken(TokenType_1.TokenType.Backtick);
|
|
679
|
-
case "$":
|
|
680
|
-
const charAhead = this.input.ahead(0);
|
|
681
|
-
if (charAhead === "{") {
|
|
682
|
-
appendTokenChar();
|
|
683
|
-
this.fetchNextChar();
|
|
684
|
-
return completeToken(TokenType_1.TokenType.DollarLBrace);
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
const charAhead1 = this.input.ahead(0);
|
|
688
|
-
const charAhead2 = this.input.ahead(1);
|
|
689
|
-
if (charAhead1 === "`" || (charAhead1 === "$" && charAhead2 === "{")) {
|
|
690
|
-
return completeToken(TokenType_1.TokenType.StringLiteral);
|
|
691
|
-
}
|
|
692
|
-
break;
|
|
693
|
-
case LexerPhase.String:
|
|
694
|
-
if (ch === stringState) {
|
|
695
|
-
return completeToken(TokenType_1.TokenType.StringLiteral);
|
|
696
|
-
}
|
|
697
|
-
else if (isRestrictedInString(ch)) {
|
|
698
|
-
return completeToken(TokenType_1.TokenType.Unknown);
|
|
699
|
-
}
|
|
700
|
-
else if (ch === "\\") {
|
|
701
|
-
phase = LexerPhase.StringBackSlash;
|
|
702
|
-
tokenType = TokenType_1.TokenType.Unknown;
|
|
703
|
-
}
|
|
704
|
-
break;
|
|
705
|
-
// Start of string character escape
|
|
706
|
-
case LexerPhase.StringBackSlash:
|
|
707
|
-
switch (ch) {
|
|
708
|
-
case "b":
|
|
709
|
-
case "f":
|
|
710
|
-
case "n":
|
|
711
|
-
case "r":
|
|
712
|
-
case "t":
|
|
713
|
-
case "v":
|
|
714
|
-
case "S":
|
|
715
|
-
case "0":
|
|
716
|
-
case "'":
|
|
717
|
-
case '"':
|
|
718
|
-
case "`":
|
|
719
|
-
case "\\":
|
|
720
|
-
phase = LexerPhase.String;
|
|
721
|
-
break;
|
|
722
|
-
case "x":
|
|
723
|
-
phase = LexerPhase.StringHexa1;
|
|
724
|
-
break;
|
|
725
|
-
case "u":
|
|
726
|
-
phase = LexerPhase.StringUHexa1;
|
|
727
|
-
break;
|
|
728
|
-
default:
|
|
729
|
-
phase = LexerPhase.String;
|
|
730
|
-
break;
|
|
731
|
-
}
|
|
732
|
-
break;
|
|
733
|
-
// --- First hexadecimal digit of string character escape
|
|
734
|
-
case LexerPhase.StringHexa1:
|
|
735
|
-
if (isHexadecimalDigit(ch)) {
|
|
736
|
-
phase = LexerPhase.StringHexa2;
|
|
737
|
-
}
|
|
738
|
-
else {
|
|
739
|
-
return completeToken(TokenType_1.TokenType.Unknown);
|
|
740
|
-
}
|
|
741
|
-
break;
|
|
742
|
-
// --- Second hexadecimal digit of character escape
|
|
743
|
-
case LexerPhase.StringHexa2:
|
|
744
|
-
if (isHexadecimalDigit(ch)) {
|
|
745
|
-
phase = LexerPhase.String;
|
|
746
|
-
}
|
|
747
|
-
else {
|
|
748
|
-
return completeToken(TokenType_1.TokenType.Unknown);
|
|
749
|
-
}
|
|
750
|
-
break;
|
|
751
|
-
// --- First hexadecimal digit of Unicode string character escape
|
|
752
|
-
case LexerPhase.StringUHexa1:
|
|
753
|
-
if (ch === "{") {
|
|
754
|
-
phase = LexerPhase.StringUcp1;
|
|
755
|
-
break;
|
|
756
|
-
}
|
|
757
|
-
if (isHexadecimalDigit(ch)) {
|
|
758
|
-
phase = LexerPhase.StringUHexa2;
|
|
759
|
-
}
|
|
760
|
-
else {
|
|
761
|
-
return completeToken(TokenType_1.TokenType.Unknown);
|
|
762
|
-
}
|
|
763
|
-
break;
|
|
764
|
-
// --- Second hexadecimal digit of Unicode string character escape
|
|
765
|
-
case LexerPhase.StringUHexa2:
|
|
766
|
-
if (isHexadecimalDigit(ch)) {
|
|
767
|
-
phase = LexerPhase.StringUHexa3;
|
|
768
|
-
}
|
|
769
|
-
else {
|
|
770
|
-
return completeToken(TokenType_1.TokenType.Unknown);
|
|
771
|
-
}
|
|
772
|
-
break;
|
|
773
|
-
// --- Third hexadecimal digit of Unicode string character escape
|
|
774
|
-
case LexerPhase.StringUHexa3:
|
|
775
|
-
if (isHexadecimalDigit(ch)) {
|
|
776
|
-
phase = LexerPhase.StringUHexa4;
|
|
777
|
-
}
|
|
778
|
-
else {
|
|
779
|
-
return completeToken(TokenType_1.TokenType.Unknown);
|
|
780
|
-
}
|
|
781
|
-
break;
|
|
782
|
-
// --- Fourth hexadecimal digit of Unicode string character escape
|
|
783
|
-
case LexerPhase.StringUHexa4:
|
|
784
|
-
if (isHexadecimalDigit(ch)) {
|
|
785
|
-
phase = LexerPhase.String;
|
|
786
|
-
}
|
|
787
|
-
else {
|
|
788
|
-
return completeToken(TokenType_1.TokenType.Unknown);
|
|
789
|
-
}
|
|
790
|
-
break;
|
|
791
|
-
// --- First hexadecimal digit of Unicode codepoint string character escape
|
|
792
|
-
case LexerPhase.StringUcp1:
|
|
793
|
-
if (isHexadecimalDigit(ch)) {
|
|
794
|
-
phase = LexerPhase.StringUcp2;
|
|
795
|
-
}
|
|
796
|
-
else {
|
|
797
|
-
return completeToken(TokenType_1.TokenType.Unknown);
|
|
798
|
-
}
|
|
799
|
-
break;
|
|
800
|
-
// --- Second hexadecimal digit of Unicode codepoint string character escape
|
|
801
|
-
case LexerPhase.StringUcp2:
|
|
802
|
-
if (ch === "}") {
|
|
803
|
-
phase = LexerPhase.String;
|
|
804
|
-
}
|
|
805
|
-
else if (isHexadecimalDigit(ch)) {
|
|
806
|
-
phase = LexerPhase.StringUcp3;
|
|
807
|
-
}
|
|
808
|
-
else {
|
|
809
|
-
return completeToken(TokenType_1.TokenType.Unknown);
|
|
810
|
-
}
|
|
811
|
-
break;
|
|
812
|
-
// --- Third hexadecimal digit of Unicode codepoint string character escape
|
|
813
|
-
case LexerPhase.StringUcp3:
|
|
814
|
-
if (ch === "}") {
|
|
815
|
-
phase = LexerPhase.String;
|
|
816
|
-
}
|
|
817
|
-
else if (isHexadecimalDigit(ch)) {
|
|
818
|
-
phase = LexerPhase.StringUcp4;
|
|
819
|
-
}
|
|
820
|
-
else {
|
|
821
|
-
return completeToken(TokenType_1.TokenType.Unknown);
|
|
822
|
-
}
|
|
823
|
-
break;
|
|
824
|
-
// --- Fourth hexadecimal digit of Unicode codepoint string character escape
|
|
825
|
-
case LexerPhase.StringUcp4:
|
|
826
|
-
if (ch === "}") {
|
|
827
|
-
phase = LexerPhase.String;
|
|
828
|
-
}
|
|
829
|
-
else if (isHexadecimalDigit(ch)) {
|
|
830
|
-
phase = LexerPhase.StringUcp5;
|
|
831
|
-
}
|
|
832
|
-
else {
|
|
833
|
-
return completeToken(TokenType_1.TokenType.Unknown);
|
|
834
|
-
}
|
|
835
|
-
break;
|
|
836
|
-
// --- Fifth hexadecimal digit of Unicode codepoint string character escape
|
|
837
|
-
case LexerPhase.StringUcp5:
|
|
838
|
-
if (ch === "}") {
|
|
839
|
-
phase = LexerPhase.String;
|
|
840
|
-
}
|
|
841
|
-
else if (isHexadecimalDigit(ch)) {
|
|
842
|
-
phase = LexerPhase.StringUcp6;
|
|
843
|
-
}
|
|
844
|
-
else {
|
|
845
|
-
return completeToken(TokenType_1.TokenType.Unknown);
|
|
846
|
-
}
|
|
847
|
-
break;
|
|
848
|
-
// --- Sixth hexadecimal digit of Unicode codepoint string character escape
|
|
849
|
-
case LexerPhase.StringUcp6:
|
|
850
|
-
if (ch === "}") {
|
|
851
|
-
phase = LexerPhase.String;
|
|
852
|
-
}
|
|
853
|
-
else if (isHexadecimalDigit(ch)) {
|
|
854
|
-
phase = LexerPhase.StringUcpTail;
|
|
855
|
-
}
|
|
856
|
-
else {
|
|
857
|
-
return completeToken(TokenType_1.TokenType.Unknown);
|
|
858
|
-
}
|
|
859
|
-
break;
|
|
860
|
-
// --- Closing bracket of Unicode codepoint string character escape
|
|
861
|
-
case LexerPhase.StringUcpTail:
|
|
862
|
-
if (ch === "}") {
|
|
863
|
-
phase = LexerPhase.String;
|
|
864
|
-
}
|
|
865
|
-
else {
|
|
866
|
-
return completeToken(TokenType_1.TokenType.Unknown);
|
|
867
|
-
}
|
|
868
|
-
break;
|
|
869
|
-
// ====================================================================
|
|
870
|
-
// --- We cannot continue
|
|
871
|
-
default:
|
|
872
|
-
return makeToken();
|
|
873
|
-
}
|
|
874
|
-
// --- Append the char to the current text
|
|
875
|
-
appendTokenChar();
|
|
876
|
-
// --- Go on with parsing the next character
|
|
877
|
-
}
|
|
878
|
-
/**
|
|
879
|
-
* Appends the last character to the token, and manages positions
|
|
880
|
-
*/
|
|
881
|
-
function appendTokenChar() {
|
|
882
|
-
text += ch;
|
|
883
|
-
lexer._prefetched = null;
|
|
884
|
-
lexer._prefetchedPos = null;
|
|
885
|
-
lexer._prefetchedColumn = null;
|
|
886
|
-
lastEndPos = input.position;
|
|
887
|
-
lastEndColumn = input.position;
|
|
888
|
-
}
|
|
889
|
-
/**
|
|
890
|
-
* Packs the specified type of token to send back
|
|
891
|
-
*/
|
|
892
|
-
function makeToken() {
|
|
893
|
-
var _a;
|
|
894
|
-
if (useResolver) {
|
|
895
|
-
tokenType =
|
|
896
|
-
(_a = resolverHash.get(text)) !== null && _a !== void 0 ? _a : (isIdStart(text[0]) && text[text.length - 1] !== "'" ? TokenType_1.TokenType.Identifier : TokenType_1.TokenType.Unknown);
|
|
897
|
-
}
|
|
898
|
-
return {
|
|
899
|
-
text,
|
|
900
|
-
type: tokenType,
|
|
901
|
-
startPosition: startPos,
|
|
902
|
-
endPosition: lastEndPos,
|
|
903
|
-
startLine: line,
|
|
904
|
-
endLine: line,
|
|
905
|
-
startColumn,
|
|
906
|
-
endColumn: lastEndColumn,
|
|
907
|
-
};
|
|
908
|
-
}
|
|
909
|
-
/**
|
|
910
|
-
* Add the last character to the token and return it
|
|
911
|
-
*/
|
|
912
|
-
function completeToken(suggestedType) {
|
|
913
|
-
appendTokenChar();
|
|
914
|
-
// --- Send back the token
|
|
915
|
-
if (suggestedType !== undefined) {
|
|
916
|
-
tokenType = suggestedType;
|
|
917
|
-
}
|
|
918
|
-
return makeToken();
|
|
919
|
-
}
|
|
920
|
-
}
|
|
921
|
-
getStartingPhaseThenReset() {
|
|
922
|
-
if (this._phaseExternallySet !== null) {
|
|
923
|
-
const phase = this._phaseExternallySet;
|
|
924
|
-
this._phaseExternallySet = null;
|
|
925
|
-
return phase;
|
|
926
|
-
}
|
|
927
|
-
return LexerPhase.Start;
|
|
928
|
-
}
|
|
929
|
-
/**
|
|
930
|
-
* Fetches the next RegEx token from the input stream
|
|
931
|
-
*/
|
|
932
|
-
fetchRegEx() {
|
|
933
|
-
// --- Get the tail
|
|
934
|
-
const tailPosition = this._ahead.length > 0 ? this._ahead[0].startPosition : this._lastFetchPosition;
|
|
935
|
-
const tail = this.input.getTail(tailPosition);
|
|
936
|
-
// --- Parse the tail. If no error, the entire tail is the RegExp
|
|
937
|
-
try {
|
|
938
|
-
const regexpResult = (0, regexpp_1.parseRegExpLiteral)(tail);
|
|
939
|
-
const text = regexpResult.raw;
|
|
940
|
-
// --- Consume the characters parsed successfully
|
|
941
|
-
for (let i = 1; i < text.length; i++) {
|
|
942
|
-
this.fetchNextChar();
|
|
943
|
-
this._prefetched = null;
|
|
944
|
-
this._prefetchedPos = null;
|
|
945
|
-
this._prefetchedColumn = null;
|
|
946
|
-
}
|
|
947
|
-
this._ahead.length = 0;
|
|
948
|
-
// --- Return the token
|
|
949
|
-
return {
|
|
950
|
-
success: true,
|
|
951
|
-
pattern: regexpResult.pattern.raw,
|
|
952
|
-
flags: regexpResult.flags.raw,
|
|
953
|
-
length: text.length,
|
|
954
|
-
};
|
|
955
|
-
}
|
|
956
|
-
catch (parseErr) {
|
|
957
|
-
let errorIndex = parseErr.index;
|
|
958
|
-
if (parseErr.toString().includes("Invalid flag")) {
|
|
959
|
-
while (errorIndex < tail.length && "dgimsuy".includes(tail[errorIndex])) {
|
|
960
|
-
errorIndex++;
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
// --- If there is no error, something is wrong
|
|
964
|
-
if (errorIndex === undefined) {
|
|
965
|
-
return {
|
|
966
|
-
success: false,
|
|
967
|
-
pattern: tail[0],
|
|
968
|
-
};
|
|
969
|
-
}
|
|
970
|
-
// --- Try to parse the tail before the error position
|
|
971
|
-
const tailBeforeError = tail.substring(0, errorIndex);
|
|
972
|
-
try {
|
|
973
|
-
const regexpResult = (0, regexpp_1.parseRegExpLiteral)(tailBeforeError);
|
|
974
|
-
const text = regexpResult.raw;
|
|
975
|
-
// --- Consume the characters parsed successfully
|
|
976
|
-
for (let i = 1; i < text.length; i++) {
|
|
977
|
-
this.fetchNextChar();
|
|
978
|
-
this._prefetched = null;
|
|
979
|
-
this._prefetchedPos = null;
|
|
980
|
-
this._prefetchedColumn = null;
|
|
981
|
-
}
|
|
982
|
-
this._ahead.length = 0;
|
|
983
|
-
// --- Return the token
|
|
984
|
-
return {
|
|
985
|
-
success: true,
|
|
986
|
-
pattern: regexpResult.pattern.raw,
|
|
987
|
-
flags: regexpResult.flags.raw,
|
|
988
|
-
length: text.length,
|
|
989
|
-
};
|
|
990
|
-
}
|
|
991
|
-
catch (parseErr2) {
|
|
992
|
-
// --- This is really not a regexp
|
|
993
|
-
return {
|
|
994
|
-
success: false,
|
|
995
|
-
pattern: tailBeforeError,
|
|
996
|
-
};
|
|
997
|
-
}
|
|
998
|
-
}
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
exports.Lexer = Lexer;
|
|
1002
|
-
/**
|
|
1003
|
-
* Reserved ID-like tokens
|
|
1004
|
-
*/
|
|
1005
|
-
const resolverHash = new Map();
|
|
1006
|
-
resolverHash.set("typeof", TokenType_1.TokenType.Typeof);
|
|
1007
|
-
resolverHash.set("Infinity", TokenType_1.TokenType.Infinity);
|
|
1008
|
-
resolverHash.set("NaN", TokenType_1.TokenType.NaN);
|
|
1009
|
-
resolverHash.set("true", TokenType_1.TokenType.True);
|
|
1010
|
-
resolverHash.set("false", TokenType_1.TokenType.False);
|
|
1011
|
-
resolverHash.set("undefined", TokenType_1.TokenType.Undefined);
|
|
1012
|
-
resolverHash.set("null", TokenType_1.TokenType.Null);
|
|
1013
|
-
resolverHash.set("in", TokenType_1.TokenType.In);
|
|
1014
|
-
resolverHash.set("let", TokenType_1.TokenType.Let);
|
|
1015
|
-
resolverHash.set("const", TokenType_1.TokenType.Const);
|
|
1016
|
-
resolverHash.set("var", TokenType_1.TokenType.Var);
|
|
1017
|
-
resolverHash.set("if", TokenType_1.TokenType.If);
|
|
1018
|
-
resolverHash.set("else", TokenType_1.TokenType.Else);
|
|
1019
|
-
resolverHash.set("return", TokenType_1.TokenType.Return);
|
|
1020
|
-
resolverHash.set("break", TokenType_1.TokenType.Break);
|
|
1021
|
-
resolverHash.set("continue", TokenType_1.TokenType.Continue);
|
|
1022
|
-
resolverHash.set("do", TokenType_1.TokenType.Do);
|
|
1023
|
-
resolverHash.set("while", TokenType_1.TokenType.While);
|
|
1024
|
-
resolverHash.set("for", TokenType_1.TokenType.For);
|
|
1025
|
-
resolverHash.set("of", TokenType_1.TokenType.Of);
|
|
1026
|
-
resolverHash.set("try", TokenType_1.TokenType.Try);
|
|
1027
|
-
resolverHash.set("catch", TokenType_1.TokenType.Catch);
|
|
1028
|
-
resolverHash.set("finally", TokenType_1.TokenType.Finally);
|
|
1029
|
-
resolverHash.set("throw", TokenType_1.TokenType.Throw);
|
|
1030
|
-
resolverHash.set("switch", TokenType_1.TokenType.Switch);
|
|
1031
|
-
resolverHash.set("case", TokenType_1.TokenType.Case);
|
|
1032
|
-
resolverHash.set("default", TokenType_1.TokenType.Default);
|
|
1033
|
-
resolverHash.set("delete", TokenType_1.TokenType.Delete);
|
|
1034
|
-
resolverHash.set("function", TokenType_1.TokenType.Function);
|
|
1035
|
-
resolverHash.set("as", TokenType_1.TokenType.As);
|
|
1036
|
-
resolverHash.set("from", TokenType_1.TokenType.From);
|
|
1037
|
-
/**
|
|
1038
|
-
* Tests if a token id EOF
|
|
1039
|
-
* @param t Token instance
|
|
1040
|
-
*/
|
|
1041
|
-
function isEof(t) {
|
|
1042
|
-
return t.type === TokenType_1.TokenType.Eof;
|
|
1043
|
-
}
|
|
1044
|
-
/**
|
|
1045
|
-
* Tests if a token is whitespace
|
|
1046
|
-
* @param t Token instance
|
|
1047
|
-
*/
|
|
1048
|
-
function isWs(t) {
|
|
1049
|
-
return t.type <= TokenType_1.TokenType.Ws;
|
|
1050
|
-
}
|
|
1051
|
-
/**
|
|
1052
|
-
* Tests if a character is an identifier start character
|
|
1053
|
-
* @param ch Character to test
|
|
1054
|
-
*/
|
|
1055
|
-
function isIdStart(ch) {
|
|
1056
|
-
return (ch >= "a" && ch <= "z") || (ch >= "A" && ch <= "Z") || ch === "_" || ch === "$";
|
|
1057
|
-
}
|
|
1058
|
-
/**
|
|
1059
|
-
* Tests if a character is an identifier continuation character
|
|
1060
|
-
* @param ch Character to test
|
|
1061
|
-
*/
|
|
1062
|
-
function isIdContinuation(ch) {
|
|
1063
|
-
return (ch >= "a" && ch <= "z") || (ch >= "A" && ch <= "Z") || (ch >= "0" && ch <= "9") || ch === "_" || ch === "$";
|
|
1064
|
-
}
|
|
1065
|
-
/**
|
|
1066
|
-
* Tests if a character is a binary digit
|
|
1067
|
-
* @param ch Character to test
|
|
1068
|
-
*/
|
|
1069
|
-
function isBinaryDigit(ch) {
|
|
1070
|
-
return ch === "0" || ch === "1";
|
|
1071
|
-
}
|
|
1072
|
-
/**
|
|
1073
|
-
* Tests if a character is a decimal digit
|
|
1074
|
-
* @param ch Character to test
|
|
1075
|
-
*/
|
|
1076
|
-
function isDecimalDigit(ch) {
|
|
1077
|
-
return ch >= "0" && ch <= "9";
|
|
1078
|
-
}
|
|
1079
|
-
/**
|
|
1080
|
-
* Tests if a character is a hexadecimal digit
|
|
1081
|
-
* @param ch Character to test
|
|
1082
|
-
*/
|
|
1083
|
-
function isHexadecimalDigit(ch) {
|
|
1084
|
-
return (ch >= "0" && ch <= "9") || (ch >= "A" && ch <= "F") || (ch >= "a" && ch <= "f");
|
|
1085
|
-
}
|
|
1086
|
-
/**
|
|
1087
|
-
* Tests if a character is restricted in a string
|
|
1088
|
-
* @param ch Character to test
|
|
1089
|
-
*/
|
|
1090
|
-
function isRestrictedInString(ch) {
|
|
1091
|
-
return ch === "\r" || ch === "\n" || ch === "\u0085" || ch === "\u2028" || ch === "\u2029";
|
|
1092
|
-
}
|