Coverage Report

Created: 2026-08-14 06:19

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/moddable/xs/sources/xsLexical.c
Line
Count
Source
1
/*
2
 * Copyright (c) 2016-2025  Moddable Tech, Inc.
3
 *
4
 *   This file is part of the Moddable SDK Runtime.
5
 * 
6
 *   The Moddable SDK Runtime is free software: you can redistribute it and/or modify
7
 *   it under the terms of the GNU Lesser General Public License as published by
8
 *   the Free Software Foundation, either version 3 of the License, or
9
 *   (at your option) any later version.
10
 * 
11
 *   The Moddable SDK Runtime is distributed in the hope that it will be useful,
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *   GNU Lesser General Public License for more details.
15
 * 
16
 *   You should have received a copy of the GNU Lesser General Public License
17
 *   along with the Moddable SDK Runtime.  If not, see <http://www.gnu.org/licenses/>.
18
 *
19
 * This file incorporates work covered by the following copyright and  
20
 * permission notice:  
21
 *
22
 *       Copyright (C) 2010-2016 Marvell International Ltd.
23
 *       Copyright (C) 2002-2010 Kinoma, Inc.
24
 *
25
 *       Licensed under the Apache License, Version 2.0 (the "License");
26
 *       you may not use this file except in compliance with the License.
27
 *       You may obtain a copy of the License at
28
 *
29
 *        http://www.apache.org/licenses/LICENSE-2.0
30
 *
31
 *       Unless required by applicable law or agreed to in writing, software
32
 *       distributed under the License is distributed on an "AS IS" BASIS,
33
 *       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
34
 *       See the License for the specific language governing permissions and
35
 *       limitations under the License.
36
 */
37
38
#include "xsScript.h"
39
40
static txU4 fxGetNextCode(txParser* parser);
41
static txString fxGetNextDigits(txParser* parser, txString (*f)(txParser*, txString, txString), txString p, txString q, int empty);
42
static txString fxGetNextDigitsB(txParser* parser, txString p, txString q);
43
static txString fxGetNextDigitsD(txParser* parser, txString p, txString q, int* base);
44
static txString fxGetNextDigitsE(txParser* parser, txString p, txString q);
45
static txString fxGetNextDigitsO(txParser* parser, txString p, txString q);
46
static txString fxGetNextDigitsX(txParser* parser, txString p, txString q);
47
static void fxGetNextKeyword(txParser* parser);
48
static txBoolean fxGetNextIdentiferX(txParser* parser, txU4* value);
49
static void fxGetNextNumber(txParser* parser, txNumber theNumber);
50
static void fxGetNextNumberB(txParser* parser);
51
static void fxGetNextNumberE(txParser* parser, int parseDot);
52
static void fxGetNextNumberO(txParser* parser, int c, int i);
53
static void fxGetNextNumberX(txParser* parser);
54
static void fxGetNextString(txParser* parser, int c);
55
static txBoolean fxGetNextStringD(int c, txU4* value);
56
static txBoolean fxGetNextStringX(int c, txU4* value);
57
static void fxGetNextTokenAux(txParser* parser);
58
59
3.27M
#define XS_KEYWORD_COUNT 36
60
static const txKeyword ICACHE_RODATA_ATTR gxKeywords[XS_KEYWORD_COUNT] = {
61
  { "break", XS_TOKEN_BREAK },
62
  { "case", XS_TOKEN_CASE },
63
  { "catch", XS_TOKEN_CATCH },
64
  { "class", XS_TOKEN_CLASS },
65
  { "const", XS_TOKEN_CONST },
66
  { "continue", XS_TOKEN_CONTINUE },
67
  { "debugger", XS_TOKEN_DEBUGGER },
68
  { "default", XS_TOKEN_DEFAULT },
69
  { "delete", XS_TOKEN_DELETE },
70
  { "do", XS_TOKEN_DO },
71
  { "else", XS_TOKEN_ELSE },
72
  { "enum", XS_TOKEN_ENUM },
73
  { "export", XS_TOKEN_EXPORT },
74
  { "extends", XS_TOKEN_EXTENDS },
75
  { "false", XS_TOKEN_FALSE },
76
  { "finally", XS_TOKEN_FINALLY },
77
  { "for", XS_TOKEN_FOR },
78
  { "function", XS_TOKEN_FUNCTION },
79
  { "if", XS_TOKEN_IF },
80
  { "import", XS_TOKEN_IMPORT },
81
  { "in", XS_TOKEN_IN },
82
  { "instanceof", XS_TOKEN_INSTANCEOF },
83
  { "new", XS_TOKEN_NEW }, 
84
  { "null", XS_TOKEN_NULL }, 
85
  { "return", XS_TOKEN_RETURN },
86
  { "super", XS_TOKEN_SUPER },
87
  { "switch", XS_TOKEN_SWITCH },
88
  { "this", XS_TOKEN_THIS },
89
  { "throw", XS_TOKEN_THROW },
90
  { "true", XS_TOKEN_TRUE },
91
  { "try", XS_TOKEN_TRY },
92
  { "typeof", XS_TOKEN_TYPEOF },
93
  { "var", XS_TOKEN_VAR },
94
  { "void", XS_TOKEN_VOID },
95
  { "while", XS_TOKEN_WHILE },
96
  { "with", XS_TOKEN_WITH }
97
};
98
99
221k
#define XS_STRICT_KEYWORD_COUNT 9
100
static const txKeyword ICACHE_RODATA_ATTR gxStrictKeywords[XS_STRICT_KEYWORD_COUNT] = {
101
  { "implements", XS_TOKEN_IMPLEMENTS },
102
  { "interface", XS_TOKEN_INTERFACE },
103
  { "let", XS_TOKEN_LET },
104
  { "package", XS_TOKEN_PACKAGE },
105
  { "private", XS_TOKEN_PRIVATE },
106
  { "protected", XS_TOKEN_PROTECTED },
107
  { "public", XS_TOKEN_PUBLIC },
108
  { "static", XS_TOKEN_STATIC },
109
  { "yield", XS_TOKEN_YIELD }
110
};
111
112
static txString fxUTF8Buffer(txParser* parser, txInteger character, txString string, txString limit)
113
34.7M
{
114
34.7M
  if (string + mxStringByteLength(character) > limit) {
115
30
    fxReportMemoryError(parser, parser->states[2].line, "buffer overflow");
116
30
  }
117
34.7M
  return mxStringByteEncode(string, character);
118
34.7M
} 
119
120
void fxCheckStrictKeyword(txParser* parser)
121
6.47k
{
122
6.47k
  int low, high, anIndex, aDelta;
123
21.8k
  for (low = 0, high = XS_STRICT_KEYWORD_COUNT; high > low;
124
18.4k
      (aDelta < 0) ? (low = anIndex + 1) : (high = anIndex)) {
125
18.4k
    anIndex = low + ((high - low) / 2);
126
18.4k
    aDelta = c_strcmp(gxStrictKeywords[anIndex].text, parser->buffer);
127
18.4k
    if (aDelta == 0) {
128
3.06k
      parser->states[0].token = gxStrictKeywords[anIndex].token;
129
3.06k
      goto bail;
130
3.06k
    }
131
18.4k
  }
132
6.47k
bail:
133
6.47k
  if (parser->states[0].escaped)
134
0
    fxReportParserError(parser, parser->states[0].line, "escaped keyword");     
135
6.47k
}
136
137
void fxGetNextCharacter(txParser* parser)
138
108M
{
139
108M
  parser->character = parser->lookahead;
140
108M
  if (parser->character != (txU4)C_EOF) {
141
108M
  #if mxCESU8
142
108M
    txU4 character = parser->surrogate;
143
108M
    if (character)
144
491
      parser->surrogate = 0;
145
108M
    else
146
108M
      character = fxGetNextCode(parser);
147
108M
    if ((0x0000D800 <= character) && (character <= 0x0000DBFF)) {
148
75.4k
      txU4 surrogate = fxGetNextCode(parser);
149
75.4k
      if ((0x0000DC00 <= surrogate) && (surrogate <= 0x0000DFFF))
150
74.5k
        character = 0x00010000 + ((character & 0x000003FF) << 10) + (surrogate & 0x000003FF);
151
848
      else
152
848
        parser->surrogate = surrogate;
153
75.4k
    }
154
108M
    parser->lookahead = character;
155
  #else
156
    parser->lookahead = fxGetNextCode(parser);
157
  #endif
158
108M
  }
159
108M
}
160
161
txU4 fxGetNextCode(txParser* parser)
162
108M
{
163
108M
  txU4 code = (txU4)(*(parser->getter))(parser->stream);
164
108M
  if ((code & 0x80) && (code != (txU4)C_EOF)) {
165
12.4M
    txUTF8Sequence const *sequence = NULL;
166
32.8M
    for (sequence = gxUTF8Sequences; sequence->size; sequence++) {
167
32.8M
      if ((code & sequence->cmask) == sequence->cval)
168
12.4M
        break;
169
32.8M
    }
170
12.4M
    if (sequence->size == 0) {
171
0
      fxReportParserError(parser, parser->states[2].line, "invalid character %d", code);
172
0
      code = (txU4)C_EOF;
173
0
    }
174
12.4M
    else {
175
12.4M
      txS4 size = sequence->size - 1;
176
32.8M
      while (size) {
177
20.3M
        size--;
178
20.3M
        code = (code << 6) | ((*(parser->getter))(parser->stream) & 0x3F);
179
20.3M
      }
180
12.4M
      code &= sequence->lmask;
181
12.4M
    }
182
12.4M
    if (code == 0x000110000)
183
0
      code = 0;
184
12.4M
  }
185
108M
  return code;
186
108M
}
187
188
txString fxGetNextDigits(txParser* parser, txString (*f)(txParser*, txString, txString), txString p, txString q, int empty)
189
564k
{
190
564k
  int separator = 0;
191
570k
  for (;;) {
192
570k
    txString r = p;
193
570k
    p = (*f)(parser, p, q);
194
570k
    if (r < p) {
195
545k
      empty = 0;
196
545k
      separator = 0;
197
545k
      if (parser->character == '_') {
198
6.83k
        fxGetNextCharacter(parser);
199
6.83k
        separator = 1;
200
6.83k
      }
201
538k
      else
202
538k
        break;
203
545k
    }
204
25.1k
    else
205
25.1k
      break;
206
570k
  }
207
564k
  if (empty || separator)
208
9.36k
    fxReportParserError(parser, parser->states[2].line, "invalid number"); 
209
564k
  return p;
210
564k
}
211
212
txString fxGetNextDigitsB(txParser* parser, txString p, txString q)
213
5.16k
{
214
5.16k
  int c = parser->character;
215
10.8k
  while (('0' <= c) && (c <= '1')) {
216
5.65k
    if (p < q) *p++ = (char)c;
217
5.65k
    fxGetNextCharacter(parser);
218
5.65k
    c = parser->character;
219
5.65k
  }
220
5.16k
  return p;
221
5.16k
}
222
223
txString fxGetNextDigitsD(txParser* parser, txString p, txString q, int* base)
224
4.17k
{
225
4.17k
  int c = parser->character;
226
4.17k
  *base = 8;
227
133k
  while (('0' <= c) && (c <= '9')) {
228
129k
    if (p < q) *p++ = (char)c;
229
129k
    if (('8' <= c) && (c <= '9'))
230
6.56k
      *base = 10;
231
129k
    fxGetNextCharacter(parser);
232
129k
    c = parser->character;
233
129k
  }
234
4.17k
  return p;
235
4.17k
}
236
237
txString fxGetNextDigitsE(txParser* parser, txString p, txString q)
238
434k
{
239
434k
  int c = parser->character;
240
4.79M
  while (('0' <= c) && (c <= '9')) {
241
4.35M
    if (p < q) *p++ = (char)c;
242
4.35M
    fxGetNextCharacter(parser);
243
4.35M
    c = parser->character;
244
4.35M
  }
245
434k
  return p;
246
434k
}
247
248
txString fxGetNextDigitsO(txParser* parser, txString p, txString q)
249
3.23k
{
250
3.23k
  int c = parser->character;
251
7.05k
  while (('0' <= c) && (c <= '7')) {
252
3.82k
    if (p < q) *p++ = (char)c;
253
3.82k
    fxGetNextCharacter(parser);
254
3.82k
    c = parser->character;
255
3.82k
  }
256
3.23k
  return p;
257
3.23k
}
258
259
txString fxGetNextDigitsX(txParser* parser, txString p, txString q)
260
127k
{
261
127k
  int c = parser->character;
262
899k
  while ((('0' <= c) && (c <= '9')) || (('a' <= c) && (c <= 'f')) || (('A' <= c) && (c <= 'F'))) {
263
771k
    if (p < q) *p++ = (char)c;
264
771k
    fxGetNextCharacter(parser);
265
771k
    c = parser->character;
266
771k
  }
267
127k
  return p;
268
127k
}
269
270
void fxGetNextKeyword(txParser* parser)
271
3.67M
{
272
3.67M
  int low, high, anIndex, aDelta;
273
  
274
3.67M
  parser->states[2].symbol = fxNewParserSymbol(parser, parser->buffer);
275
3.67M
  parser->states[2].token = XS_TOKEN_IDENTIFIER;
276
3.67M
  if ((parser->states[0].token == XS_TOKEN_DOT) || (parser->states[0].token == XS_TOKEN_CHAIN))
277
405k
    return;
278
19.5M
  for (low = 0, high = XS_KEYWORD_COUNT; high > low;
279
17.0M
      (aDelta < 0) ? (low = anIndex + 1) : (high = anIndex)) {
280
17.0M
    anIndex = low + ((high - low) / 2);
281
17.0M
    aDelta = c_strcmp(gxKeywords[anIndex].text, parser->buffer);
282
17.0M
    if (aDelta == 0) {
283
765k
      parser->states[2].token = gxKeywords[anIndex].token;
284
765k
      return;
285
765k
    }
286
17.0M
  }
287
2.50M
  if ((parser->flags & mxStrictFlag)) {
288
810k
    for (low = 0, high = XS_STRICT_KEYWORD_COUNT; high > low;
289
670k
        (aDelta < 0) ? (low = anIndex + 1) : (high = anIndex)) {
290
670k
      anIndex = low + ((high - low) / 2);
291
670k
      aDelta = c_strcmp(gxStrictKeywords[anIndex].text, parser->buffer);
292
670k
      if (aDelta == 0) {
293
74.8k
        parser->states[2].token = gxStrictKeywords[anIndex].token;
294
74.8k
        return;
295
74.8k
      }
296
670k
    }
297
215k
  }
298
2.43M
  if (c_strcmp("await", parser->buffer) == 0) {
299
1.95k
    if (parser->flags & mxAsyncFlag) {
300
1.30k
      parser->states[2].token = XS_TOKEN_AWAIT;
301
1.30k
      return;
302
1.30k
    }
303
1.95k
  }  
304
2.43M
  if (c_strcmp("yield", parser->buffer) == 0) {
305
42.6k
    if ((parser->flags & mxGeneratorFlag)){
306
31.0k
      parser->states[2].token = XS_TOKEN_YIELD;
307
31.0k
      return;
308
31.0k
    }
309
42.6k
  }  
310
2.39M
  return;
311
2.43M
}
312
313
txBoolean fxGetNextIdentiferX(txParser* parser, txU4* value)
314
8.84k
{
315
8.84k
  fxGetNextCharacter(parser);
316
8.84k
  if (parser->character == 'u') {
317
8.15k
    fxGetNextCharacter(parser);
318
8.15k
    if (parser->character == '{') {
319
825
      fxGetNextCharacter(parser);
320
3.07k
      while (fxGetNextStringX(parser->character, value)) {
321
2.24k
        fxGetNextCharacter(parser);
322
2.24k
      }
323
825
      if (parser->character == '}') {
324
223
        fxGetNextCharacter(parser);
325
223
        return 1;
326
223
      }
327
825
    }
328
7.32k
    else {
329
7.32k
      if (fxGetNextStringX(parser->character, value)) {
330
6.74k
        fxGetNextCharacter(parser);
331
6.74k
        if (fxGetNextStringX(parser->character, value)) {
332
4.12k
          fxGetNextCharacter(parser);
333
4.12k
          if (fxGetNextStringX(parser->character, value)) {
334
3.69k
            fxGetNextCharacter(parser);
335
3.69k
            if (fxGetNextStringX(parser->character, value)) {
336
1.64k
              fxGetNextCharacter(parser);
337
1.64k
              return 1;
338
1.64k
            }    
339
3.69k
          }    
340
4.12k
        }    
341
6.74k
      }    
342
7.32k
    }    
343
8.15k
  }
344
6.97k
  return 0;
345
8.84k
}
346
347
void fxGetNextNumber(txParser* parser, txNumber theNumber)
348
444k
{
349
444k
  parser->states[2].number = theNumber;
350
444k
  parser->states[2].integer = (txInteger)parser->states[2].number;
351
444k
  theNumber = parser->states[2].integer;
352
444k
  if (parser->states[2].number == theNumber)
353
405k
    parser->states[2].token = XS_TOKEN_INTEGER;
354
39.2k
  else
355
39.2k
    parser->states[2].token = XS_TOKEN_NUMBER;
356
444k
}
357
358
void fxGetNextNumberB(txParser* parser)
359
2.42k
{
360
2.42k
  txString p = parser->buffer;
361
2.42k
  txString q = p + parser->bufferSize;
362
2.42k
  int c;
363
2.42k
  fxGetNextCharacter(parser);
364
2.42k
  p = fxGetNextDigits(parser, fxGetNextDigitsB, p, q, 1);
365
2.42k
  c = parser->character;
366
2.42k
  if (p == q) {
367
0
    fxReportMemoryError(parser, parser->states[2].line, "number overflow");
368
0
  }
369
2.42k
  if (c == 'n')
370
24
    fxGetNextCharacter(parser);
371
2.42k
  if (fxIsIdentifierFirst(parser->character)) {
372
546
    fxReportParserError(parser, parser->states[2].line, "invalid number");
373
546
  }
374
2.42k
  *p = 0;
375
2.42k
  q = parser->buffer;
376
2.42k
  if (c == 'n') {
377
18
    parser->states[2].bigint.data = fxNewParserChunk(parser, fxBigIntMaximumB(mxPtrDiff(p - q)));
378
18
    fxBigIntParseB(&parser->states[2].bigint, q, mxPtrDiff(p - q));
379
18
    parser->states[2].token = XS_TOKEN_BIGINT;
380
18
  }
381
2.40k
  else {
382
2.40k
    txNumber n = 0;
383
3.98k
    while ((c = *q++))
384
1.57k
      n = (n * 2) + (c - '0');
385
2.40k
    fxGetNextNumber(parser, n);
386
2.40k
  }
387
2.42k
}
388
389
void fxGetNextNumberE(txParser* parser, int dot)
390
390k
{
391
390k
  txString p = parser->buffer;
392
390k
  txString q = p + parser->bufferSize;
393
390k
  txString r = NULL;
394
390k
  int c;
395
390k
  if (dot) {
396
16.0k
    if (p < q) *p++ = '.';
397
16.0k
  }
398
390k
  p = fxGetNextDigits(parser, fxGetNextDigitsE, p, q, 0); 
399
390k
  if (dot)
400
16.0k
    r = p;
401
374k
  else if (parser->character == '.') {
402
20.6k
    dot = 1;
403
20.6k
    if (p < q) *p++ = '.';
404
20.6k
    fxGetNextCharacter(parser);
405
20.6k
    p = fxGetNextDigits(parser, fxGetNextDigitsE, p, q, 0); 
406
20.6k
    r = p;
407
20.6k
  }
408
390k
  c = parser->character;
409
390k
  if ((c == 'e') || (c == 'E')) {
410
20.3k
    if (dot) {
411
12.0k
      if (p == r) {
412
12.0k
        if (p < q) *p++ = '0';
413
12.0k
      }
414
12.0k
    }
415
8.36k
    else {
416
8.36k
      dot = 1;
417
8.36k
      if (p < q) *p++ = '.';
418
8.36k
      if (p < q) *p++ = '0';
419
8.36k
    }
420
20.3k
    if (p < q) *p++ = (char)c;
421
20.3k
    fxGetNextCharacter(parser);
422
20.3k
    c = parser->character;
423
20.3k
    if ((c == '+') || (c == '-')) {
424
8.58k
      if (p < q) *p++ = (char)c;
425
8.58k
      fxGetNextCharacter(parser);
426
8.58k
      c = parser->character;
427
8.58k
    }
428
20.3k
    p = fxGetNextDigits(parser, fxGetNextDigitsE, p, q, 1);
429
20.3k
    c = parser->character;
430
20.3k
  }
431
390k
  if (p == q) {
432
8
    fxReportMemoryError(parser, parser->states[2].line, "number overflow");
433
8
  }
434
390k
  if (c == 'n')
435
67.2k
    fxGetNextCharacter(parser);
436
390k
  if (fxIsIdentifierFirst(parser->character)) {
437
3.54k
    fxReportParserError(parser, parser->states[2].line, "invalid number");
438
3.54k
  }
439
390k
  *p = 0;
440
390k
  q = parser->buffer;
441
390k
  if (c == 'n') {
442
66.8k
    if (dot == 0) {
443
65.5k
      parser->states[2].bigint.data = fxNewParserChunk(parser, fxBigIntMaximum(mxPtrDiff(p - q)));
444
65.5k
      fxBigIntParse(&parser->states[2].bigint, q, mxPtrDiff(p - q), 0);
445
65.5k
      parser->states[2].token = XS_TOKEN_BIGINT;
446
65.5k
    }
447
1.26k
    else
448
1.26k
      fxReportParserError(parser, parser->states[2].line, "invalid number");     
449
66.8k
  }  
450
324k
  else
451
324k
    fxGetNextNumber(parser, fxStringToNumber(parser->console, parser->buffer, 1));
452
390k
}
453
454
void fxGetNextNumberO(txParser* parser, int c, int legacy)
455
6.33k
{
456
6.33k
  txString p = parser->buffer;
457
6.33k
  txString q = p + parser->bufferSize;
458
6.33k
  if (legacy) {
459
4.17k
    p = fxGetNextDigitsD(parser, p, q, &legacy);
460
4.17k
    if (parser->character == '_')
461
523
      fxReportParserError(parser, parser->states[2].line, "invalid number");     
462
4.17k
    if (parser->character == 'n')
463
59
      fxReportParserError(parser, parser->states[2].line, "invalid number");     
464
4.17k
  }
465
2.16k
  else {
466
2.16k
    fxGetNextCharacter(parser);
467
2.16k
    legacy = 8;
468
2.16k
    p = fxGetNextDigits(parser, fxGetNextDigitsO, p, q, 1);
469
2.16k
  }
470
6.33k
  c = parser->character;
471
6.33k
  if (p == q) {
472
1
    fxReportMemoryError(parser, parser->states[2].line, "number overflow");
473
1
  }
474
6.33k
  if (c == 'n')
475
173
    fxGetNextCharacter(parser);
476
6.33k
  if (fxIsIdentifierFirst(parser->character)) {
477
445
    fxReportParserError(parser, parser->states[2].line, "invalid number");
478
445
  }
479
6.33k
  *p = 0;
480
6.33k
  q = parser->buffer;
481
6.33k
  if (c == 'n') {
482
173
    parser->states[2].bigint.data = fxNewParserChunk(parser, fxBigIntMaximumO(mxPtrDiff(p - q)));
483
173
    fxBigIntParseO(&parser->states[2].bigint, q, mxPtrDiff(p - q));
484
173
    parser->states[2].token = XS_TOKEN_BIGINT;
485
173
  }
486
6.16k
  else { 
487
6.16k
    txNumber n = 0;
488
59.3k
    while ((c = *q++))
489
53.1k
      n = (n * legacy) + (c - '0');
490
6.16k
    fxGetNextNumber(parser, n);
491
6.16k
  }
492
6.33k
}
493
494
void fxGetNextNumberX(txParser* parser)
495
127k
{
496
127k
  txString p = parser->buffer;
497
127k
  txString q = p + parser->bufferSize;
498
127k
  int c;
499
127k
  fxGetNextCharacter(parser);
500
127k
  p = fxGetNextDigits(parser, fxGetNextDigitsX, p, q, 1);
501
127k
  c = parser->character;
502
127k
  if (p == q) {
503
3
    fxReportMemoryError(parser, parser->states[2].line, "number overflow");
504
3
  }
505
127k
  if (c == 'n')
506
601
    fxGetNextCharacter(parser);
507
127k
  if (fxIsIdentifierFirst(parser->character)) {
508
282
    fxReportParserError(parser, parser->states[2].line, "invalid number");
509
282
  }
510
127k
  *p = 0;
511
127k
  q = parser->buffer;
512
127k
  if (c == 'n') {
513
592
    parser->states[2].bigint.data = fxNewParserChunk(parser, fxBigIntMaximumX(mxPtrDiff(p - q)));
514
592
    fxBigIntParseX(&parser->states[2].bigint, q, mxPtrDiff(p - q));
515
592
    parser->states[2].token = XS_TOKEN_BIGINT;
516
592
  }
517
126k
  else {
518
126k
    txNumber n = 0;
519
659k
    while ((c = *q++)) {
520
532k
      if (('0' <= c) && (c <= '9'))
521
418k
        n = (n * 16) + (c - '0');
522
113k
      else if (('a' <= c) && (c <= 'f'))
523
1.58k
        n = (n * 16) + (10 + c - 'a');
524
112k
      else
525
112k
        n = (n * 16) + (10 + c - 'A');
526
532k
    }
527
126k
    fxGetNextNumber(parser, n);
528
126k
  }
529
127k
}
530
531
void fxGetNextRegExp(txParser* parser, txU4 c)
532
33.6k
{
533
33.6k
  txString p;
534
33.6k
  txString q;
535
33.6k
  txBoolean backslash = 0;
536
33.6k
  txBoolean bracket = 0;
537
33.6k
    txBoolean first = 1;
538
33.6k
    txBoolean second = 1;
539
33.6k
  p = parser->buffer;
540
33.6k
  q = p + parser->bufferSize - 1;
541
33.6k
    if (!c) {
542
32.8k
    c = parser->character;
543
32.8k
        second = 0;
544
32.8k
    }
545
1.24M
  for (;;) {
546
1.24M
    if (c == (txU4)C_EOF) {
547
1.14k
      fxReportParserError(parser, parser->states[0].line, "end of file in regular expression");     
548
1.14k
      break;
549
1.14k
    }
550
1.24M
    else if ((c == 10) || (c == 13) || (c == 0x2028) || (c == 0x2029)) {
551
1.15k
      fxReportParserError(parser, parser->states[0].line, "end of line in regular expression");     
552
1.15k
      break;
553
1.15k
    }
554
1.24M
    else if (c == '*') {
555
1.46k
      if (first) {
556
1
        fxReportParserError(parser, parser->states[0].line, "invalid regular expression");
557
1
        break;
558
1
      }
559
1.46k
      backslash = 0;
560
1.46k
    }
561
1.23M
    else if (c == '\\') {
562
26.2k
      if (!backslash)
563
21.5k
        backslash = 1;
564
4.69k
      else
565
4.69k
        backslash = 0;
566
26.2k
    }
567
1.21M
    else if (c == '[') {
568
35.1k
      if (!backslash)
569
32.5k
        bracket = 1;
570
35.1k
      backslash = 0;
571
35.1k
    }
572
1.17M
    else if (c == ']') {
573
13.3k
      if (!backslash)
574
13.2k
        bracket = 0;
575
13.3k
      backslash = 0;
576
13.3k
    }
577
1.16M
    else if (c == '/') {
578
34.2k
      if (!backslash && !bracket)
579
31.3k
        break;
580
2.93k
      backslash = 0;
581
2.93k
    }
582
1.13M
    else {
583
1.13M
      backslash = 0;
584
1.13M
    }
585
1.20M
    p = fxUTF8Buffer(parser, c, p, q);
586
1.20M
        if (second)
587
744
            second = 0;
588
1.20M
        else
589
1.20M
            fxGetNextCharacter(parser);
590
1.20M
    c = parser->character;
591
1.20M
    first = 0;
592
1.20M
  }
593
33.6k
  *p = 0;
594
33.6k
  parser->states[0].stringLength = mxPtrDiff(p - parser->buffer);
595
33.6k
  parser->states[0].string = fxNewParserString(parser, parser->buffer, parser->states[0].stringLength);
596
33.6k
  p = parser->buffer;
597
33.6k
  q = p + parser->bufferSize - 1;
598
51.3k
  for (;;) {
599
51.3k
    fxGetNextCharacter(parser);
600
51.3k
    if (fxIsIdentifierNext(parser->character))
601
19.9k
      p = fxUTF8Buffer(parser, parser->character, p, q);
602
31.3k
    else 
603
31.3k
      break;
604
51.3k
  }
605
33.6k
  *p = 0;
606
33.6k
  parser->states[0].modifierLength = mxPtrDiff(p - parser->buffer);
607
33.6k
  parser->states[0].modifier = fxNewParserString(parser, parser->buffer, parser->states[0].modifierLength);
608
33.6k
  if (!fxCompileRegExp(parser->console, parser->states[0].string, parser->states[0].modifier, C_NULL, C_NULL, parser->buffer, parser->bufferSize))
609
6.01k
    fxReportParserError(parser, parser->states[0].line, "%s", parser->buffer);
610
33.6k
  parser->states[0].token = XS_TOKEN_REGEXP;
611
33.6k
}
612
613
void fxGetNextString(txParser* parser, int c)
614
586k
{
615
586k
  txString p = parser->buffer;
616
586k
  txString q = p + parser->bufferSize - 1;
617
13.2M
  for (;;) {
618
13.2M
    if (parser->character == (txU4)C_EOF) {
619
1.68k
      fxReportParserError(parser, parser->states[2].line, "end of file in string");     
620
1.68k
      break;
621
1.68k
    }
622
13.2M
    else if (parser->character == 10) {
623
140k
      parser->states[2].line++;
624
140k
      if (c == '`') {
625
135k
        p = fxUTF8Buffer(parser, parser->character, p, q);
626
135k
        fxGetNextCharacter(parser);
627
135k
      }
628
5.33k
      else {
629
5.33k
        fxReportParserError(parser, parser->states[2].line, "end of line in string");     
630
5.33k
        break;
631
5.33k
      }
632
140k
    }
633
13.1M
    else if (parser->character == 13) {
634
55.9k
      parser->states[2].line++;
635
55.9k
      if (c == '`') {
636
55.7k
        p = fxUTF8Buffer(parser, 10, p, q);
637
55.7k
        fxGetNextCharacter(parser);
638
55.7k
        if (parser->character == 10)
639
29.0k
          fxGetNextCharacter(parser);
640
55.7k
      }
641
131
      else {
642
131
        fxReportParserError(parser, parser->states[2].line, "end of line in string");     
643
131
        break;
644
131
      }
645
55.9k
    }
646
13.0M
    else if ((parser->character == 0x2028) || (parser->character == 0x2029)) {
647
7.66k
      parser->states[2].line++;
648
7.66k
      p = fxUTF8Buffer(parser, parser->character, p, q);
649
7.66k
      fxGetNextCharacter(parser);
650
7.66k
    }
651
13.0M
    else if (parser->character == (txU4)c) {
652
574k
      break;
653
574k
    }
654
12.4M
    else if (parser->character == '$') {
655
34.0k
      fxGetNextCharacter(parser);
656
34.0k
      if ((c == '`') && (parser->character == '{'))
657
4.10k
        break;
658
29.9k
      p = fxUTF8Buffer(parser, '$', p, q);
659
29.9k
    }
660
12.4M
    else if (parser->character == '\\') {
661
116k
      parser->states[2].escaped = 1;
662
116k
      p = fxUTF8Buffer(parser, '\\', p, q);
663
116k
      fxGetNextCharacter(parser);
664
116k
      switch (parser->character) {
665
479
      case 10:
666
1.20k
      case 0x2028:
667
1.34k
      case 0x2029:
668
1.34k
        parser->states[2].line++;
669
1.34k
        p = fxUTF8Buffer(parser, parser->character, p, q);
670
1.34k
        fxGetNextCharacter(parser);
671
1.34k
        break;
672
1.64k
      case 13:
673
1.64k
        parser->states[2].line++;
674
1.64k
        p = fxUTF8Buffer(parser, 10, p, q);
675
1.64k
        fxGetNextCharacter(parser);
676
1.64k
        if (parser->character == 10)
677
1.51k
          fxGetNextCharacter(parser);
678
1.64k
        break;
679
113k
      default:
680
113k
        p = fxUTF8Buffer(parser, parser->character, p, q);
681
113k
        fxGetNextCharacter(parser);
682
113k
        break;
683
116k
      } 
684
116k
    }  
685
12.3M
    else {
686
12.3M
      p = fxUTF8Buffer(parser, parser->character, p, q);
687
12.3M
      fxGetNextCharacter(parser);
688
12.3M
    }
689
13.2M
  }  
690
586k
  *p = 0;
691
586k
  if (p == q) {
692
0
    fxReportMemoryError(parser, parser->states[2].line, "string overflow");
693
0
  }
694
586k
  parser->states[2].rawLength = mxPtrDiff(p - parser->buffer);
695
586k
  parser->states[2].raw = fxNewParserString(parser, parser->buffer, parser->states[2].rawLength);
696
586k
  if (parser->states[2].escaped) {
697
21.5k
    txInteger character;
698
21.5k
    txString s;
699
21.5k
    txU1* u;
700
21.5k
    p = parser->buffer;
701
21.5k
    q = p + parser->bufferSize - 1; 
702
21.5k
    s = parser->states[2].raw;
703
6.80M
    while (*s) {
704
6.78M
      if (p == q) {
705
0
        fxReportMemoryError(parser, parser->states[2].line, "buffer overflow");
706
0
      }
707
6.78M
      if (*s == '\\') {
708
113k
        s++;
709
113k
        switch (*s) {
710
0
        case 0:
711
0
          break;
712
1.73k
        case 10:
713
1.73k
          s++;
714
1.73k
          break;
715
0
        case 13:
716
0
          s++;
717
0
          if (*s == 10)
718
0
            s++;
719
0
          break;
720
1.00k
        case 'b':
721
1.00k
          s++;
722
1.00k
          *p++ = '\b';
723
1.00k
          break;
724
155
        case 'f':
725
155
          s++;
726
155
          *p++ = '\f';
727
155
          break;
728
2.98k
        case 'n':
729
2.98k
          s++;
730
2.98k
          *p++ = '\n';
731
2.98k
          break;
732
2.22k
        case 'r':
733
2.22k
          s++;
734
2.22k
          *p++ = '\r';
735
2.22k
          break;
736
3.56k
        case 't':
737
3.56k
          s++;
738
3.56k
          *p++ = '\t';
739
3.56k
          break;
740
252
        case 'v':
741
252
          s++;
742
252
          *p++ = '\v';
743
252
          break;
744
569
        case 'x':
745
569
          s++;
746
569
          if (fxParseHexEscape(&s, &character))
747
475
            p = fxUTF8Buffer(parser, character, p, q);
748
94
          else
749
94
            parser->states[2].escaped |= mxStringErrorFlag;
750
569
          break;
751
30.0k
        case 'u':
752
30.0k
          s++;
753
30.0k
          if (fxParseUnicodeEscape(&s, &character, 1, '\\'))
754
17.9k
            p = fxUTF8Buffer(parser, character, p, q);
755
12.0k
          else
756
12.0k
            parser->states[2].escaped |= mxStringErrorFlag;
757
30.0k
          break;
758
1.47k
        case '0':
759
2.09k
        case '1':
760
2.23k
        case '2':
761
2.47k
        case '3':
762
2.98k
        case '4':
763
3.89k
        case '5':
764
3.92k
        case '6':
765
4.01k
        case '7':
766
4.01k
          character = *s++ - '0';
767
4.01k
          if ((character == 0) && ((*s < '0') || ('9' < *s)))
768
1.18k
            p = fxUTF8Buffer(parser, character, p, q);
769
2.83k
          else { 
770
2.83k
            parser->states[2].escaped |= mxStringLegacyFlag;
771
2.83k
            if ((0 <= character) && (character <= 3)) {
772
1.29k
              if (('0' <= *s) && (*s <= '7'))
773
362
                character = (character * 8) + *s++ - '0';
774
1.29k
            }
775
2.83k
            if (('0' <= *s) && (*s <= '7'))
776
311
              character = (character * 8) + *s++ - '0';
777
2.83k
            p = fxUTF8Buffer(parser, character, p, q);
778
2.83k
          }
779
4.01k
          break;
780
727
        case '8':
781
829
        case '9':
782
829
          parser->states[2].escaped |= mxStringLegacyFlag;
783
829
          *p++ = *s++;
784
829
          break;
785
65.8k
        default:
786
65.8k
          u = (txU1*)s;
787
65.8k
          if ((u[0] == 0xE2) && (u[1] == 0x80) && ((u[2] == 0xA8) || (u[2] == 0xA9))) { /* LS || PS */
788
824
            s += 3;
789
824
          }
790
65.0k
          else
791
65.0k
            *p++ = *s++;
792
65.8k
          break;
793
113k
        }
794
113k
      }
795
6.67M
      else {
796
6.67M
        *p++ = *s++;
797
6.67M
      }
798
6.78M
    }
799
21.5k
    *p = 0;
800
21.5k
    parser->states[2].stringLength = mxPtrDiff(p - parser->buffer);
801
21.5k
    parser->states[2].string = fxNewParserString(parser, parser->buffer, parser->states[2].stringLength);
802
21.5k
    if ((c == '`') && (parser->states[2].escaped & mxStringLegacyFlag))
803
1.34k
      parser->states[2].escaped |= mxStringErrorFlag;
804
21.5k
  }
805
564k
  else {
806
564k
    parser->states[2].stringLength = parser->states[2].rawLength;
807
564k
    parser->states[2].string = parser->states[2].raw;
808
564k
  }
809
586k
}
810
811
txBoolean fxGetNextStringD(int c, txU4* value)
812
10.2k
{
813
10.2k
  if (('0' <= c) && (c <= '9'))
814
7.55k
    *value = (*value * 10) + (c - '0');
815
2.65k
  else
816
2.65k
    return 0;
817
7.55k
  return 1;
818
10.2k
}
819
820
txBoolean fxGetNextStringX(int c, txU4* value)
821
52.9k
{
822
52.9k
  if (('0' <= c) && (c <= '9'))
823
17.0k
    *value = (*value * 16) + (c - '0');
824
35.9k
  else if (('a' <= c) && (c <= 'f'))
825
21.3k
    *value = (*value * 16) + (10 + c - 'a');
826
14.5k
  else if (('A' <= c) && (c <= 'F'))
827
4.55k
    *value = (*value * 16) + (10 + c - 'A');
828
10.0k
  else
829
10.0k
    return 0;
830
42.9k
  return 1;
831
52.9k
}
832
833
void fxGetNextToken(txParser* parser)
834
36.7M
{
835
36.7M
  if (parser->ahead == 0) {
836
35.6M
    fxGetNextTokenAux(parser);
837
35.6M
    parser->states[0] = parser->states[2];
838
35.6M
  }
839
1.15M
  else if (parser->ahead == 1) {
840
1.15M
    parser->states[0] = parser->states[1];
841
1.15M
    parser->ahead = 0;
842
1.15M
  }
843
3
  else if (parser->ahead == 2) {
844
3
    parser->states[0] = parser->states[1];
845
3
    parser->states[1] = parser->states[2];
846
3
    parser->ahead = 1;
847
3
  }
848
36.7M
}
849
850
void fxLookAheadOnce(txParser* parser)
851
1.18M
{
852
1.18M
  if (parser->ahead == 0) {
853
1.18M
    fxGetNextTokenAux(parser);
854
1.18M
    parser->states[1] = parser->states[2];
855
1.18M
    parser->ahead = 1;
856
1.18M
  }  
857
1.18M
}
858
859
void fxLookAheadTwice(txParser* parser)
860
3
{
861
3
  if (parser->ahead == 0) {
862
0
    fxGetNextTokenAux(parser);
863
0
    parser->states[1] = parser->states[2];
864
0
    fxGetNextTokenAux(parser);
865
0
    parser->ahead = 2;
866
0
  }  
867
3
  else if (parser->ahead == 1) {
868
3
    fxGetNextTokenAux(parser);
869
3
    parser->ahead = 2;
870
3
  }  
871
3
}
872
873
void fxGetNextTokenAux(txParser* parser)
874
36.7M
{
875
36.7M
  int c;
876
36.7M
  txString p;
877
36.7M
  txString q;
878
36.7M
  txU4 t = 0;
879
36.7M
  parser->states[2].crlf = 0;
880
36.7M
  parser->states[2].escaped = 0;
881
36.7M
  parser->states[2].bigint.data = C_NULL;
882
36.7M
  parser->states[2].bigint.size = 0;
883
36.7M
  parser->states[2].bigint.sign = 0;
884
36.7M
  parser->states[2].integer = 0;
885
36.7M
  parser->states[2].modifierLength = 0;
886
36.7M
  parser->states[2].modifier = parser->emptyString;
887
36.7M
  parser->states[2].number = 0;
888
36.7M
  parser->states[2].rawLength = 0;
889
36.7M
  parser->states[2].raw = parser->emptyString;
890
36.7M
  parser->states[2].stringLength = 0;
891
36.7M
  parser->states[2].string = parser->emptyString;
892
36.7M
  parser->states[2].symbol = C_NULL;
893
36.7M
  parser->states[2].token = XS_NO_TOKEN;
894
79.3M
  while (parser->states[2].token == XS_NO_TOKEN) {
895
42.7M
    switch (parser->character) {
896
190k
    case C_EOF:
897
190k
      parser->states[2].token = XS_TOKEN_EOF;
898
190k
      break;
899
1.89M
    case 10:  
900
1.89M
    case 0x2028: // <LS>
901
1.89M
    case 0x2029: // <PS>  
902
1.89M
      parser->states[2].line++;
903
1.89M
      fxGetNextCharacter(parser);
904
1.89M
      parser->states[2].crlf = 1;
905
1.89M
      break;
906
50.7k
    case 13:  
907
50.7k
      parser->states[2].line++;
908
50.7k
      fxGetNextCharacter(parser);
909
50.7k
      if (parser->character == 10)
910
26.2k
        fxGetNextCharacter(parser);
911
50.7k
      parser->states[2].crlf = 1;
912
50.7k
      break;
913
      
914
199k
    case '\t':
915
422k
    case 11:
916
429k
    case 12:
917
3.54M
    case ' ':
918
3.54M
    case 0x00A0:
919
3.54M
    case 0x1680:
920
3.54M
    case 0x2000:
921
3.54M
    case 0x2001:
922
3.54M
    case 0x2002:
923
3.54M
    case 0x2003:
924
3.54M
    case 0x2004:
925
3.54M
    case 0x2005:
926
3.55M
    case 0x2006:
927
3.57M
    case 0x2007:
928
3.57M
    case 0x2008:
929
3.57M
    case 0x2009:
930
3.57M
    case 0x200A:
931
3.57M
    case 0x202F:
932
3.57M
    case 0x205F:
933
3.57M
    case 0x3000:
934
3.57M
    case 0xFEFF:
935
3.57M
      fxGetNextCharacter(parser);
936
3.57M
      break;
937
      
938
12.9M
    case '0':
939
12.9M
      fxGetNextCharacter(parser);
940
12.9M
      c = parser->character;
941
12.9M
      if (c == '.') {
942
12.3k
        fxGetNextCharacter(parser);
943
12.3k
        c = parser->character;
944
12.3k
        if ((('0' <= c) && (c <= '9')) || (c == 'e') || (c == 'E'))
945
10.0k
          fxGetNextNumberE(parser, 1);
946
2.27k
        else {
947
2.27k
          parser->states[2].number = 0;
948
2.27k
          parser->states[2].token = XS_TOKEN_NUMBER;
949
2.27k
        }
950
12.3k
      }
951
12.9M
      else if ((c == 'b') || (c == 'B')) {
952
2.42k
        fxGetNextNumberB(parser);
953
2.42k
      }
954
12.9M
            else if ((c == 'e') || (c == 'E')) {
955
1.56k
                fxGetNextNumberE(parser, 0);
956
1.56k
            }
957
12.9M
            else if (c == 'n') {
958
7.32k
                fxGetNextNumberE(parser, 0);
959
7.32k
            }
960
12.9M
      else if ((c == 'o') || (c == 'O')) {
961
2.16k
        fxGetNextNumberO(parser, '0', 0);
962
2.16k
      }
963
12.9M
      else if ((c == 'x') || (c == 'X')) {
964
127k
        fxGetNextNumberX(parser);
965
127k
      }
966
12.7M
      else if (('0' <= c) && (c <= '9')) {
967
4.66k
        if ((parser->flags & mxStrictFlag))
968
485
          fxReportParserError(parser, parser->states[2].line, "octal number (strict mode)");     
969
4.66k
        fxGetNextNumberO(parser, c, 1);
970
4.66k
      }
971
12.7M
      else {
972
12.7M
        parser->states[2].integer = 0;
973
12.7M
        parser->states[2].token = XS_TOKEN_INTEGER;
974
12.7M
      }
975
12.9M
      break;
976
121k
    case '1':
977
198k
    case '2':
978
269k
    case '3':
979
293k
    case '4':
980
315k
    case '5':
981
337k
    case '6':
982
348k
    case '7':
983
357k
    case '8':
984
365k
    case '9':
985
365k
      fxGetNextNumberE(parser, 0);
986
365k
      break;
987
440k
    case '.':
988
440k
      fxGetNextCharacter(parser);
989
440k
      c = parser->character;
990
440k
      if (c == '.') { 
991
12.1k
        fxGetNextCharacter(parser);
992
12.1k
        if (parser->character == '.') { 
993
11.4k
          parser->states[2].token = XS_TOKEN_SPREAD;
994
11.4k
          fxGetNextCharacter(parser);
995
11.4k
        }
996
785
        else {
997
785
          fxReportParserError(parser, parser->states[2].line, "invalid character %d", parser->character);
998
785
        }    
999
12.1k
      }    
1000
428k
      else if (('0' <= c) && (c <= '9'))
1001
6.01k
        fxGetNextNumberE(parser, 1);
1002
422k
      else
1003
422k
        parser->states[2].token = XS_TOKEN_DOT;
1004
440k
      break;  
1005
594k
    case ',':
1006
594k
      parser->states[2].token = XS_TOKEN_COMMA;
1007
594k
      fxGetNextCharacter(parser);
1008
594k
      break;  
1009
498k
    case ';':
1010
498k
      parser->states[2].token = XS_TOKEN_SEMICOLON;
1011
498k
      fxGetNextCharacter(parser);
1012
498k
      break;  
1013
225k
    case ':':
1014
225k
      parser->states[2].token = XS_TOKEN_COLON;
1015
225k
      fxGetNextCharacter(parser);
1016
225k
      break;  
1017
33.3k
    case '?':
1018
33.3k
      fxGetNextCharacter(parser);
1019
33.3k
      if (parser->character == '.') { 
1020
14.0k
        if ((parser->lookahead < '0') || ('9' < parser->lookahead)) {
1021
13.6k
          parser->states[2].token = XS_TOKEN_CHAIN;
1022
13.6k
          fxGetNextCharacter(parser);
1023
13.6k
        }
1024
444
        else
1025
444
          parser->states[2].token = XS_TOKEN_QUESTION_MARK;
1026
14.0k
      }
1027
19.3k
      else if (parser->character == '?') {   
1028
5.60k
        parser->states[2].token = XS_TOKEN_COALESCE;
1029
5.60k
        fxGetNextCharacter(parser);
1030
5.60k
        if (parser->character == '=') { 
1031
1.20k
          parser->states[2].token = XS_TOKEN_COALESCE_ASSIGN;
1032
1.20k
          fxGetNextCharacter(parser);
1033
1.20k
        }
1034
5.60k
      }
1035
13.7k
      else  
1036
13.7k
        parser->states[2].token = XS_TOKEN_QUESTION_MARK;
1037
33.3k
      break;  
1038
912k
    case '(':
1039
912k
      parser->states[2].token = XS_TOKEN_LEFT_PARENTHESIS;
1040
912k
      fxGetNextCharacter(parser);
1041
912k
      break;  
1042
707k
    case ')':
1043
707k
      parser->states[2].token = XS_TOKEN_RIGHT_PARENTHESIS;
1044
707k
      fxGetNextCharacter(parser);
1045
707k
      break;  
1046
185k
    case '[':
1047
185k
      parser->states[2].token = XS_TOKEN_LEFT_BRACKET;
1048
185k
      fxGetNextCharacter(parser);
1049
185k
      break;  
1050
167k
    case ']':
1051
167k
      parser->states[2].token = XS_TOKEN_RIGHT_BRACKET;
1052
167k
      fxGetNextCharacter(parser);
1053
167k
      break;  
1054
636k
    case '{':
1055
636k
      parser->states[2].token = XS_TOKEN_LEFT_BRACE;
1056
636k
      fxGetNextCharacter(parser);
1057
636k
      break;  
1058
272k
    case '}':
1059
272k
      parser->states[2].token = XS_TOKEN_RIGHT_BRACE;
1060
272k
      fxGetNextCharacter(parser);
1061
272k
      break;  
1062
312k
    case '=':
1063
312k
      fxGetNextCharacter(parser);
1064
312k
      if (parser->character == '=') {     
1065
4.26k
        fxGetNextCharacter(parser);
1066
4.26k
        if (parser->character == '=') {
1067
2.84k
          parser->states[2].token = XS_TOKEN_STRICT_EQUAL;
1068
2.84k
          fxGetNextCharacter(parser);
1069
2.84k
        }
1070
1.42k
        else
1071
1.42k
          parser->states[2].token = XS_TOKEN_EQUAL;
1072
4.26k
      }
1073
308k
      else if (parser->character == '>') { 
1074
66.8k
        parser->states[2].token = XS_TOKEN_ARROW;
1075
66.8k
        fxGetNextCharacter(parser);
1076
66.8k
      }
1077
241k
      else  
1078
241k
        parser->states[2].token = XS_TOKEN_ASSIGN;
1079
312k
      break;
1080
91.3k
    case '<':
1081
91.3k
      fxGetNextCharacter(parser);
1082
91.3k
      if (parser->character == '<') {
1083
21.3k
        fxGetNextCharacter(parser);
1084
21.3k
        if (parser->character == '=') {
1085
301
          parser->states[2].token = XS_TOKEN_LEFT_SHIFT_ASSIGN;
1086
301
          fxGetNextCharacter(parser);
1087
301
        }
1088
21.0k
        else
1089
21.0k
          parser->states[2].token = XS_TOKEN_LEFT_SHIFT;
1090
21.3k
      }
1091
69.9k
      else  if (parser->character == '=') {
1092
6.40k
        parser->states[2].token = XS_TOKEN_LESS_EQUAL;
1093
6.40k
        fxGetNextCharacter(parser);
1094
6.40k
      }
1095
63.5k
      else
1096
63.5k
        parser->states[2].token = XS_TOKEN_LESS;
1097
91.3k
      break;  
1098
139k
    case '>':
1099
139k
      fxGetNextCharacter(parser);
1100
139k
      if (parser->character == '>') {     
1101
5.05k
        fxGetNextCharacter(parser);
1102
5.05k
        if (parser->character == '>') {     
1103
1.23k
          fxGetNextCharacter(parser);
1104
1.23k
          if (parser->character == '=') {
1105
48
            parser->states[2].token = XS_TOKEN_UNSIGNED_RIGHT_SHIFT_ASSIGN;
1106
48
            fxGetNextCharacter(parser);
1107
48
          }
1108
1.18k
          else
1109
1.18k
            parser->states[2].token = XS_TOKEN_UNSIGNED_RIGHT_SHIFT;
1110
1.23k
        }
1111
3.82k
        else if (parser->character == '=') {
1112
1.47k
          parser->states[2].token = XS_TOKEN_SIGNED_RIGHT_SHIFT_ASSIGN;
1113
1.47k
          fxGetNextCharacter(parser);
1114
1.47k
        }
1115
2.34k
        else
1116
2.34k
          parser->states[2].token = XS_TOKEN_SIGNED_RIGHT_SHIFT;
1117
5.05k
      }
1118
134k
      else if (parser->character == '=') {
1119
4.25k
        parser->states[2].token = XS_TOKEN_MORE_EQUAL;
1120
4.25k
        fxGetNextCharacter(parser);
1121
4.25k
      }
1122
130k
      else
1123
130k
        parser->states[2].token = XS_TOKEN_MORE;
1124
139k
      break;  
1125
184k
    case '!':
1126
184k
      fxGetNextCharacter(parser);
1127
184k
      if (parser->character == '=') {     
1128
3.70k
        fxGetNextCharacter(parser);
1129
3.70k
        if (parser->character == '=') {
1130
1.66k
          parser->states[2].token = XS_TOKEN_STRICT_NOT_EQUAL;
1131
1.66k
          fxGetNextCharacter(parser);
1132
1.66k
        }
1133
2.03k
        else
1134
2.03k
          parser->states[2].token = XS_TOKEN_NOT_EQUAL;
1135
3.70k
      }
1136
180k
      else
1137
180k
        parser->states[2].token = XS_TOKEN_NOT;
1138
184k
      break;
1139
7.41k
    case '~':
1140
7.41k
      parser->states[2].token = XS_TOKEN_BIT_NOT;
1141
7.41k
      fxGetNextCharacter(parser);
1142
7.41k
      break;
1143
30.5k
    case '&':
1144
30.5k
      fxGetNextCharacter(parser);
1145
30.5k
      if (parser->character == '=') { 
1146
1.31k
        parser->states[2].token = XS_TOKEN_BIT_AND_ASSIGN;
1147
1.31k
        fxGetNextCharacter(parser);
1148
1.31k
      }
1149
29.1k
      else if (parser->character == '&') {
1150
9.01k
        parser->states[2].token = XS_TOKEN_AND;
1151
9.01k
        fxGetNextCharacter(parser);
1152
9.01k
        if (parser->character == '=') { 
1153
2.88k
          parser->states[2].token = XS_TOKEN_AND_ASSIGN;
1154
2.88k
          fxGetNextCharacter(parser);
1155
2.88k
        }
1156
9.01k
      }
1157
20.1k
      else
1158
20.1k
        parser->states[2].token = XS_TOKEN_BIT_AND;
1159
30.5k
      break;
1160
22.8k
    case '|':
1161
22.8k
      fxGetNextCharacter(parser);
1162
22.8k
      if (parser->character == '=') {
1163
855
        parser->states[2].token = XS_TOKEN_BIT_OR_ASSIGN;
1164
855
        fxGetNextCharacter(parser);
1165
855
      }
1166
22.0k
      else if (parser->character == '|') {
1167
9.61k
        parser->states[2].token = XS_TOKEN_OR;
1168
9.61k
        fxGetNextCharacter(parser);
1169
9.61k
        if (parser->character == '=') { 
1170
1.94k
          parser->states[2].token = XS_TOKEN_OR_ASSIGN;
1171
1.94k
          fxGetNextCharacter(parser);
1172
1.94k
        }
1173
9.61k
      }
1174
12.4k
      else
1175
12.4k
        parser->states[2].token = XS_TOKEN_BIT_OR;
1176
22.8k
      break;
1177
5.53k
    case '^':
1178
5.53k
      fxGetNextCharacter(parser);
1179
5.53k
      if (parser->character == '=') {
1180
277
        parser->states[2].token = XS_TOKEN_BIT_XOR_ASSIGN;
1181
277
        fxGetNextCharacter(parser);
1182
277
      }
1183
5.26k
      else
1184
5.26k
        parser->states[2].token = XS_TOKEN_BIT_XOR;
1185
5.53k
      break;
1186
104k
    case '+': 
1187
104k
      fxGetNextCharacter(parser);
1188
104k
      if (parser->character == '=') {
1189
3.97k
        parser->states[2].token = XS_TOKEN_ADD_ASSIGN;
1190
3.97k
        fxGetNextCharacter(parser);
1191
3.97k
      }
1192
100k
      else if (parser->character == '+') {
1193
29.6k
        parser->states[2].token = XS_TOKEN_INCREMENT;
1194
29.6k
        fxGetNextCharacter(parser);
1195
29.6k
      }
1196
71.2k
      else
1197
71.2k
        parser->states[2].token = XS_TOKEN_ADD;
1198
104k
      break;
1199
13.0M
    case '-': 
1200
13.0M
      fxGetNextCharacter(parser);
1201
13.0M
      if (parser->character == '=') {
1202
189
        parser->states[2].token = XS_TOKEN_SUBTRACT_ASSIGN;
1203
189
        fxGetNextCharacter(parser);
1204
189
      }
1205
13.0M
      else if (parser->character == '-') {
1206
212k
        parser->states[2].token = XS_TOKEN_DECREMENT;
1207
212k
        fxGetNextCharacter(parser);
1208
212k
      }
1209
12.8M
      else
1210
12.8M
        parser->states[2].token = XS_TOKEN_SUBTRACT;
1211
13.0M
      break;
1212
54.6k
    case '*': 
1213
54.6k
      fxGetNextCharacter(parser);
1214
54.6k
      if (parser->character == '=') {
1215
478
        parser->states[2].token = XS_TOKEN_MULTIPLY_ASSIGN;
1216
478
        fxGetNextCharacter(parser);
1217
478
      }
1218
54.1k
      else if (parser->character == '*') {
1219
2.96k
        fxGetNextCharacter(parser);
1220
2.96k
        if (parser->character == '=') {
1221
41
          parser->states[2].token = XS_TOKEN_EXPONENTIATION_ASSIGN;
1222
41
          fxGetNextCharacter(parser);
1223
41
        }
1224
2.91k
        else
1225
2.91k
          parser->states[2].token = XS_TOKEN_EXPONENTIATION;
1226
2.96k
      }
1227
51.1k
      else
1228
51.1k
        parser->states[2].token = XS_TOKEN_MULTIPLY;
1229
54.6k
      break;
1230
645k
    case '/':
1231
645k
      fxGetNextCharacter(parser);
1232
645k
      if (parser->character == '*') {
1233
14.3k
        fxGetNextCharacter(parser);
1234
2.65M
        for (;;) {
1235
2.65M
          if (parser->character == (txU4)C_EOF) {
1236
2.61k
            fxReportParserError(parser, parser->states[2].line, "end of file in comment");      
1237
2.61k
            break;
1238
2.61k
          }
1239
2.65M
          else if ((parser->character == 10) || (parser->character == 0x2028) || (parser->character == 0x2029)) {
1240
54.8k
            parser->states[2].line++;
1241
54.8k
            fxGetNextCharacter(parser);
1242
54.8k
            parser->states[2].crlf = 1;
1243
54.8k
          }
1244
2.59M
          else if (parser->character == 13) {
1245
15.1k
            parser->states[2].line++;
1246
15.1k
            fxGetNextCharacter(parser);
1247
15.1k
            if (parser->character == 10)
1248
2.41k
              fxGetNextCharacter(parser);
1249
15.1k
            parser->states[2].crlf = 1;
1250
15.1k
          }
1251
2.58M
          else if (parser->character == '*') {
1252
96.6k
            fxGetNextCharacter(parser);
1253
96.6k
            if (parser->character == '/') {
1254
11.7k
              fxGetNextCharacter(parser);
1255
11.7k
              break;
1256
11.7k
            }
1257
96.6k
          }
1258
2.48M
          else
1259
2.48M
            fxGetNextCharacter(parser);
1260
2.65M
        }
1261
14.3k
      }
1262
631k
      else if (parser->character == '/') {
1263
421k
        fxGetNextCharacter(parser);
1264
421k
        p = parser->buffer;
1265
421k
        q = p + parser->bufferSize - 1;
1266
24.9M
        while ((parser->character != (txU4)C_EOF) && (parser->character != 10) && (parser->character != 13) && (parser->character != 0x2028) && (parser->character != 0x2029)) {
1267
24.5M
          if (p < q)
1268
23.6M
            *p++ = (char)parser->character;
1269
24.5M
          fxGetNextCharacter(parser);
1270
24.5M
        }  
1271
421k
        *p = 0;
1272
421k
        p = parser->buffer;
1273
421k
        if ((*p == '#') || (*p == '@')) {
1274
62.4k
          if (!c_strncmp(p, "@line ", 6)) {
1275
24.9k
            p += 6;
1276
24.9k
            t = 0;
1277
24.9k
            c = *p++;
1278
194k
            while (('0' <= c) && (c <= '9')) {
1279
169k
              t = (t * 10) + (c - '0');
1280
169k
              c = *p++;
1281
169k
            }
1282
24.9k
            if (!t) goto bail;
1283
23.3k
            if (c == ' ') {
1284
2.15k
              c = *p++;
1285
2.15k
              if (c != '"') goto bail;
1286
1.52k
              q = p;
1287
1.52k
              c = *q++;
1288
33.6k
              while ((c != 0) && (c != 10) && (c != 13) && (c != '"'))
1289
32.1k
                c = *q++;
1290
1.52k
              if (c != '"') goto bail;
1291
148
              *(--q) = 0;
1292
148
              parser->path = fxNewParserSymbol(parser, p);
1293
148
            }
1294
21.3k
            parser->states[2].line = t - 1;
1295
21.3k
          }
1296
37.5k
          else if (!c_strncmp(p, "# sourceMappingURL=", 19) || !c_strncmp(p, "@ sourceMappingURL=", 19)) {
1297
1.35k
            p += 19;
1298
1.35k
            q = p;
1299
13.5k
            while (((c = *q)) && (c != 10) && (c != 13))
1300
12.2k
              q++;
1301
1.35k
            *q = 0;
1302
1.35k
            parser->name = fxNewParserString(parser, p, mxPtrDiff(q - p));
1303
1.35k
          }
1304
36.1k
          else if (!c_strncmp(p, "# sourceURL=", 12) || !c_strncmp(p, "@ sourceURL=", 12)) {
1305
1.32k
            p += 12;
1306
1.32k
            q = p;
1307
139k
            while (((c = *q)) && (c != 10) && (c != 13))
1308
138k
              q++;
1309
1.32k
            *q = 0;
1310
1.32k
            parser->source = fxNewParserSymbol(parser, p);
1311
1.32k
          }
1312
62.4k
      }
1313
421k
      bail:
1314
421k
        ;
1315
421k
      }
1316
209k
      else if (parser->character == '=') {
1317
1.58k
        parser->states[2].token = XS_TOKEN_DIVIDE_ASSIGN;
1318
1.58k
        fxGetNextCharacter(parser);
1319
1.58k
      }
1320
207k
      else 
1321
207k
        parser->states[2].token = XS_TOKEN_DIVIDE;
1322
645k
      break;
1323
645k
    case '%': 
1324
10.7k
      fxGetNextCharacter(parser);
1325
10.7k
      if (parser->character == '=') {
1326
729
        parser->states[2].token = XS_TOKEN_MODULO_ASSIGN;
1327
729
        fxGetNextCharacter(parser);
1328
729
      }
1329
10.0k
      else
1330
10.0k
        parser->states[2].token = XS_TOKEN_MODULO;
1331
10.7k
      break;
1332
    
1333
205k
    case '"':
1334
315k
    case '\'':
1335
315k
      c = parser->character;
1336
315k
      fxGetNextCharacter(parser);
1337
315k
      fxGetNextString(parser, c);
1338
315k
      parser->states[2].token = XS_TOKEN_STRING;
1339
315k
      fxGetNextCharacter(parser);
1340
315k
      break;
1341
      
1342
266k
    case '`':
1343
266k
      fxGetNextCharacter(parser);
1344
266k
      fxGetNextString(parser, '`');
1345
266k
      if (parser->character == '{')
1346
1.12k
        parser->states[2].token = XS_TOKEN_TEMPLATE_HEAD;
1347
265k
      else
1348
265k
        parser->states[2].token = XS_TOKEN_TEMPLATE;
1349
266k
      fxGetNextCharacter(parser);
1350
266k
      break;
1351
      
1352
1.35k
    case '@':
1353
1.35k
      if (parser->flags & mxCFlag)
1354
0
        parser->states[2].token = XS_TOKEN_HOST;
1355
1.35k
            else
1356
1.35k
                fxReportParserError(parser, parser->states[2].line, "invalid character @");
1357
1.35k
            fxGetNextCharacter(parser);
1358
1.35k
      break;
1359
      
1360
3.84M
    default:
1361
3.84M
      p = parser->buffer;
1362
3.84M
      q = p + parser->bufferSize - 1;
1363
3.84M
      if (parser->character == '#') {
1364
36.4k
        *p++ = '#';
1365
36.4k
        fxGetNextCharacter(parser);
1366
36.4k
      }
1367
3.84M
      if (fxIsIdentifierFirst(parser->character)) {
1368
3.70M
        p = fxUTF8Buffer(parser, parser->character, p, q);        
1369
3.70M
        fxGetNextCharacter(parser);
1370
3.70M
      }
1371
136k
      else if (parser->character == '\\') {
1372
6.42k
        parser->states[2].escaped = 1;
1373
6.42k
        t = 0;
1374
6.42k
        if (fxGetNextIdentiferX(parser, &t) && fxIsIdentifierFirst(t))
1375
1.14k
          p = fxUTF8Buffer(parser, t, p, q);        
1376
5.27k
        else
1377
5.27k
          p = C_NULL;
1378
6.42k
      }
1379
130k
      else
1380
130k
        p = C_NULL;
1381
3.84M
      if (p) {
1382
18.3M
        for (;;) {
1383
18.3M
          if (p == q) {
1384
1
            fxReportMemoryError(parser, parser->states[2].line, "identifier overflow");
1385
1
          }
1386
18.3M
          if (fxIsIdentifierNext(parser->character)) {
1387
14.6M
            p = fxUTF8Buffer(parser, parser->character, p, q);        
1388
14.6M
            fxGetNextCharacter(parser);
1389
14.6M
          }
1390
3.70M
          else if (parser->character == '\\') {
1391
2.42k
            parser->states[2].escaped = 1;
1392
2.42k
            t = 0;
1393
2.42k
            if (fxGetNextIdentiferX(parser, &t) && fxIsIdentifierNext(t))
1394
682
              p = fxUTF8Buffer(parser, t, p, q);        
1395
1.74k
            else {
1396
1.74k
              p = C_NULL;
1397
1.74k
              break;
1398
1.74k
            }
1399
2.42k
          }
1400
3.70M
          else {
1401
3.70M
            *p = 0;
1402
3.70M
            if (parser->buffer[0] == '#') {
1403
28.0k
              parser->states[2].symbol = fxNewParserSymbol(parser, parser->buffer);
1404
28.0k
              parser->states[2].token = XS_TOKEN_PRIVATE_IDENTIFIER;
1405
28.0k
            }
1406
3.67M
            else {
1407
3.67M
              fxGetNextKeyword(parser);
1408
3.67M
            }
1409
3.70M
            break;
1410
3.70M
          }
1411
18.3M
        }
1412
3.70M
      }
1413
3.84M
      if (!p) {
1414
137k
        fxReportParserError(parser, parser->states[2].line, "invalid character %d", parser->character);
1415
137k
        fxGetNextCharacter(parser);
1416
137k
      }
1417
3.84M
      break;
1418
42.7M
    }
1419
42.7M
  }
1420
36.7M
}
1421
1422
void fxGetNextTokenTemplate(txParser* parser)
1423
4.08k
{
1424
4.08k
  parser->states[2].crlf = 0;
1425
4.08k
  parser->states[2].escaped = 0;
1426
4.08k
  parser->states[2].integer = 0;
1427
4.08k
  parser->states[2].modifierLength = 0;
1428
4.08k
  parser->states[2].modifier = parser->emptyString;
1429
4.08k
  parser->states[2].number = 0;
1430
4.08k
  parser->states[2].rawLength = 0;
1431
4.08k
  parser->states[2].raw = parser->emptyString;
1432
4.08k
  parser->states[2].stringLength = 0;
1433
4.08k
  parser->states[2].string = parser->emptyString;
1434
4.08k
  parser->states[2].symbol = C_NULL;
1435
4.08k
  parser->states[2].token = XS_NO_TOKEN;
1436
4.08k
  fxGetNextString(parser, '`');
1437
4.08k
  if (parser->character == '{')
1438
2.98k
    parser->states[2].token = XS_TOKEN_TEMPLATE_MIDDLE;
1439
1.09k
  else
1440
1.09k
    parser->states[2].token = XS_TOKEN_TEMPLATE_TAIL;
1441
4.08k
  fxGetNextCharacter(parser);
1442
4.08k
  parser->states[0] = parser->states[2];
1443
4.08k
  parser->ahead = 0;
1444
4.08k
}
1445
1446
void fxGetNextTokenJSON(txParser* parser)
1447
0
{
1448
0
  int c;
1449
0
  txString p;
1450
0
  txString q;
1451
1452
0
  parser->states[0] = parser->states[2];
1453
  
1454
0
  parser->states[2].crlf = 0;
1455
0
  parser->states[2].escaped = 0;
1456
0
  parser->states[2].integer = 0;
1457
0
  parser->states[2].modifierLength = 0;
1458
0
  parser->states[2].modifier = parser->emptyString;
1459
0
  parser->states[2].number = 0;
1460
0
  parser->states[2].rawLength = 0;
1461
0
  parser->states[2].raw = parser->emptyString;
1462
0
  parser->states[2].stringLength = 0;
1463
0
  parser->states[2].string = parser->emptyString;
1464
0
  parser->states[2].symbol = C_NULL;
1465
0
  parser->states[2].token = XS_NO_TOKEN;
1466
  
1467
0
  while (parser->states[2].token == XS_NO_TOKEN) {
1468
0
    switch (parser->character) {
1469
0
    case C_EOF:
1470
0
      parser->states[2].token = XS_TOKEN_EOF;
1471
0
      break;
1472
0
    case 10:  
1473
0
      parser->states[2].line++;
1474
0
      fxGetNextCharacter(parser);
1475
0
      parser->states[2].crlf = 1;
1476
0
      break;
1477
0
    case 13:  
1478
0
      parser->states[2].line++;
1479
0
      fxGetNextCharacter(parser);
1480
0
      if (parser->character == 10)
1481
0
        fxGetNextCharacter(parser);
1482
0
      parser->states[2].crlf = 1;
1483
0
      break;
1484
      
1485
0
    case '\t':
1486
0
    case ' ':
1487
0
      fxGetNextCharacter(parser);
1488
0
      break;
1489
      
1490
0
    case '0':
1491
0
      fxGetNextCharacter(parser);
1492
0
      c = parser->character;
1493
0
      if (c == '.') {
1494
0
        fxGetNextCharacter(parser);
1495
0
        c = parser->character;
1496
0
        if ((('0' <= c) && (c <= '9')) || (c == 'e') || (c == 'E'))
1497
0
          fxGetNextNumberE(parser, 1);
1498
0
        else {
1499
0
          parser->states[2].number = 0;
1500
0
          parser->states[2].token = XS_TOKEN_NUMBER;
1501
0
        }
1502
0
      }
1503
0
      else if ((c == 'b') || (c == 'B')) {
1504
0
        fxGetNextNumberB(parser);
1505
0
      }
1506
0
      else if ((c == 'e') || (c == 'E')) {
1507
0
        fxGetNextNumberE(parser, 0);
1508
0
      }
1509
0
      else if ((c == 'o') || (c == 'O')) {
1510
0
        fxGetNextNumberO(parser, '0', 0);
1511
0
      }
1512
0
      else if ((c == 'x') || (c == 'X')) {
1513
0
        fxGetNextNumberX(parser);
1514
0
      }
1515
0
      else {
1516
0
        parser->states[2].integer = 0;
1517
0
        parser->states[2].token = XS_TOKEN_INTEGER;
1518
0
      }
1519
0
      break;
1520
0
    case '1':
1521
0
    case '2':
1522
0
    case '3':
1523
0
    case '4':
1524
0
    case '5':
1525
0
    case '6':
1526
0
    case '7':
1527
0
    case '8':
1528
0
    case '9':
1529
0
      fxGetNextNumberE(parser, 0);
1530
0
      break;
1531
0
    case '-': 
1532
0
      fxGetNextCharacter(parser);
1533
0
      fxGetNextNumberE(parser, 0);
1534
0
      if (parser->states[2].token == XS_TOKEN_INTEGER)
1535
0
        parser->states[2].integer = 0 - parser->states[2].integer;
1536
0
      else
1537
0
        parser->states[2].number = 0 - parser->states[2].number;
1538
0
      break;
1539
0
    case ',':
1540
0
      parser->states[2].token = XS_TOKEN_COMMA;
1541
0
      fxGetNextCharacter(parser);
1542
0
      break; 
1543
0
    case ':':
1544
0
      parser->states[2].token = XS_TOKEN_COLON;
1545
0
      fxGetNextCharacter(parser);
1546
0
      break; 
1547
0
    case '[':
1548
0
      parser->states[2].token = XS_TOKEN_LEFT_BRACKET;
1549
0
      fxGetNextCharacter(parser);
1550
0
      break; 
1551
0
    case ']':
1552
0
      parser->states[2].token = XS_TOKEN_RIGHT_BRACKET;
1553
0
      fxGetNextCharacter(parser);
1554
0
      break; 
1555
0
    case '{':
1556
0
      parser->states[2].token = XS_TOKEN_LEFT_BRACE;
1557
0
      fxGetNextCharacter(parser);
1558
0
      break; 
1559
0
    case '}':
1560
0
      parser->states[2].token = XS_TOKEN_RIGHT_BRACE;
1561
0
      fxGetNextCharacter(parser);
1562
0
      break; 
1563
0
    case '"':
1564
0
      fxGetNextCharacter(parser);
1565
0
      fxGetNextString(parser, '"');
1566
0
      parser->states[2].token = XS_TOKEN_STRING;
1567
0
      fxGetNextCharacter(parser);
1568
0
      break;
1569
0
    default:
1570
0
      if (fxIsIdentifierFirst((char)parser->character)) {
1571
0
        p = parser->buffer;
1572
0
        q = p + parser->bufferSize - 1;
1573
0
        for (;;) {
1574
0
          if (p == q) {
1575
0
            fxReportMemoryError(parser, parser->states[2].line, "identifier overflow");
1576
0
          }
1577
0
          *p++ = (char)parser->character;
1578
0
          fxGetNextCharacter(parser);
1579
0
          if (!fxIsIdentifierNext((char)parser->character))
1580
0
            break;
1581
0
        }
1582
0
        *p = 0;
1583
0
        if (!c_strcmp("false", parser->buffer)) 
1584
0
          parser->states[2].token = XS_TOKEN_FALSE;
1585
0
        else if (!c_strcmp("null", parser->buffer)) 
1586
0
          parser->states[2].token = XS_TOKEN_NULL;
1587
0
        else if (!c_strcmp("true", parser->buffer)) 
1588
0
          parser->states[2].token = XS_TOKEN_TRUE;
1589
0
        else {
1590
0
          parser->states[2].symbol = fxNewParserSymbol(parser, parser->buffer);
1591
0
          parser->states[2].token = XS_TOKEN_IDENTIFIER;
1592
0
        }
1593
0
      }
1594
0
      else {
1595
0
        fxReportParserError(parser, parser->states[2].line, "invalid character %d", parser->character);
1596
0
        fxGetNextCharacter(parser);
1597
0
      }
1598
0
      break;
1599
0
    }
1600
0
  }
1601
0
}
1602
1603
typedef struct {
1604
  char* name;
1605
  int value;
1606
} txEntity;
1607
1608
static int fxCompareEntities(const void *name, const void *entity);
1609
1610
36.0k
#define XS_ENTITIES_COUNT 253
1611
static const txEntity ICACHE_RODATA_ATTR gxEntities[XS_ENTITIES_COUNT] = {
1612
  { "AElig", 0x00C6 }, { "Aacute", 0x00C1 }, { "Acirc", 0x00C2 }, { "Agrave", 0x00C0 }, { "Alpha", 0x0391 }, { "Aring", 0x00C5 }, { "Atilde", 0x00C3 }, { "Auml", 0x00C4 },
1613
  { "Beta", 0x0392 }, { "Ccedil", 0x00C7 }, { "Chi", 0x03A7 }, { "Dagger", 0x2021 }, { "Delta", 0x0394 }, { "ETH", 0x00D0 }, { "Eacute", 0x00C9 }, { "Ecirc", 0x00CA },
1614
  { "Egrave", 0x00C8 }, { "Epsilon", 0x0395 }, { "Eta", 0x0397 }, { "Euml", 0x00CB }, { "Gamma", 0x0393 }, { "Iacute", 0x00CD }, { "Icirc", 0x00CE }, { "Igrave", 0x00CC },
1615
  { "Iota", 0x0399 }, { "Iuml", 0x00CF }, { "Kappa", 0x039A }, { "Lambda", 0x039B }, { "Mu", 0x039C }, { "Ntilde", 0x00D1 }, { "Nu", 0x039D }, { "OElig", 0x0152 },
1616
  { "Oacute", 0x00D3 }, { "Ocirc", 0x00D4 }, { "Ograve", 0x00D2 }, { "Omega", 0x03A9 }, { "Omicron", 0x039F }, { "Oslash", 0x00D8 }, { "Otilde", 0x00D5 }, { "Ouml", 0x00D6 },
1617
  { "Phi", 0x03A6 }, { "Pi", 0x03A0 }, { "Prime", 0x2033 }, { "Psi", 0x03A8 }, { "Rho", 0x03A1 }, { "Scaron", 0x0160 }, { "Sigma", 0x03A3 }, { "THORN", 0x00DE },
1618
  { "Tau", 0x03A4 }, { "Theta", 0x0398 }, { "Uacute", 0x00DA }, { "Ucirc", 0x00DB }, { "Ugrave", 0x00D9 }, { "Upsilon", 0x03A5 }, { "Uuml", 0x00DC }, { "Xi", 0x039E },
1619
  { "Yacute", 0x00DD }, { "Yuml", 0x0178 }, { "Zeta", 0x0396 }, { "aacute", 0x00E1 }, { "acirc", 0x00E2 }, { "acute", 0x00B4 }, { "aelig", 0x00E6 }, { "agrave", 0x00E0 },
1620
  { "alefsym", 0x2135 }, { "alpha", 0x03B1 }, { "amp", 0x0026 }, { "and", 0x2227 }, { "ang", 0x2220 }, { "apos", 0x0027 }, { "aring", 0x00E5 }, { "asymp", 0x2248 },
1621
  { "atilde", 0x00E3 }, { "auml", 0x00E4 }, { "bdquo", 0x201E }, { "beta", 0x03B2 }, { "brvbar", 0x00A6 }, { "bull", 0x2022 }, { "cap", 0x2229 }, { "ccedil", 0x00E7 },
1622
  { "cedil", 0x00B8 }, { "cent", 0x00A2 }, { "chi", 0x03C7 }, { "circ", 0x02C6 }, { "clubs", 0x2663 }, { "cong", 0x2245 }, { "copy", 0x00A9 }, { "crarr", 0x21B5 },
1623
  { "cup", 0x222A }, { "curren", 0x00A4 }, { "dArr", 0x21D3 }, { "dagger", 0x2020 }, { "darr", 0x2193 }, { "deg", 0x00B0 }, { "delta", 0x03B4 }, { "diams", 0x2666 },
1624
  { "divide", 0x00F7 }, { "eacute", 0x00E9 }, { "ecirc", 0x00EA }, { "egrave", 0x00E8 }, { "empty", 0x2205 }, { "emsp", 0x2003 }, { "ensp", 0x2002 }, { "epsilon", 0x03B5 },
1625
  { "equiv", 0x2261 }, { "eta", 0x03B7 }, { "eth", 0x00F0 }, { "euml", 0x00EB }, { "euro", 0x20AC }, { "exist", 0x2203 }, { "fnof", 0x0192 }, { "forall", 0x2200 },
1626
  { "frac12", 0x00BD }, { "frac14", 0x00BC }, { "frac34", 0x00BE }, { "frasl", 0x2044 }, { "gamma", 0x03B3 }, { "ge", 0x2265 }, { "gt", 0x003E }, { "hArr", 0x21D4 },
1627
  { "harr", 0x2194 }, { "hearts", 0x2665 }, { "hellip", 0x2026 }, { "iacute", 0x00ED }, { "icirc", 0x00EE }, { "iexcl", 0x00A1 }, { "igrave", 0x00EC }, { "image", 0x2111 },
1628
  { "infin", 0x221E }, { "int", 0x222B }, { "iota", 0x03B9 }, { "iquest", 0x00BF }, { "isin", 0x2208 }, { "iuml", 0x00EF }, { "kappa", 0x03BA }, { "lArr", 0x21D0 },
1629
  { "lambda", 0x03BB }, { "lang", 0x2329 }, { "laquo", 0x00AB }, { "larr", 0x2190 }, { "lceil", 0x2308 }, { "ldquo", 0x201C }, { "le", 0x2264 }, { "lfloor", 0x230A },
1630
  { "lowast", 0x2217 }, { "loz", 0x25CA }, { "lrm", 0x200E }, { "lsaquo", 0x2039 }, { "lsquo", 0x2018 }, { "lt", 0x003C }, { "macr", 0x00AF }, { "mdash", 0x2014 },
1631
  { "micro", 0x00B5 }, { "middot", 0x00B7 }, { "minus", 0x2212 }, { "mu", 0x03BC }, { "nabla", 0x2207 }, { "nbsp", 0x00A0 }, { "ndash", 0x2013 }, { "ne", 0x2260 },
1632
  { "ni", 0x220B }, { "not", 0x00AC }, { "notin", 0x2209 }, { "nsub", 0x2284 }, { "ntilde", 0x00F1 }, { "nu", 0x03BD }, { "oacute", 0x00F3 }, { "ocirc", 0x00F4 },
1633
  { "oelig", 0x0153 }, { "ograve", 0x00F2 }, { "oline", 0x203E }, { "omega", 0x03C9 }, { "omicron", 0x03BF }, { "oplus", 0x2295 }, { "or", 0x2228 }, { "ordf", 0x00AA },
1634
  { "ordm", 0x00BA }, { "oslash", 0x00F8 }, { "otilde", 0x00F5 }, { "otimes", 0x2297 }, { "ouml", 0x00F6 }, { "para", 0x00B6 }, { "part", 0x2202 }, { "permil", 0x2030 },
1635
  { "perp", 0x22A5 }, { "phi", 0x03C6 }, { "pi", 0x03C0 }, { "piv", 0x03D6 }, { "plusmn", 0x00B1 }, { "pound", 0x00A3 }, { "prime", 0x2032 }, { "prod", 0x220F },
1636
  { "prop", 0x221D }, { "psi", 0x03C8 }, { "quot", 0x0022 }, { "rArr", 0x21D2 }, { "radic", 0x221A }, { "rang", 0x232A }, { "raquo", 0x00BB }, { "rarr", 0x2192 },
1637
  { "rceil", 0x2309 }, { "rdquo", 0x201D }, { "real", 0x211C }, { "reg", 0x00AE }, { "rfloor", 0x230B }, { "rho", 0x03C1 }, { "rlm", 0x200F }, { "rsaquo", 0x203A },
1638
  { "rsquo", 0x2019 }, { "sbquo", 0x201A }, { "scaron", 0x0161 }, { "sdot", 0x22C5 }, { "sect", 0x00A7 }, { "shy", 0x00AD }, { "sigma", 0x03C3 }, { "sigmaf", 0x03C2 },
1639
  { "sim", 0x223C }, { "spades", 0x2660 }, { "sub", 0x2282 }, { "sube", 0x2286 }, { "sum", 0x2211 }, { "sup", 0x2283 }, { "sup1", 0x00B9 }, { "sup2", 0x00B2 },
1640
  { "sup3", 0x00B3 }, { "supe", 0x2287 }, { "szlig", 0x00DF }, { "tau", 0x03C4 }, { "there4", 0x2234 }, { "theta", 0x03B8 }, { "thetasym", 0x03D1 }, { "thinsp", 0x2009 },
1641
  { "thorn", 0x00FE }, { "tilde", 0x02DC }, { "times", 0x00D7 }, { "trade", 0x2122 }, { "uArr", 0x21D1 }, { "uacute", 0x00FA }, { "uarr", 0x2191 }, { "ucirc", 0x00FB },
1642
  { "ugrave", 0x00F9 }, { "uml", 0x00A8 }, { "upsih", 0x03D2 }, { "upsilon", 0x03C5 }, { "uuml", 0x00FC }, { "weierp", 0x2118 }, { "xi", 0x03BE }, { "yacute", 0x00FD },
1643
  { "yen", 0x00A5 }, { "yuml", 0x00FF }, { "zeta", 0x03B6 }, { "zwj", 0x200D }, { "zwnj", 0x200C },
1644
};
1645
1646
int fxCompareEntities(const void *name, const void *entity)
1647
287k
{
1648
287k
  return c_strcmp((char*)name, ((txEntity*)entity)->name);
1649
287k
}
1650
1651
txString fxGetNextEntity(txParser* parser, txString p, txString q)
1652
42.2k
{
1653
42.2k
  txString r = p;
1654
42.2k
  txU4 t = 0;
1655
42.2k
    if (p < q) *p++ = '&';
1656
42.2k
  fxGetNextCharacter(parser);
1657
42.2k
  if (parser->character == '#') {
1658
6.18k
    if (p < q) *p++ = '#';
1659
6.18k
    fxGetNextCharacter(parser);
1660
6.18k
    if (parser->character == 'x') {
1661
3.52k
      if (p < q) *p++ = 'x';
1662
3.52k
      fxGetNextCharacter(parser);
1663
28.0k
      while (fxGetNextStringX(parser->character, &t)) {
1664
24.4k
        if (p < q) *p++ = parser->character;
1665
24.4k
        fxGetNextCharacter(parser);
1666
24.4k
      }
1667
3.52k
    }
1668
2.65k
    else {
1669
10.2k
      while (fxGetNextStringD(parser->character, &t)) {
1670
7.55k
        if (p < q) *p++ = parser->character;
1671
7.55k
        fxGetNextCharacter(parser);
1672
7.55k
      }
1673
2.65k
    }
1674
6.18k
  }
1675
36.0k
  else {
1676
36.0k
    txEntity* entity = C_NULL;
1677
36.0k
    int c = parser->character;
1678
51.6k
    while ((p < q) && ((('0' <= c) && (c <= '9')) || (('A' <= c) && (c <= 'Z')) || (('a' <= c) && (c <= 'z')))) {
1679
15.5k
      if (p < q) *p++ = c;
1680
15.5k
      fxGetNextCharacter(parser);
1681
15.5k
      c = parser->character;
1682
15.5k
    }
1683
36.0k
    *p = 0;
1684
36.0k
        if (r < q)
1685
36.0k
            entity = (txEntity*)c_bsearch(r + 1, gxEntities, XS_ENTITIES_COUNT, sizeof(txEntity), fxCompareEntities);
1686
36.0k
    t = entity ? entity->value : 0;
1687
36.0k
  }
1688
42.2k
  if (parser->character == ';') {
1689
2.91k
    if (p < q) *p++ = ';';
1690
2.91k
    fxGetNextCharacter(parser);
1691
2.91k
    if (t)
1692
2.50k
      p = fxUTF8Buffer(parser, t, r, q);
1693
2.91k
  }
1694
42.2k
  return p;
1695
42.2k
}
1696
1697
void fxGetNextTokenJSXAttribute(txParser* parser)
1698
1.69k
{
1699
1.69k
  txString p = parser->buffer;
1700
1.69k
  txString q = p + parser->bufferSize - 1;
1701
1.69k
  txU4 quote = 0;
1702
1.69k
  parser->states[2].crlf = 0;
1703
1.69k
  parser->states[2].escaped = 0;
1704
1.69k
  parser->states[2].integer = 0;
1705
1.69k
  parser->states[2].modifierLength = 0;
1706
1.69k
  parser->states[2].modifier = parser->emptyString;
1707
1.69k
  parser->states[2].number = 0;
1708
1.69k
  parser->states[2].rawLength = 0;
1709
1.69k
  parser->states[2].raw = parser->emptyString;
1710
1.69k
  parser->states[2].stringLength = 0;
1711
1.69k
  parser->states[2].string = parser->emptyString;
1712
1.69k
  parser->states[2].symbol = C_NULL;
1713
1.69k
  parser->states[2].token = XS_NO_TOKEN;
1714
955k
  while (parser->states[2].token == XS_NO_TOKEN) {
1715
954k
    switch (parser->character) {
1716
764
    case C_EOF:
1717
764
      parser->states[2].token = XS_TOKEN_EOF;
1718
764
      break;
1719
10.3k
    case 10:  
1720
10.4k
    case 0x2028: // <LS>
1721
10.6k
    case 0x2029: // <PS>  
1722
10.6k
      parser->states[2].line++;
1723
10.6k
      if (quote)
1724
10.5k
        p = fxUTF8Buffer(parser, parser->character, p, q);
1725
10.6k
      fxGetNextCharacter(parser);
1726
10.6k
      parser->states[2].crlf = 1;
1727
10.6k
      break;
1728
91.0k
    case 13:  
1729
91.0k
      parser->states[2].line++;
1730
91.0k
      if (quote)
1731
90.7k
        p = fxUTF8Buffer(parser, parser->character, p, q);
1732
91.0k
      fxGetNextCharacter(parser);
1733
91.0k
      if (parser->character == 10) {
1734
701
        if (quote)
1735
613
          p = fxUTF8Buffer(parser, parser->character, p, q);
1736
701
        fxGetNextCharacter(parser);
1737
701
      }
1738
91.0k
      parser->states[2].crlf = 1;
1739
91.0k
      break;
1740
4.66k
    case '\t':
1741
6.66k
    case 11:
1742
7.70k
    case 12:
1743
42.3k
    case ' ':
1744
42.5k
    case 0x00A0:
1745
43.4k
    case 0x1680:
1746
43.6k
    case 0x2000:
1747
43.8k
    case 0x2001:
1748
43.8k
    case 0x2002:
1749
44.1k
    case 0x2003:
1750
44.2k
    case 0x2004:
1751
44.5k
    case 0x2005:
1752
44.8k
    case 0x2006:
1753
44.8k
    case 0x2007:
1754
44.9k
    case 0x2008:
1755
45.1k
    case 0x2009:
1756
45.5k
    case 0x200A:
1757
45.7k
    case 0x202F:
1758
45.7k
    case 0x205F:
1759
45.7k
    case 0x3000:
1760
45.8k
    case 0xFEFF:
1761
45.8k
      if (quote)
1762
45.1k
        p = fxUTF8Buffer(parser, parser->character, p, q);
1763
45.8k
      fxGetNextCharacter(parser);
1764
45.8k
      break;
1765
      
1766
954
    case '{':
1767
954
      if (quote)
1768
733
        p = fxUTF8Buffer(parser, parser->character, p, q);
1769
221
      else
1770
221
        parser->states[2].token = XS_TOKEN_LEFT_BRACE;
1771
954
      fxGetNextCharacter(parser);
1772
954
      break;
1773
      
1774
1.06k
    case '"':
1775
32.2k
    case '\'':
1776
32.2k
      if (quote) {
1777
31.0k
        if (quote == parser->character) {
1778
402
          parser->states[2].stringLength = mxPtrDiff(p - parser->buffer);
1779
402
          parser->states[2].string = fxNewParserString(parser, parser->buffer, parser->states[2].stringLength);
1780
402
          parser->states[2].token = XS_TOKEN_STRING;
1781
402
        }
1782
30.6k
        else
1783
30.6k
          p = fxUTF8Buffer(parser, parser->character, p, q);
1784
31.0k
      }
1785
1.17k
      else
1786
1.17k
        quote = parser->character;
1787
32.2k
      fxGetNextCharacter(parser);
1788
32.2k
      break;
1789
      
1790
38.1k
    case '&':
1791
38.1k
      if (quote)
1792
38.1k
        p = fxGetNextEntity(parser, p, q);
1793
2
      else {
1794
2
        fxReportParserError(parser, parser->states[2].line, "invalid character %d", parser->character);
1795
2
        fxGetNextCharacter(parser);
1796
2
      }
1797
38.1k
      break;
1798
      
1799
734k
    default:
1800
734k
      if (quote)
1801
734k
        p = fxUTF8Buffer(parser, parser->character, p, q);
1802
281
      else
1803
281
        fxReportParserError(parser, parser->states[2].line, "invalid character %d", parser->character);
1804
734k
      fxGetNextCharacter(parser);
1805
734k
      break; 
1806
954k
    } 
1807
954k
  }
1808
1.38k
  parser->states[0] = parser->states[2];
1809
1.38k
  parser->ahead = 0;
1810
1.38k
}
1811
1812
void fxGetNextTokenJSXChild(txParser* parser)
1813
103k
{
1814
103k
  txString p = parser->buffer;
1815
103k
  txString q = p + parser->bufferSize - 1;
1816
103k
  txString s = C_NULL;
1817
103k
  char c;
1818
103k
  txString after = C_NULL;
1819
103k
  txString before = C_NULL;
1820
103k
  txString text = C_NULL;
1821
103k
  parser->states[2].crlf = 0;
1822
103k
  parser->states[2].escaped = 0;
1823
103k
  parser->states[2].integer = 0;
1824
103k
  parser->states[2].modifierLength = 0;
1825
103k
  parser->states[2].modifier = parser->emptyString;
1826
103k
  parser->states[2].number = 0;
1827
103k
  parser->states[2].rawLength = 0;
1828
103k
  parser->states[2].raw = parser->emptyString;
1829
103k
  parser->states[2].stringLength = 0;
1830
103k
  parser->states[2].string = parser->emptyString;
1831
103k
  parser->states[2].symbol = C_NULL;
1832
103k
  parser->states[2].token = XS_NO_TOKEN;
1833
1.60M
  while (parser->states[2].token == XS_NO_TOKEN) {
1834
1.50M
    switch (parser->character) {
1835
558
    case C_EOF:
1836
558
      parser->states[2].token = XS_TOKEN_EOF;
1837
558
      break;
1838
17.6k
    case 10:  
1839
18.0k
    case 0x2028: // <LS>
1840
19.1k
    case 0x2029: // <PS>  
1841
19.1k
      parser->states[2].line++;
1842
19.1k
      p = fxUTF8Buffer(parser, parser->character, p, q);
1843
19.1k
      fxGetNextCharacter(parser);
1844
19.1k
      parser->states[2].crlf = 1;
1845
19.1k
      break;
1846
6.76k
    case 13:  
1847
6.76k
      parser->states[2].line++;
1848
6.76k
      p = fxUTF8Buffer(parser, parser->character, p, q);
1849
6.76k
      fxGetNextCharacter(parser);
1850
6.76k
      if (parser->character == 10) {
1851
6.05k
        p = fxUTF8Buffer(parser, parser->character, p, q);
1852
6.05k
        fxGetNextCharacter(parser);
1853
6.05k
      }
1854
6.76k
      parser->states[2].crlf = 1;
1855
6.76k
      break;
1856
      
1857
83.3k
    case '<':
1858
83.3k
      fxGetNextCharacter(parser);
1859
83.3k
      parser->states[2].token = XS_TOKEN_LESS;
1860
83.3k
      break;
1861
1.89k
    case '>':
1862
1.89k
      fxGetNextCharacter(parser);
1863
1.89k
      parser->states[2].token = XS_TOKEN_MORE;
1864
1.89k
      break;
1865
13.5k
    case '{':
1866
13.5k
      fxGetNextCharacter(parser);
1867
13.5k
      parser->states[2].token = XS_TOKEN_LEFT_BRACE;
1868
13.5k
      break;
1869
3.76k
    case '}':
1870
3.76k
      fxGetNextCharacter(parser);
1871
3.76k
      parser->states[2].token = XS_TOKEN_RIGHT_BRACE;
1872
3.76k
      break;
1873
4.11k
    case '&':
1874
4.11k
      p = fxGetNextEntity(parser, p, q);
1875
4.11k
      break;
1876
1.37M
    default:
1877
1.37M
      p = fxUTF8Buffer(parser, parser->character, p, q);
1878
1.37M
      fxGetNextCharacter(parser);
1879
1.37M
      break; 
1880
1.50M
    } 
1881
1.50M
  }
1882
103k
  parser->states[2].rawLength = mxPtrDiff(p - parser->buffer);
1883
103k
  parser->states[2].raw = fxNewParserString(parser, parser->buffer, parser->states[2].rawLength);
1884
103k
  if (parser->states[2].crlf) {
1885
8.54k
    p = parser->buffer;
1886
8.54k
    q = p + parser->bufferSize - 1;
1887
8.54k
    s = parser->states[2].raw;
1888
8.54k
    c = *s++;
1889
977k
    while (c) {
1890
969k
      if ((c == 10) || (c == 13)) {
1891
18.7k
        if (before)
1892
6.35k
          p = before;
1893
12.3k
        else
1894
12.3k
          before = p;
1895
18.7k
        after = p;
1896
18.7k
      }
1897
950k
      else if ((c == 9) || (c == 32)) {
1898
66.9k
        if (!before)
1899
44.7k
          before = p;
1900
66.9k
        *p++ = c;
1901
66.9k
      }
1902
883k
      else {
1903
883k
        if (after) {
1904
12.1k
          p = after;
1905
12.1k
          if (text)
1906
10.5k
            *p++ = 32;
1907
12.1k
        }
1908
883k
        after = C_NULL;
1909
883k
        before = C_NULL;
1910
883k
        text = p;
1911
883k
        *p++ = c;
1912
883k
      }
1913
969k
      c = *s++;
1914
969k
    }
1915
8.54k
    if (after)
1916
3.78k
      p = after;
1917
8.54k
  }
1918
103k
  parser->states[2].stringLength = mxPtrDiff(p - parser->buffer);
1919
103k
  parser->states[2].string = fxNewParserString(parser, parser->buffer, parser->states[2].stringLength);
1920
  
1921
103k
  parser->states[0] = parser->states[2];
1922
103k
  parser->ahead = 0;
1923
103k
}
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939