Coverage Report

Created: 2025-12-14 06:18

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
1.63M
#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
119k
#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
17.4M
{
114
17.4M
  if (string + mxStringByteLength(character) > limit) {
115
15
    fxReportMemoryError(parser, parser->states[2].line, "buffer overflow");
116
15
  }
117
17.4M
  return mxStringByteEncode(string, character);
118
17.4M
} 
119
120
void fxCheckStrictKeyword(txParser* parser)
121
8.05k
{
122
8.05k
  int low, high, anIndex, aDelta;
123
30.6k
  for (low = 0, high = XS_STRICT_KEYWORD_COUNT; high > low;
124
24.0k
      (aDelta < 0) ? (low = anIndex + 1) : (high = anIndex)) {
125
24.0k
    anIndex = low + ((high - low) / 2);
126
24.0k
    aDelta = c_strcmp(gxStrictKeywords[anIndex].text, parser->buffer);
127
24.0k
    if (aDelta == 0) {
128
1.43k
      parser->states[0].token = gxStrictKeywords[anIndex].token;
129
1.43k
      goto bail;
130
1.43k
    }
131
24.0k
  }
132
8.05k
bail:
133
8.05k
  if (parser->states[0].escaped)
134
0
    fxReportParserError(parser, parser->states[0].line, "escaped keyword");     
135
8.05k
}
136
137
void fxGetNextCharacter(txParser* parser)
138
53.2M
{
139
53.2M
  parser->character = parser->lookahead;
140
53.2M
  if (parser->character != (txU4)C_EOF) {
141
53.1M
  #if mxCESU8
142
53.1M
    txU4 character = parser->surrogate;
143
53.1M
    if (character)
144
6.71k
      parser->surrogate = 0;
145
53.1M
    else
146
53.1M
      character = fxGetNextCode(parser);
147
53.1M
    if ((0x0000D800 <= character) && (character <= 0x0000DBFF)) {
148
21.2k
      txU4 surrogate = fxGetNextCode(parser);
149
21.2k
      if ((0x0000DC00 <= surrogate) && (surrogate <= 0x0000DFFF))
150
14.4k
        character = 0x00010000 + ((character & 0x000003FF) << 10) + (surrogate & 0x000003FF);
151
6.72k
      else
152
6.72k
        parser->surrogate = surrogate;
153
21.2k
    }
154
53.1M
    parser->lookahead = character;
155
  #else
156
    parser->lookahead = fxGetNextCode(parser);
157
  #endif
158
53.1M
  }
159
53.2M
}
160
161
txU4 fxGetNextCode(txParser* parser)
162
53.1M
{
163
53.1M
  txU4 code = (txU4)(*(parser->getter))(parser->stream);
164
53.1M
  if ((code & 0x80) && (code != (txU4)C_EOF)) {
165
8.50M
    txUTF8Sequence const *sequence = NULL;
166
23.5M
    for (sequence = gxUTF8Sequences; sequence->size; sequence++) {
167
23.5M
      if ((code & sequence->cmask) == sequence->cval)
168
8.50M
        break;
169
23.5M
    }
170
8.50M
    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
8.50M
    else {
175
8.50M
      txS4 size = sequence->size - 1;
176
23.5M
      while (size) {
177
15.0M
        size--;
178
15.0M
        code = (code << 6) | ((*(parser->getter))(parser->stream) & 0x3F);
179
15.0M
      }
180
8.50M
      code &= sequence->lmask;
181
8.50M
    }
182
8.50M
    if (code == 0x000110000)
183
0
      code = 0;
184
8.50M
  }
185
53.1M
  return code;
186
53.1M
}
187
188
txString fxGetNextDigits(txParser* parser, txString (*f)(txParser*, txString, txString), txString p, txString q, int empty)
189
355k
{
190
355k
  int separator = 0;
191
357k
  for (;;) {
192
357k
    txString r = p;
193
357k
    p = (*f)(parser, p, q);
194
357k
    if (r < p) {
195
346k
      empty = 0;
196
346k
      separator = 0;
197
346k
      if (parser->character == '_') {
198
2.20k
        fxGetNextCharacter(parser);
199
2.20k
        separator = 1;
200
2.20k
      }
201
344k
      else
202
344k
        break;
203
346k
    }
204
11.6k
    else
205
11.6k
      break;
206
357k
  }
207
355k
  if (empty || separator)
208
2.85k
    fxReportParserError(parser, parser->states[2].line, "invalid number"); 
209
355k
  return p;
210
355k
}
211
212
txString fxGetNextDigitsB(txParser* parser, txString p, txString q)
213
190
{
214
190
  int c = parser->character;
215
2.34k
  while (('0' <= c) && (c <= '1')) {
216
2.15k
    if (p < q) *p++ = (char)c;
217
2.15k
    fxGetNextCharacter(parser);
218
2.15k
    c = parser->character;
219
2.15k
  }
220
190
  return p;
221
190
}
222
223
txString fxGetNextDigitsD(txParser* parser, txString p, txString q, int* base)
224
4.27k
{
225
4.27k
  int c = parser->character;
226
4.27k
  *base = 8;
227
181k
  while (('0' <= c) && (c <= '9')) {
228
176k
    if (p < q) *p++ = (char)c;
229
176k
    if (('8' <= c) && (c <= '9'))
230
1.15k
      *base = 10;
231
176k
    fxGetNextCharacter(parser);
232
176k
    c = parser->character;
233
176k
  }
234
4.27k
  return p;
235
4.27k
}
236
237
txString fxGetNextDigitsE(txParser* parser, txString p, txString q)
238
224k
{
239
224k
  int c = parser->character;
240
1.12M
  while (('0' <= c) && (c <= '9')) {
241
900k
    if (p < q) *p++ = (char)c;
242
900k
    fxGetNextCharacter(parser);
243
900k
    c = parser->character;
244
900k
  }
245
224k
  return p;
246
224k
}
247
248
txString fxGetNextDigitsO(txParser* parser, txString p, txString q)
249
409
{
250
409
  int c = parser->character;
251
1.91k
  while (('0' <= c) && (c <= '7')) {
252
1.50k
    if (p < q) *p++ = (char)c;
253
1.50k
    fxGetNextCharacter(parser);
254
1.50k
    c = parser->character;
255
1.50k
  }
256
409
  return p;
257
409
}
258
259
txString fxGetNextDigitsX(txParser* parser, txString p, txString q)
260
132k
{
261
132k
  int c = parser->character;
262
991k
  while ((('0' <= c) && (c <= '9')) || (('a' <= c) && (c <= 'f')) || (('A' <= c) && (c <= 'F'))) {
263
858k
    if (p < q) *p++ = (char)c;
264
858k
    fxGetNextCharacter(parser);
265
858k
    c = parser->character;
266
858k
  }
267
132k
  return p;
268
132k
}
269
270
void fxGetNextKeyword(txParser* parser)
271
1.83M
{
272
1.83M
  int low, high, anIndex, aDelta;
273
  
274
1.83M
  parser->states[2].symbol = fxNewParserSymbol(parser, parser->buffer);
275
1.83M
  parser->states[2].token = XS_TOKEN_IDENTIFIER;
276
1.83M
  if ((parser->states[0].token == XS_TOKEN_DOT) || (parser->states[0].token == XS_TOKEN_CHAIN))
277
198k
    return;
278
9.50M
  for (low = 0, high = XS_KEYWORD_COUNT; high > low;
279
8.34M
      (aDelta < 0) ? (low = anIndex + 1) : (high = anIndex)) {
280
8.34M
    anIndex = low + ((high - low) / 2);
281
8.34M
    aDelta = c_strcmp(gxKeywords[anIndex].text, parser->buffer);
282
8.34M
    if (aDelta == 0) {
283
467k
      parser->states[2].token = gxKeywords[anIndex].token;
284
467k
      return;
285
467k
    }
286
8.34M
  }
287
1.16M
  if ((parser->flags & mxStrictFlag)) {
288
328k
    for (low = 0, high = XS_STRICT_KEYWORD_COUNT; high > low;
289
288k
        (aDelta < 0) ? (low = anIndex + 1) : (high = anIndex)) {
290
288k
      anIndex = low + ((high - low) / 2);
291
288k
      aDelta = c_strcmp(gxStrictKeywords[anIndex].text, parser->buffer);
292
288k
      if (aDelta == 0) {
293
71.1k
        parser->states[2].token = gxStrictKeywords[anIndex].token;
294
71.1k
        return;
295
71.1k
      }
296
288k
    }
297
111k
  }
298
1.09M
  if (c_strcmp("await", parser->buffer) == 0) {
299
1.00k
    if (parser->flags & mxAsyncFlag) {
300
484
      parser->states[2].token = XS_TOKEN_AWAIT;
301
484
      return;
302
484
    }
303
1.00k
  }  
304
1.09M
  if (c_strcmp("yield", parser->buffer) == 0) {
305
4.09k
    if ((parser->flags & mxGeneratorFlag)){
306
2.22k
      parser->states[2].token = XS_TOKEN_YIELD;
307
2.22k
      return;
308
2.22k
    }
309
4.09k
  }  
310
1.09M
  return;
311
1.09M
}
312
313
txBoolean fxGetNextIdentiferX(txParser* parser, txU4* value)
314
2.81k
{
315
2.81k
  fxGetNextCharacter(parser);
316
2.81k
  if (parser->character == 'u') {
317
2.65k
    fxGetNextCharacter(parser);
318
2.65k
    if (parser->character == '{') {
319
763
      fxGetNextCharacter(parser);
320
6.87k
      while (fxGetNextStringX(parser->character, value)) {
321
6.11k
        fxGetNextCharacter(parser);
322
6.11k
      }
323
763
      if (parser->character == '}') {
324
145
        fxGetNextCharacter(parser);
325
145
        return 1;
326
145
      }
327
763
    }
328
1.89k
    else {
329
1.89k
      if (fxGetNextStringX(parser->character, value)) {
330
1.60k
        fxGetNextCharacter(parser);
331
1.60k
        if (fxGetNextStringX(parser->character, value)) {
332
1.59k
          fxGetNextCharacter(parser);
333
1.59k
          if (fxGetNextStringX(parser->character, value)) {
334
982
            fxGetNextCharacter(parser);
335
982
            if (fxGetNextStringX(parser->character, value)) {
336
456
              fxGetNextCharacter(parser);
337
456
              return 1;
338
456
            }    
339
982
          }    
340
1.59k
        }    
341
1.60k
      }    
342
1.89k
    }    
343
2.65k
  }
344
2.20k
  return 0;
345
2.81k
}
346
347
void fxGetNextNumber(txParser* parser, txNumber theNumber)
348
314k
{
349
314k
  parser->states[2].number = theNumber;
350
314k
  parser->states[2].integer = (txInteger)parser->states[2].number;
351
314k
  theNumber = parser->states[2].integer;
352
314k
  if (parser->states[2].number == theNumber)
353
295k
    parser->states[2].token = XS_TOKEN_INTEGER;
354
18.4k
  else
355
18.4k
    parser->states[2].token = XS_TOKEN_NUMBER;
356
314k
}
357
358
void fxGetNextNumberB(txParser* parser)
359
169
{
360
169
  txString p = parser->buffer;
361
169
  txString q = p + parser->bufferSize;
362
169
  int c;
363
169
  fxGetNextCharacter(parser);
364
169
  p = fxGetNextDigits(parser, fxGetNextDigitsB, p, q, 1);
365
169
  c = parser->character;
366
169
  if (p == q) {
367
0
    fxReportMemoryError(parser, parser->states[2].line, "number overflow");
368
0
  }
369
169
  if (c == 'n')
370
17
    fxGetNextCharacter(parser);
371
169
  if (fxIsIdentifierFirst(parser->character)) {
372
10
    fxReportParserError(parser, parser->states[2].line, "invalid number");
373
10
  }
374
169
  *p = 0;
375
169
  q = parser->buffer;
376
169
  if (c == 'n') {
377
17
    parser->states[2].bigint.data = fxNewParserChunk(parser, fxBigIntMaximumB(mxPtrDiff(p - q)));
378
17
    fxBigIntParseB(&parser->states[2].bigint, q, mxPtrDiff(p - q));
379
17
    parser->states[2].token = XS_TOKEN_BIGINT;
380
17
  }
381
152
  else {
382
152
    txNumber n = 0;
383
1.15k
    while ((c = *q++))
384
1.00k
      n = (n * 2) + (c - '0');
385
152
    fxGetNextNumber(parser, n);
386
152
  }
387
169
}
388
389
void fxGetNextNumberE(txParser* parser, int dot)
390
204k
{
391
204k
  txString p = parser->buffer;
392
204k
  txString q = p + parser->bufferSize;
393
204k
  txString r;
394
204k
  int c;
395
204k
  if (dot) {
396
6.02k
    if (p < q) *p++ = '.';
397
6.02k
  }
398
204k
  p = fxGetNextDigits(parser, fxGetNextDigitsE, p, q, 0); 
399
204k
  if (dot)
400
6.02k
    r = p;
401
198k
  else if (parser->character == '.') {
402
11.3k
    dot = 1;
403
11.3k
    if (p < q) *p++ = '.';
404
11.3k
    fxGetNextCharacter(parser);
405
11.3k
    p = fxGetNextDigits(parser, fxGetNextDigitsE, p, q, 0); 
406
11.3k
    r = p;
407
11.3k
  }
408
204k
  c = parser->character;
409
204k
  if ((c == 'e') || (c == 'E')) {
410
6.38k
    if (dot) {
411
3.72k
      if (p == r) {
412
3.72k
        if (p < q) *p++ = '0';
413
3.72k
      }
414
3.72k
    }
415
2.66k
    else {
416
2.66k
      dot = 1;
417
2.66k
      if (p < q) *p++ = '.';
418
2.66k
      if (p < q) *p++ = '0';
419
2.66k
    }
420
6.38k
    if (p < q) *p++ = (char)c;
421
6.38k
    fxGetNextCharacter(parser);
422
6.38k
    c = parser->character;
423
6.38k
    if ((c == '+') || (c == '-')) {
424
2.52k
      if (p < q) *p++ = (char)c;
425
2.52k
      fxGetNextCharacter(parser);
426
2.52k
      c = parser->character;
427
2.52k
    }
428
6.38k
    p = fxGetNextDigits(parser, fxGetNextDigitsE, p, q, 1);
429
6.38k
    c = parser->character;
430
6.38k
  }
431
204k
  if (p == q) {
432
5
    fxReportMemoryError(parser, parser->states[2].line, "number overflow");
433
5
  }
434
204k
  if (c == 'n')
435
20.9k
    fxGetNextCharacter(parser);
436
204k
  if (fxIsIdentifierFirst(parser->character)) {
437
2.01k
    fxReportParserError(parser, parser->states[2].line, "invalid number");
438
2.01k
  }
439
204k
  *p = 0;
440
204k
  q = parser->buffer;
441
204k
  if (c == 'n') {
442
20.6k
    if (dot == 0) {
443
20.5k
      parser->states[2].bigint.data = fxNewParserChunk(parser, fxBigIntMaximum(mxPtrDiff(p - q)));
444
20.5k
      fxBigIntParse(&parser->states[2].bigint, q, mxPtrDiff(p - q), 0);
445
20.5k
      parser->states[2].token = XS_TOKEN_BIGINT;
446
20.5k
    }
447
42
    else
448
42
      fxReportParserError(parser, parser->states[2].line, "invalid number");     
449
20.6k
  }  
450
184k
  else
451
184k
    fxGetNextNumber(parser, fxStringToNumber(parser->console, parser->buffer, 1));
452
204k
}
453
454
void fxGetNextNumberO(txParser* parser, int c, int legacy)
455
4.67k
{
456
4.67k
  txString p = parser->buffer;
457
4.67k
  txString q = p + parser->bufferSize;
458
4.67k
  if (legacy) {
459
4.27k
    p = fxGetNextDigitsD(parser, p, q, &legacy);
460
4.27k
    if (parser->character == '_')
461
311
      fxReportParserError(parser, parser->states[2].line, "invalid number");     
462
4.27k
    if (parser->character == 'n')
463
596
      fxReportParserError(parser, parser->states[2].line, "invalid number");     
464
4.27k
  }
465
402
  else {
466
402
    fxGetNextCharacter(parser);
467
402
    legacy = 8;
468
402
    p = fxGetNextDigits(parser, fxGetNextDigitsO, p, q, 1);
469
402
  }
470
4.67k
  c = parser->character;
471
4.67k
  if (p == q) {
472
1
    fxReportMemoryError(parser, parser->states[2].line, "number overflow");
473
1
  }
474
4.67k
  if (c == 'n')
475
104
    fxGetNextCharacter(parser);
476
4.67k
  if (fxIsIdentifierFirst(parser->character)) {
477
786
    fxReportParserError(parser, parser->states[2].line, "invalid number");
478
786
  }
479
4.67k
  *p = 0;
480
4.67k
  q = parser->buffer;
481
4.67k
  if (c == 'n') {
482
104
    parser->states[2].bigint.data = fxNewParserChunk(parser, fxBigIntMaximumO(mxPtrDiff(p - q)));
483
104
    fxBigIntParseO(&parser->states[2].bigint, q, mxPtrDiff(p - q));
484
104
    parser->states[2].token = XS_TOKEN_BIGINT;
485
104
  }
486
4.56k
  else { 
487
4.56k
    txNumber n = 0;
488
44.8k
    while ((c = *q++))
489
40.3k
      n = (n * legacy) + (c - '0');
490
4.56k
    fxGetNextNumber(parser, n);
491
4.56k
  }
492
4.67k
}
493
494
void fxGetNextNumberX(txParser* parser)
495
132k
{
496
132k
  txString p = parser->buffer;
497
132k
  txString q = p + parser->bufferSize;
498
132k
  int c;
499
132k
  fxGetNextCharacter(parser);
500
132k
  p = fxGetNextDigits(parser, fxGetNextDigitsX, p, q, 1);
501
132k
  c = parser->character;
502
132k
  if (p == q) {
503
4
    fxReportMemoryError(parser, parser->states[2].line, "number overflow");
504
4
  }
505
132k
  if (c == 'n')
506
358
    fxGetNextCharacter(parser);
507
132k
  if (fxIsIdentifierFirst(parser->character)) {
508
274
    fxReportParserError(parser, parser->states[2].line, "invalid number");
509
274
  }
510
132k
  *p = 0;
511
132k
  q = parser->buffer;
512
132k
  if (c == 'n') {
513
358
    parser->states[2].bigint.data = fxNewParserChunk(parser, fxBigIntMaximumX(mxPtrDiff(p - q)));
514
358
    fxBigIntParseX(&parser->states[2].bigint, q, mxPtrDiff(p - q));
515
358
    parser->states[2].token = XS_TOKEN_BIGINT;
516
358
  }
517
132k
  else {
518
132k
    txNumber n = 0;
519
708k
    while ((c = *q++)) {
520
576k
      if (('0' <= c) && (c <= '9'))
521
451k
        n = (n * 16) + (c - '0');
522
125k
      else if (('a' <= c) && (c <= 'f'))
523
425
        n = (n * 16) + (10 + c - 'a');
524
124k
      else
525
124k
        n = (n * 16) + (10 + c - 'A');
526
576k
    }
527
132k
    fxGetNextNumber(parser, n);
528
132k
  }
529
132k
}
530
531
void fxGetNextRegExp(txParser* parser, txU4 c)
532
11.0k
{
533
11.0k
  txString p;
534
11.0k
  txString q;
535
11.0k
  txBoolean backslash = 0;
536
11.0k
  txBoolean bracket = 0;
537
11.0k
    txBoolean first = 1;
538
11.0k
    txBoolean second = 1;
539
11.0k
  p = parser->buffer;
540
11.0k
  q = p + parser->bufferSize - 1;
541
11.0k
    if (!c) {
542
10.3k
    c = parser->character;
543
10.3k
        second = 0;
544
10.3k
    }
545
969k
  for (;;) {
546
969k
    if (c == (txU4)C_EOF) {
547
375
      fxReportParserError(parser, parser->states[0].line, "end of file in regular expression");     
548
375
      break;
549
375
    }
550
969k
    else if ((c == 10) || (c == 13) || (c == 0x2028) || (c == 0x2029)) {
551
1.87k
      fxReportParserError(parser, parser->states[0].line, "end of line in regular expression");     
552
1.87k
      break;
553
1.87k
    }
554
967k
    else if (c == '*') {
555
831
      if (first) {
556
4
        fxReportParserError(parser, parser->states[0].line, "invalid regular expression");
557
4
        break;
558
4
      }
559
827
      backslash = 0;
560
827
    }
561
966k
    else if (c == '\\') {
562
16.1k
      if (!backslash)
563
13.3k
        backslash = 1;
564
2.81k
      else
565
2.81k
        backslash = 0;
566
16.1k
    }
567
950k
    else if (c == '[') {
568
22.6k
      if (!backslash)
569
20.8k
        bracket = 1;
570
22.6k
      backslash = 0;
571
22.6k
    }
572
927k
    else if (c == ']') {
573
2.90k
      if (!backslash)
574
2.84k
        bracket = 0;
575
2.90k
      backslash = 0;
576
2.90k
    }
577
924k
    else if (c == '/') {
578
12.1k
      if (!backslash && !bracket)
579
8.81k
        break;
580
3.34k
      backslash = 0;
581
3.34k
    }
582
912k
    else {
583
912k
      backslash = 0;
584
912k
    }
585
958k
    p = fxUTF8Buffer(parser, c, p, q);
586
958k
        if (second)
587
699
            second = 0;
588
957k
        else
589
957k
            fxGetNextCharacter(parser);
590
958k
    c = parser->character;
591
958k
    first = 0;
592
958k
  }
593
11.0k
  *p = 0;
594
11.0k
  parser->states[0].stringLength = mxPtrDiff(p - parser->buffer);
595
11.0k
  parser->states[0].string = fxNewParserString(parser, parser->buffer, parser->states[0].stringLength);
596
11.0k
  p = parser->buffer;
597
11.0k
  q = p + parser->bufferSize - 1;
598
13.2k
  for (;;) {
599
13.2k
    fxGetNextCharacter(parser);
600
13.2k
    if (fxIsIdentifierNext(parser->character))
601
4.40k
      p = fxUTF8Buffer(parser, parser->character, p, q);
602
8.81k
    else 
603
8.81k
      break;
604
13.2k
  }
605
11.0k
  *p = 0;
606
11.0k
  parser->states[0].modifierLength = mxPtrDiff(p - parser->buffer);
607
11.0k
  parser->states[0].modifier = fxNewParserString(parser, parser->buffer, parser->states[0].modifierLength);
608
11.0k
  if (!fxCompileRegExp(parser->console, parser->states[0].string, parser->states[0].modifier, C_NULL, C_NULL, parser->buffer, parser->bufferSize))
609
1.94k
    fxReportParserError(parser, parser->states[0].line, "%s", parser->buffer);
610
11.0k
  parser->states[0].token = XS_TOKEN_REGEXP;
611
11.0k
}
612
613
void fxGetNextString(txParser* parser, int c)
614
362k
{
615
362k
  txString p = parser->buffer;
616
362k
  txString q = p + parser->bufferSize - 1;
617
6.35M
  for (;;) {
618
6.35M
    if (parser->character == (txU4)C_EOF) {
619
274
      fxReportParserError(parser, parser->states[2].line, "end of file in string");     
620
274
      break;
621
274
    }
622
6.35M
    else if (parser->character == 10) {
623
63.9k
      parser->states[2].line++;
624
63.9k
      if (c == '`') {
625
62.4k
        p = fxUTF8Buffer(parser, parser->character, p, q);
626
62.4k
        fxGetNextCharacter(parser);
627
62.4k
      }
628
1.46k
      else {
629
1.46k
        fxReportParserError(parser, parser->states[2].line, "end of line in string");     
630
1.46k
        break;
631
1.46k
      }
632
63.9k
    }
633
6.29M
    else if (parser->character == 13) {
634
16.0k
      parser->states[2].line++;
635
16.0k
      if (c == '`') {
636
15.9k
        p = fxUTF8Buffer(parser, 10, p, q);
637
15.9k
        fxGetNextCharacter(parser);
638
15.9k
        if (parser->character == 10)
639
7.90k
          fxGetNextCharacter(parser);
640
15.9k
      }
641
43
      else {
642
43
        fxReportParserError(parser, parser->states[2].line, "end of line in string");     
643
43
        break;
644
43
      }
645
16.0k
    }
646
6.27M
    else if ((parser->character == 0x2028) || (parser->character == 0x2029)) {
647
255
      parser->states[2].line++;
648
255
      p = fxUTF8Buffer(parser, parser->character, p, q);
649
255
      fxGetNextCharacter(parser);
650
255
    }
651
6.27M
    else if (parser->character == (txU4)c) {
652
358k
      break;
653
358k
    }
654
5.91M
    else if (parser->character == '$') {
655
10.2k
      fxGetNextCharacter(parser);
656
10.2k
      if ((c == '`') && (parser->character == '{'))
657
2.31k
        break;
658
7.94k
      p = fxUTF8Buffer(parser, '$', p, q);
659
7.94k
    }
660
5.90M
    else if (parser->character == '\\') {
661
76.1k
      parser->states[2].escaped = 1;
662
76.1k
      p = fxUTF8Buffer(parser, '\\', p, q);
663
76.1k
      fxGetNextCharacter(parser);
664
76.1k
      switch (parser->character) {
665
532
      case 10:
666
918
      case 0x2028:
667
967
      case 0x2029:
668
967
        parser->states[2].line++;
669
967
        p = fxUTF8Buffer(parser, parser->character, p, q);
670
967
        fxGetNextCharacter(parser);
671
967
        break;
672
258
      case 13:
673
258
        parser->states[2].line++;
674
258
        p = fxUTF8Buffer(parser, 10, p, q);
675
258
        fxGetNextCharacter(parser);
676
258
        if (parser->character == 10)
677
175
          fxGetNextCharacter(parser);
678
258
        break;
679
74.9k
      default:
680
74.9k
        p = fxUTF8Buffer(parser, parser->character, p, q);
681
74.9k
        fxGetNextCharacter(parser);
682
74.9k
        break;
683
76.1k
      } 
684
76.1k
    }  
685
5.83M
    else {
686
5.83M
      p = fxUTF8Buffer(parser, parser->character, p, q);
687
5.83M
      fxGetNextCharacter(parser);
688
5.83M
    }
689
6.35M
  }  
690
362k
  *p = 0;
691
362k
  if (p == q) {
692
0
    fxReportMemoryError(parser, parser->states[2].line, "string overflow");
693
0
  }
694
362k
  parser->states[2].rawLength = mxPtrDiff(p - parser->buffer);
695
362k
  parser->states[2].raw = fxNewParserString(parser, parser->buffer, parser->states[2].rawLength);
696
362k
  if (parser->states[2].escaped) {
697
11.6k
    txInteger character;
698
11.6k
    txString s;
699
11.6k
    txU1* u;
700
11.6k
    p = parser->buffer;
701
11.6k
    q = p + parser->bufferSize - 1; 
702
11.6k
    s = parser->states[2].raw;
703
2.92M
    while (*s) {
704
2.90M
      if (p == q) {
705
0
        fxReportMemoryError(parser, parser->states[2].line, "buffer overflow");
706
0
      }
707
2.90M
      if (*s == '\\') {
708
70.3k
        s++;
709
70.3k
        switch (*s) {
710
0
        case 0:
711
0
          break;
712
444
        case 10:
713
444
          s++;
714
444
          break;
715
0
        case 13:
716
0
          s++;
717
0
          if (*s == 10)
718
0
            s++;
719
0
          break;
720
955
        case 'b':
721
955
          s++;
722
955
          *p++ = '\b';
723
955
          break;
724
216
        case 'f':
725
216
          s++;
726
216
          *p++ = '\f';
727
216
          break;
728
1.93k
        case 'n':
729
1.93k
          s++;
730
1.93k
          *p++ = '\n';
731
1.93k
          break;
732
695
        case 'r':
733
695
          s++;
734
695
          *p++ = '\r';
735
695
          break;
736
489
        case 't':
737
489
          s++;
738
489
          *p++ = '\t';
739
489
          break;
740
226
        case 'v':
741
226
          s++;
742
226
          *p++ = '\v';
743
226
          break;
744
278
        case 'x':
745
278
          s++;
746
278
          if (fxParseHexEscape(&s, &character))
747
262
            p = fxUTF8Buffer(parser, character, p, q);
748
16
          else
749
16
            parser->states[2].escaped |= mxStringErrorFlag;
750
278
          break;
751
23.6k
        case 'u':
752
23.6k
          s++;
753
23.6k
          if (fxParseUnicodeEscape(&s, &character, 1, '\\'))
754
16.5k
            p = fxUTF8Buffer(parser, character, p, q);
755
7.08k
          else
756
7.08k
            parser->states[2].escaped |= mxStringErrorFlag;
757
23.6k
          break;
758
1.34k
        case '0':
759
1.77k
        case '1':
760
1.96k
        case '2':
761
2.05k
        case '3':
762
2.39k
        case '4':
763
2.83k
        case '5':
764
2.92k
        case '6':
765
3.03k
        case '7':
766
3.03k
          character = *s++ - '0';
767
3.03k
          if ((character == 0) && ((*s < '0') || ('9' < *s)))
768
1.06k
            p = fxUTF8Buffer(parser, character, p, q);
769
1.97k
          else { 
770
1.97k
            parser->states[2].escaped |= mxStringLegacyFlag;
771
1.97k
            if ((0 <= character) && (character <= 3)) {
772
991
              if (('0' <= *s) && (*s <= '7'))
773
453
                character = (character * 8) + *s++ - '0';
774
991
            }
775
1.97k
            if (('0' <= *s) && (*s <= '7'))
776
136
              character = (character * 8) + *s++ - '0';
777
1.97k
            p = fxUTF8Buffer(parser, character, p, q);
778
1.97k
          }
779
3.03k
          break;
780
58
        case '8':
781
145
        case '9':
782
145
          parser->states[2].escaped |= mxStringLegacyFlag;
783
145
          *p++ = *s++;
784
145
          break;
785
38.2k
        default:
786
38.2k
          u = (txU1*)s;
787
38.2k
          if ((u[0] == 0xE2) && (u[1] == 0x80) && ((u[2] == 0xA8) || (u[2] == 0xA9))) { /* LS || PS */
788
393
            s += 3;
789
393
          }
790
37.8k
          else
791
37.8k
            *p++ = *s++;
792
38.2k
          break;
793
70.3k
        }
794
70.3k
      }
795
2.83M
      else {
796
2.83M
        *p++ = *s++;
797
2.83M
      }
798
2.90M
    }
799
11.6k
    *p = 0;
800
11.6k
    parser->states[2].stringLength = mxPtrDiff(p - parser->buffer);
801
11.6k
    parser->states[2].string = fxNewParserString(parser, parser->buffer, parser->states[2].stringLength);
802
11.6k
    if ((c == '`') && (parser->states[2].escaped & mxStringLegacyFlag))
803
863
      parser->states[2].escaped |= mxStringErrorFlag;
804
11.6k
  }
805
350k
  else {
806
350k
    parser->states[2].stringLength = parser->states[2].rawLength;
807
350k
    parser->states[2].string = parser->states[2].raw;
808
350k
  }
809
362k
}
810
811
txBoolean fxGetNextStringD(int c, txU4* value)
812
806
{
813
806
  if (('0' <= c) && (c <= '9'))
814
390
    *value = (*value * 10) + (c - '0');
815
416
  else
816
416
    return 0;
817
390
  return 1;
818
806
}
819
820
txBoolean fxGetNextStringX(int c, txU4* value)
821
88.6k
{
822
88.6k
  if (('0' <= c) && (c <= '9'))
823
9.61k
    *value = (*value * 16) + (c - '0');
824
79.0k
  else if (('a' <= c) && (c <= 'f'))
825
30.1k
    *value = (*value * 16) + (10 + c - 'a');
826
48.8k
  else if (('A' <= c) && (c <= 'F'))
827
32.7k
    *value = (*value * 16) + (10 + c - 'A');
828
16.1k
  else
829
16.1k
    return 0;
830
72.5k
  return 1;
831
88.6k
}
832
833
void fxGetNextToken(txParser* parser)
834
15.1M
{
835
15.1M
  if (parser->ahead == 0) {
836
14.6M
    fxGetNextTokenAux(parser);
837
14.6M
    parser->states[0] = parser->states[2];
838
14.6M
  }
839
498k
  else if (parser->ahead == 1) {
840
498k
    parser->states[0] = parser->states[1];
841
498k
    parser->ahead = 0;
842
498k
  }
843
0
  else if (parser->ahead == 2) {
844
0
    parser->states[0] = parser->states[1];
845
0
    parser->states[1] = parser->states[2];
846
0
    parser->ahead = 1;
847
0
  }
848
15.1M
}
849
850
void fxLookAheadOnce(txParser* parser)
851
512k
{
852
512k
  if (parser->ahead == 0) {
853
512k
    fxGetNextTokenAux(parser);
854
512k
    parser->states[1] = parser->states[2];
855
512k
    parser->ahead = 1;
856
512k
  }  
857
512k
}
858
859
void fxLookAheadTwice(txParser* parser)
860
0
{
861
0
  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
0
  else if (parser->ahead == 1) {
868
0
    fxGetNextTokenAux(parser);
869
0
    parser->ahead = 2;
870
0
  }  
871
0
}
872
873
void fxGetNextTokenAux(txParser* parser)
874
15.2M
{
875
15.2M
  int c;
876
15.2M
  txString p;
877
15.2M
  txString q;
878
15.2M
  txU4 t = 0;
879
15.2M
  parser->states[2].crlf = 0;
880
15.2M
  parser->states[2].escaped = 0;
881
15.2M
  parser->states[2].bigint.data = C_NULL;
882
15.2M
  parser->states[2].bigint.size = 0;
883
15.2M
  parser->states[2].bigint.sign = 0;
884
15.2M
  parser->states[2].integer = 0;
885
15.2M
  parser->states[2].modifierLength = 0;
886
15.2M
  parser->states[2].modifier = parser->emptyString;
887
15.2M
  parser->states[2].number = 0;
888
15.2M
  parser->states[2].rawLength = 0;
889
15.2M
  parser->states[2].raw = parser->emptyString;
890
15.2M
  parser->states[2].stringLength = 0;
891
15.2M
  parser->states[2].string = parser->emptyString;
892
15.2M
  parser->states[2].symbol = C_NULL;
893
15.2M
  parser->states[2].token = XS_NO_TOKEN;
894
33.1M
  while (parser->states[2].token == XS_NO_TOKEN) {
895
18.0M
    switch (parser->character) {
896
110k
    case C_EOF:
897
110k
      parser->states[2].token = XS_TOKEN_EOF;
898
110k
      break;
899
906k
    case 10:  
900
907k
    case 0x2028: // <LS>
901
908k
    case 0x2029: // <PS>  
902
908k
      parser->states[2].line++;
903
908k
      fxGetNextCharacter(parser);
904
908k
      parser->states[2].crlf = 1;
905
908k
      break;
906
24.4k
    case 13:  
907
24.4k
      parser->states[2].line++;
908
24.4k
      fxGetNextCharacter(parser);
909
24.4k
      if (parser->character == 10)
910
12.6k
        fxGetNextCharacter(parser);
911
24.4k
      parser->states[2].crlf = 1;
912
24.4k
      break;
913
      
914
74.1k
    case '\t':
915
149k
    case 11:
916
171k
    case 12:
917
1.70M
    case ' ':
918
1.70M
    case 0x00A0:
919
1.70M
    case 0x1680:
920
1.70M
    case 0x2000:
921
1.70M
    case 0x2001:
922
1.70M
    case 0x2002:
923
1.70M
    case 0x2003:
924
1.70M
    case 0x2004:
925
1.71M
    case 0x2005:
926
1.71M
    case 0x2006:
927
1.71M
    case 0x2007:
928
1.71M
    case 0x2008:
929
1.71M
    case 0x2009:
930
1.71M
    case 0x200A:
931
1.71M
    case 0x202F:
932
1.71M
    case 0x205F:
933
1.71M
    case 0x3000:
934
1.71M
    case 0xFEFF:
935
1.71M
      fxGetNextCharacter(parser);
936
1.71M
      break;
937
      
938
4.66M
    case '0':
939
4.66M
      fxGetNextCharacter(parser);
940
4.66M
      c = parser->character;
941
4.66M
      if (c == '.') {
942
6.10k
        fxGetNextCharacter(parser);
943
6.10k
        c = parser->character;
944
6.10k
        if ((('0' <= c) && (c <= '9')) || (c == 'e') || (c == 'E'))
945
3.59k
          fxGetNextNumberE(parser, 1);
946
2.50k
        else {
947
2.50k
          parser->states[2].number = 0;
948
2.50k
          parser->states[2].token = XS_TOKEN_NUMBER;
949
2.50k
        }
950
6.10k
      }
951
4.66M
      else if ((c == 'b') || (c == 'B')) {
952
169
        fxGetNextNumberB(parser);
953
169
      }
954
4.66M
            else if ((c == 'e') || (c == 'E')) {
955
950
                fxGetNextNumberE(parser, 0);
956
950
            }
957
4.65M
            else if (c == 'n') {
958
2.85k
                fxGetNextNumberE(parser, 0);
959
2.85k
            }
960
4.65M
      else if ((c == 'o') || (c == 'O')) {
961
402
        fxGetNextNumberO(parser, '0', 0);
962
402
      }
963
4.65M
      else if ((c == 'x') || (c == 'X')) {
964
132k
        fxGetNextNumberX(parser);
965
132k
      }
966
4.52M
      else if (('0' <= c) && (c <= '9')) {
967
4.27k
        if ((parser->flags & mxStrictFlag))
968
6
          fxReportParserError(parser, parser->states[2].line, "octal number (strict mode)");     
969
4.27k
        fxGetNextNumberO(parser, c, 1);
970
4.27k
      }
971
4.51M
      else {
972
4.51M
        parser->states[2].integer = 0;
973
4.51M
        parser->states[2].token = XS_TOKEN_INTEGER;
974
4.51M
      }
975
4.66M
      break;
976
42.2k
    case '1':
977
83.1k
    case '2':
978
132k
    case '3':
979
146k
    case '4':
980
165k
    case '5':
981
177k
    case '6':
982
184k
    case '7':
983
187k
    case '8':
984
194k
    case '9':
985
194k
      fxGetNextNumberE(parser, 0);
986
194k
      break;
987
205k
    case '.':
988
205k
      fxGetNextCharacter(parser);
989
205k
      c = parser->character;
990
205k
      if (c == '.') { 
991
3.71k
        fxGetNextCharacter(parser);
992
3.71k
        if (parser->character == '.') { 
993
3.35k
          parser->states[2].token = XS_TOKEN_SPREAD;
994
3.35k
          fxGetNextCharacter(parser);
995
3.35k
        }
996
360
        else {
997
360
          fxReportParserError(parser, parser->states[2].line, "invalid character %d", parser->character);
998
360
        }    
999
3.71k
      }    
1000
201k
      else if (('0' <= c) && (c <= '9'))
1001
2.43k
        fxGetNextNumberE(parser, 1);
1002
199k
      else
1003
199k
        parser->states[2].token = XS_TOKEN_DOT;
1004
205k
      break;  
1005
463k
    case ',':
1006
463k
      parser->states[2].token = XS_TOKEN_COMMA;
1007
463k
      fxGetNextCharacter(parser);
1008
463k
      break;  
1009
289k
    case ';':
1010
289k
      parser->states[2].token = XS_TOKEN_SEMICOLON;
1011
289k
      fxGetNextCharacter(parser);
1012
289k
      break;  
1013
121k
    case ':':
1014
121k
      parser->states[2].token = XS_TOKEN_COLON;
1015
121k
      fxGetNextCharacter(parser);
1016
121k
      break;  
1017
9.84k
    case '?':
1018
9.84k
      fxGetNextCharacter(parser);
1019
9.84k
      if (parser->character == '.') { 
1020
3.66k
        if ((parser->lookahead < '0') || ('9' < parser->lookahead)) {
1021
2.84k
          parser->states[2].token = XS_TOKEN_CHAIN;
1022
2.84k
          fxGetNextCharacter(parser);
1023
2.84k
        }
1024
822
        else
1025
822
          parser->states[2].token = XS_TOKEN_QUESTION_MARK;
1026
3.66k
      }
1027
6.18k
      else if (parser->character == '?') {   
1028
1.95k
        parser->states[2].token = XS_TOKEN_COALESCE;
1029
1.95k
        fxGetNextCharacter(parser);
1030
1.95k
        if (parser->character == '=') { 
1031
377
          parser->states[2].token = XS_TOKEN_COALESCE_ASSIGN;
1032
377
          fxGetNextCharacter(parser);
1033
377
        }
1034
1.95k
      }
1035
4.23k
      else  
1036
4.23k
        parser->states[2].token = XS_TOKEN_QUESTION_MARK;
1037
9.84k
      break;  
1038
447k
    case '(':
1039
447k
      parser->states[2].token = XS_TOKEN_LEFT_PARENTHESIS;
1040
447k
      fxGetNextCharacter(parser);
1041
447k
      break;  
1042
366k
    case ')':
1043
366k
      parser->states[2].token = XS_TOKEN_RIGHT_PARENTHESIS;
1044
366k
      fxGetNextCharacter(parser);
1045
366k
      break;  
1046
108k
    case '[':
1047
108k
      parser->states[2].token = XS_TOKEN_LEFT_BRACKET;
1048
108k
      fxGetNextCharacter(parser);
1049
108k
      break;  
1050
100k
    case ']':
1051
100k
      parser->states[2].token = XS_TOKEN_RIGHT_BRACKET;
1052
100k
      fxGetNextCharacter(parser);
1053
100k
      break;  
1054
396k
    case '{':
1055
396k
      parser->states[2].token = XS_TOKEN_LEFT_BRACE;
1056
396k
      fxGetNextCharacter(parser);
1057
396k
      break;  
1058
133k
    case '}':
1059
133k
      parser->states[2].token = XS_TOKEN_RIGHT_BRACE;
1060
133k
      fxGetNextCharacter(parser);
1061
133k
      break;  
1062
157k
    case '=':
1063
157k
      fxGetNextCharacter(parser);
1064
157k
      if (parser->character == '=') {     
1065
3.16k
        fxGetNextCharacter(parser);
1066
3.16k
        if (parser->character == '=') {
1067
2.31k
          parser->states[2].token = XS_TOKEN_STRICT_EQUAL;
1068
2.31k
          fxGetNextCharacter(parser);
1069
2.31k
        }
1070
859
        else
1071
859
          parser->states[2].token = XS_TOKEN_EQUAL;
1072
3.16k
      }
1073
154k
      else if (parser->character == '>') { 
1074
19.4k
        parser->states[2].token = XS_TOKEN_ARROW;
1075
19.4k
        fxGetNextCharacter(parser);
1076
19.4k
      }
1077
134k
      else  
1078
134k
        parser->states[2].token = XS_TOKEN_ASSIGN;
1079
157k
      break;
1080
50.9k
    case '<':
1081
50.9k
      fxGetNextCharacter(parser);
1082
50.9k
      if (parser->character == '<') {
1083
7.38k
        fxGetNextCharacter(parser);
1084
7.38k
        if (parser->character == '=') {
1085
189
          parser->states[2].token = XS_TOKEN_LEFT_SHIFT_ASSIGN;
1086
189
          fxGetNextCharacter(parser);
1087
189
        }
1088
7.19k
        else
1089
7.19k
          parser->states[2].token = XS_TOKEN_LEFT_SHIFT;
1090
7.38k
      }
1091
43.5k
      else  if (parser->character == '=') {
1092
1.58k
        parser->states[2].token = XS_TOKEN_LESS_EQUAL;
1093
1.58k
        fxGetNextCharacter(parser);
1094
1.58k
      }
1095
41.9k
      else
1096
41.9k
        parser->states[2].token = XS_TOKEN_LESS;
1097
50.9k
      break;  
1098
49.2k
    case '>':
1099
49.2k
      fxGetNextCharacter(parser);
1100
49.2k
      if (parser->character == '>') {     
1101
5.90k
        fxGetNextCharacter(parser);
1102
5.90k
        if (parser->character == '>') {     
1103
2.30k
          fxGetNextCharacter(parser);
1104
2.30k
          if (parser->character == '=') {
1105
1.52k
            parser->states[2].token = XS_TOKEN_UNSIGNED_RIGHT_SHIFT_ASSIGN;
1106
1.52k
            fxGetNextCharacter(parser);
1107
1.52k
          }
1108
780
          else
1109
780
            parser->states[2].token = XS_TOKEN_UNSIGNED_RIGHT_SHIFT;
1110
2.30k
        }
1111
3.59k
        else if (parser->character == '=') {
1112
2.18k
          parser->states[2].token = XS_TOKEN_SIGNED_RIGHT_SHIFT_ASSIGN;
1113
2.18k
          fxGetNextCharacter(parser);
1114
2.18k
        }
1115
1.41k
        else
1116
1.41k
          parser->states[2].token = XS_TOKEN_SIGNED_RIGHT_SHIFT;
1117
5.90k
      }
1118
43.3k
      else if (parser->character == '=') {
1119
2.65k
        parser->states[2].token = XS_TOKEN_MORE_EQUAL;
1120
2.65k
        fxGetNextCharacter(parser);
1121
2.65k
      }
1122
40.6k
      else
1123
40.6k
        parser->states[2].token = XS_TOKEN_MORE;
1124
49.2k
      break;  
1125
178k
    case '!':
1126
178k
      fxGetNextCharacter(parser);
1127
178k
      if (parser->character == '=') {     
1128
1.64k
        fxGetNextCharacter(parser);
1129
1.64k
        if (parser->character == '=') {
1130
1.21k
          parser->states[2].token = XS_TOKEN_STRICT_NOT_EQUAL;
1131
1.21k
          fxGetNextCharacter(parser);
1132
1.21k
        }
1133
428
        else
1134
428
          parser->states[2].token = XS_TOKEN_NOT_EQUAL;
1135
1.64k
      }
1136
176k
      else
1137
176k
        parser->states[2].token = XS_TOKEN_NOT;
1138
178k
      break;
1139
2.92k
    case '~':
1140
2.92k
      parser->states[2].token = XS_TOKEN_BIT_NOT;
1141
2.92k
      fxGetNextCharacter(parser);
1142
2.92k
      break;
1143
24.5k
    case '&':
1144
24.5k
      fxGetNextCharacter(parser);
1145
24.5k
      if (parser->character == '=') { 
1146
528
        parser->states[2].token = XS_TOKEN_BIT_AND_ASSIGN;
1147
528
        fxGetNextCharacter(parser);
1148
528
      }
1149
24.0k
      else if (parser->character == '&') {
1150
12.1k
        parser->states[2].token = XS_TOKEN_AND;
1151
12.1k
        fxGetNextCharacter(parser);
1152
12.1k
        if (parser->character == '=') { 
1153
1.05k
          parser->states[2].token = XS_TOKEN_AND_ASSIGN;
1154
1.05k
          fxGetNextCharacter(parser);
1155
1.05k
        }
1156
12.1k
      }
1157
11.9k
      else
1158
11.9k
        parser->states[2].token = XS_TOKEN_BIT_AND;
1159
24.5k
      break;
1160
5.90k
    case '|':
1161
5.90k
      fxGetNextCharacter(parser);
1162
5.90k
      if (parser->character == '=') {
1163
128
        parser->states[2].token = XS_TOKEN_BIT_OR_ASSIGN;
1164
128
        fxGetNextCharacter(parser);
1165
128
      }
1166
5.77k
      else if (parser->character == '|') {
1167
2.33k
        parser->states[2].token = XS_TOKEN_OR;
1168
2.33k
        fxGetNextCharacter(parser);
1169
2.33k
        if (parser->character == '=') { 
1170
332
          parser->states[2].token = XS_TOKEN_OR_ASSIGN;
1171
332
          fxGetNextCharacter(parser);
1172
332
        }
1173
2.33k
      }
1174
3.43k
      else
1175
3.43k
        parser->states[2].token = XS_TOKEN_BIT_OR;
1176
5.90k
      break;
1177
6.11k
    case '^':
1178
6.11k
      fxGetNextCharacter(parser);
1179
6.11k
      if (parser->character == '=') {
1180
517
        parser->states[2].token = XS_TOKEN_BIT_XOR_ASSIGN;
1181
517
        fxGetNextCharacter(parser);
1182
517
      }
1183
5.59k
      else
1184
5.59k
        parser->states[2].token = XS_TOKEN_BIT_XOR;
1185
6.11k
      break;
1186
54.2k
    case '+': 
1187
54.2k
      fxGetNextCharacter(parser);
1188
54.2k
      if (parser->character == '=') {
1189
3.16k
        parser->states[2].token = XS_TOKEN_ADD_ASSIGN;
1190
3.16k
        fxGetNextCharacter(parser);
1191
3.16k
      }
1192
51.0k
      else if (parser->character == '+') {
1193
23.6k
        parser->states[2].token = XS_TOKEN_INCREMENT;
1194
23.6k
        fxGetNextCharacter(parser);
1195
23.6k
      }
1196
27.3k
      else
1197
27.3k
        parser->states[2].token = XS_TOKEN_ADD;
1198
54.2k
      break;
1199
4.74M
    case '-': 
1200
4.74M
      fxGetNextCharacter(parser);
1201
4.74M
      if (parser->character == '=') {
1202
1.35k
        parser->states[2].token = XS_TOKEN_SUBTRACT_ASSIGN;
1203
1.35k
        fxGetNextCharacter(parser);
1204
1.35k
      }
1205
4.74M
      else if (parser->character == '-') {
1206
208k
        parser->states[2].token = XS_TOKEN_DECREMENT;
1207
208k
        fxGetNextCharacter(parser);
1208
208k
      }
1209
4.53M
      else
1210
4.53M
        parser->states[2].token = XS_TOKEN_SUBTRACT;
1211
4.74M
      break;
1212
14.7k
    case '*': 
1213
14.7k
      fxGetNextCharacter(parser);
1214
14.7k
      if (parser->character == '=') {
1215
340
        parser->states[2].token = XS_TOKEN_MULTIPLY_ASSIGN;
1216
340
        fxGetNextCharacter(parser);
1217
340
      }
1218
14.4k
      else if (parser->character == '*') {
1219
1.59k
        fxGetNextCharacter(parser);
1220
1.59k
        if (parser->character == '=') {
1221
4
          parser->states[2].token = XS_TOKEN_EXPONENTIATION_ASSIGN;
1222
4
          fxGetNextCharacter(parser);
1223
4
        }
1224
1.58k
        else
1225
1.58k
          parser->states[2].token = XS_TOKEN_EXPONENTIATION;
1226
1.59k
      }
1227
12.8k
      else
1228
12.8k
        parser->states[2].token = XS_TOKEN_MULTIPLY;
1229
14.7k
      break;
1230
237k
    case '/':
1231
237k
      fxGetNextCharacter(parser);
1232
237k
      if (parser->character == '*') {
1233
15.6k
        fxGetNextCharacter(parser);
1234
3.92M
        for (;;) {
1235
3.92M
          if (parser->character == (txU4)C_EOF) {
1236
2.80k
            fxReportParserError(parser, parser->states[2].line, "end of file in comment");      
1237
2.80k
            break;
1238
2.80k
          }
1239
3.91M
          else if ((parser->character == 10) || (parser->character == 0x2028) || (parser->character == 0x2029)) {
1240
49.0k
            parser->states[2].line++;
1241
49.0k
            fxGetNextCharacter(parser);
1242
49.0k
            parser->states[2].crlf = 1;
1243
49.0k
          }
1244
3.87M
          else if (parser->character == 13) {
1245
7.79k
            parser->states[2].line++;
1246
7.79k
            fxGetNextCharacter(parser);
1247
7.79k
            if (parser->character == 10)
1248
1.82k
              fxGetNextCharacter(parser);
1249
7.79k
            parser->states[2].crlf = 1;
1250
7.79k
          }
1251
3.86M
          else if (parser->character == '*') {
1252
19.1k
            fxGetNextCharacter(parser);
1253
19.1k
            if (parser->character == '/') {
1254
12.8k
              fxGetNextCharacter(parser);
1255
12.8k
              break;
1256
12.8k
            }
1257
19.1k
          }
1258
3.84M
          else
1259
3.84M
            fxGetNextCharacter(parser);
1260
3.92M
        }
1261
15.6k
      }
1262
221k
      else if (parser->character == '/') {
1263
160k
        fxGetNextCharacter(parser);
1264
160k
        p = parser->buffer;
1265
160k
        q = p + parser->bufferSize - 1;
1266
12.4M
        while ((parser->character != (txU4)C_EOF) && (parser->character != 10) && (parser->character != 13) && (parser->character != 0x2028) && (parser->character != 0x2029)) {
1267
12.3M
          if (p < q)
1268
12.1M
            *p++ = (char)parser->character;
1269
12.3M
          fxGetNextCharacter(parser);
1270
12.3M
        }  
1271
160k
        *p = 0;
1272
160k
        p = parser->buffer;
1273
160k
        if ((*p == '#') || (*p == '@')) {
1274
8.30k
          if (!c_strncmp(p, "@line ", 6)) {
1275
3.07k
            p += 6;
1276
3.07k
            t = 0;
1277
3.07k
            c = *p++;
1278
15.7k
            while (('0' <= c) && (c <= '9')) {
1279
12.6k
              t = (t * 10) + (c - '0');
1280
12.6k
              c = *p++;
1281
12.6k
            }
1282
3.07k
            if (!t) goto bail;
1283
2.68k
            if (c == ' ') {
1284
1.69k
              c = *p++;
1285
1.69k
              if (c != '"') goto bail;
1286
710
              q = p;
1287
710
              c = *q++;
1288
16.9k
              while ((c != 0) && (c != 10) && (c != 13) && (c != '"'))
1289
16.2k
                c = *q++;
1290
710
              if (c != '"') goto bail;
1291
435
              *(--q) = 0;
1292
435
              parser->path = fxNewParserSymbol(parser, p);
1293
435
            }
1294
1.42k
            parser->states[2].line = t - 1;
1295
1.42k
          }
1296
5.22k
          else if (!c_strncmp(p, "# sourceMappingURL=", 19) || !c_strncmp(p, "@ sourceMappingURL=", 19)) {
1297
317
            p += 19;
1298
317
            q = p;
1299
10.0k
            while (((c = *q)) && (c != 10) && (c != 13))
1300
9.69k
              q++;
1301
317
            *q = 0;
1302
317
            parser->name = fxNewParserString(parser, p, mxPtrDiff(q - p));
1303
317
          }
1304
4.91k
          else if (!c_strncmp(p, "# sourceURL=", 12) || !c_strncmp(p, "@ sourceURL=", 12)) {
1305
418
            p += 12;
1306
418
            q = p;
1307
131k
            while (((c = *q)) && (c != 10) && (c != 13))
1308
131k
              q++;
1309
418
            *q = 0;
1310
418
            parser->source = fxNewParserSymbol(parser, p);
1311
418
          }
1312
8.30k
      }
1313
160k
      bail:
1314
160k
        ;
1315
160k
      }
1316
61.0k
      else if (parser->character == '=') {
1317
1.49k
        parser->states[2].token = XS_TOKEN_DIVIDE_ASSIGN;
1318
1.49k
        fxGetNextCharacter(parser);
1319
1.49k
      }
1320
59.5k
      else 
1321
59.5k
        parser->states[2].token = XS_TOKEN_DIVIDE;
1322
237k
      break;
1323
237k
    case '%': 
1324
5.98k
      fxGetNextCharacter(parser);
1325
5.98k
      if (parser->character == '=') {
1326
442
        parser->states[2].token = XS_TOKEN_MODULO_ASSIGN;
1327
442
        fxGetNextCharacter(parser);
1328
442
      }
1329
5.53k
      else
1330
5.53k
        parser->states[2].token = XS_TOKEN_MODULO;
1331
5.98k
      break;
1332
    
1333
110k
    case '"':
1334
167k
    case '\'':
1335
167k
      c = parser->character;
1336
167k
      fxGetNextCharacter(parser);
1337
167k
      fxGetNextString(parser, c);
1338
167k
      parser->states[2].token = XS_TOKEN_STRING;
1339
167k
      fxGetNextCharacter(parser);
1340
167k
      break;
1341
      
1342
192k
    case '`':
1343
192k
      fxGetNextCharacter(parser);
1344
192k
      fxGetNextString(parser, '`');
1345
192k
      if (parser->character == '{')
1346
859
        parser->states[2].token = XS_TOKEN_TEMPLATE_HEAD;
1347
191k
      else
1348
191k
        parser->states[2].token = XS_TOKEN_TEMPLATE;
1349
192k
      fxGetNextCharacter(parser);
1350
192k
      break;
1351
      
1352
3.39k
    case '@':
1353
3.39k
      if (parser->flags & mxCFlag)
1354
0
        parser->states[2].token = XS_TOKEN_HOST;
1355
3.39k
            else
1356
3.39k
                fxReportParserError(parser, parser->states[2].line, "invalid character @");
1357
3.39k
            fxGetNextCharacter(parser);
1358
3.39k
      break;
1359
      
1360
1.87M
    default:
1361
1.87M
      p = parser->buffer;
1362
1.87M
      q = p + parser->bufferSize - 1;
1363
1.87M
      if (parser->character == '#') {
1364
5.36k
        *p++ = '#';
1365
5.36k
        fxGetNextCharacter(parser);
1366
5.36k
      }
1367
1.87M
      if (fxIsIdentifierFirst(parser->character)) {
1368
1.83M
        p = fxUTF8Buffer(parser, parser->character, p, q);        
1369
1.83M
        fxGetNextCharacter(parser);
1370
1.83M
      }
1371
34.5k
      else if (parser->character == '\\') {
1372
1.31k
        parser->states[2].escaped = 1;
1373
1.31k
        t = 0;
1374
1.31k
        if (fxGetNextIdentiferX(parser, &t) && fxIsIdentifierFirst(t))
1375
321
          p = fxUTF8Buffer(parser, t, p, q);        
1376
992
        else
1377
992
          p = C_NULL;
1378
1.31k
      }
1379
33.2k
      else
1380
33.2k
        p = C_NULL;
1381
1.87M
      if (p) {
1382
9.20M
        for (;;) {
1383
9.20M
          if (p == q) {
1384
1
            fxReportMemoryError(parser, parser->states[2].line, "identifier overflow");
1385
1
          }
1386
9.20M
          if (fxIsIdentifierNext(parser->character)) {
1387
7.37M
            p = fxUTF8Buffer(parser, parser->character, p, q);        
1388
7.37M
            fxGetNextCharacter(parser);
1389
7.37M
          }
1390
1.83M
          else if (parser->character == '\\') {
1391
1.49k
            parser->states[2].escaped = 1;
1392
1.49k
            t = 0;
1393
1.49k
            if (fxGetNextIdentiferX(parser, &t) && fxIsIdentifierNext(t))
1394
277
              p = fxUTF8Buffer(parser, t, p, q);        
1395
1.22k
            else {
1396
1.22k
              p = C_NULL;
1397
1.22k
              break;
1398
1.22k
            }
1399
1.49k
          }
1400
1.83M
          else {
1401
1.83M
            *p = 0;
1402
1.83M
            if (parser->buffer[0] == '#') {
1403
3.95k
              parser->states[2].symbol = fxNewParserSymbol(parser, parser->buffer);
1404
3.95k
              parser->states[2].token = XS_TOKEN_PRIVATE_IDENTIFIER;
1405
3.95k
            }
1406
1.83M
            else {
1407
1.83M
              fxGetNextKeyword(parser);
1408
1.83M
            }
1409
1.83M
            break;
1410
1.83M
          }
1411
9.20M
        }
1412
1.83M
      }
1413
1.87M
      if (!p) {
1414
35.4k
        fxReportParserError(parser, parser->states[2].line, "invalid character %d", parser->character);
1415
35.4k
        fxGetNextCharacter(parser);
1416
35.4k
      }
1417
1.87M
      break;
1418
18.0M
    }
1419
18.0M
  }
1420
15.2M
}
1421
1422
void fxGetNextTokenTemplate(txParser* parser)
1423
2.29k
{
1424
2.29k
  parser->states[2].crlf = 0;
1425
2.29k
  parser->states[2].escaped = 0;
1426
2.29k
  parser->states[2].integer = 0;
1427
2.29k
  parser->states[2].modifierLength = 0;
1428
2.29k
  parser->states[2].modifier = parser->emptyString;
1429
2.29k
  parser->states[2].number = 0;
1430
2.29k
  parser->states[2].rawLength = 0;
1431
2.29k
  parser->states[2].raw = parser->emptyString;
1432
2.29k
  parser->states[2].stringLength = 0;
1433
2.29k
  parser->states[2].string = parser->emptyString;
1434
2.29k
  parser->states[2].symbol = C_NULL;
1435
2.29k
  parser->states[2].token = XS_NO_TOKEN;
1436
2.29k
  fxGetNextString(parser, '`');
1437
2.29k
  if (parser->character == '{')
1438
1.45k
    parser->states[2].token = XS_TOKEN_TEMPLATE_MIDDLE;
1439
842
  else
1440
842
    parser->states[2].token = XS_TOKEN_TEMPLATE_TAIL;
1441
2.29k
  fxGetNextCharacter(parser);
1442
2.29k
  parser->states[0] = parser->states[2];
1443
2.29k
  parser->ahead = 0;
1444
2.29k
}
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
18.8k
#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
150k
{
1648
150k
  return c_strcmp((char*)name, ((txEntity*)entity)->name);
1649
150k
}
1650
1651
txString fxGetNextEntity(txParser* parser, txString p, txString q)
1652
33.2k
{
1653
33.2k
  txString r = p;
1654
33.2k
  txU4 t = 0;
1655
33.2k
    if (p < q) *p++ = '&';
1656
33.2k
  fxGetNextCharacter(parser);
1657
33.2k
  if (parser->character == '#') {
1658
14.3k
    if (p < q) *p++ = '#';
1659
14.3k
    fxGetNextCharacter(parser);
1660
14.3k
    if (parser->character == 'x') {
1661
13.9k
      if (p < q) *p++ = 'x';
1662
13.9k
      fxGetNextCharacter(parser);
1663
75.7k
      while (fxGetNextStringX(parser->character, &t)) {
1664
61.8k
        if (p < q) *p++ = parser->character;
1665
61.8k
        fxGetNextCharacter(parser);
1666
61.8k
      }
1667
13.9k
    }
1668
416
    else {
1669
806
      while (fxGetNextStringD(parser->character, &t)) {
1670
390
        if (p < q) *p++ = parser->character;
1671
390
        fxGetNextCharacter(parser);
1672
390
      }
1673
416
    }
1674
14.3k
  }
1675
18.8k
  else {
1676
18.8k
    txEntity* entity = C_NULL;
1677
18.8k
    int c = parser->character;
1678
24.9k
    while ((p < q) && ((('0' <= c) && (c <= '9')) || (('A' <= c) && (c <= 'Z')) || (('a' <= c) && (c <= 'z')))) {
1679
6.04k
      if (p < q) *p++ = c;
1680
6.04k
      fxGetNextCharacter(parser);
1681
6.04k
      c = parser->character;
1682
6.04k
    }
1683
18.8k
    *p = 0;
1684
18.8k
        if (r < q)
1685
18.8k
            entity = (txEntity*)c_bsearch(r + 1, gxEntities, XS_ENTITIES_COUNT, sizeof(txEntity), fxCompareEntities);
1686
18.8k
    t = entity ? entity->value : 0;
1687
18.8k
  }
1688
33.2k
  if (parser->character == ';') {
1689
14.2k
    if (p < q) *p++ = ';';
1690
14.2k
    fxGetNextCharacter(parser);
1691
14.2k
    if (t)
1692
14.0k
      p = fxUTF8Buffer(parser, t, r, q);
1693
14.2k
  }
1694
33.2k
  return p;
1695
33.2k
}
1696
1697
void fxGetNextTokenJSXAttribute(txParser* parser)
1698
2.05k
{
1699
2.05k
  txString p = parser->buffer;
1700
2.05k
  txString q = p + parser->bufferSize - 1;
1701
2.05k
  txU4 quote = 0;
1702
2.05k
  parser->states[2].crlf = 0;
1703
2.05k
  parser->states[2].escaped = 0;
1704
2.05k
  parser->states[2].integer = 0;
1705
2.05k
  parser->states[2].modifierLength = 0;
1706
2.05k
  parser->states[2].modifier = parser->emptyString;
1707
2.05k
  parser->states[2].number = 0;
1708
2.05k
  parser->states[2].rawLength = 0;
1709
2.05k
  parser->states[2].raw = parser->emptyString;
1710
2.05k
  parser->states[2].stringLength = 0;
1711
2.05k
  parser->states[2].string = parser->emptyString;
1712
2.05k
  parser->states[2].symbol = C_NULL;
1713
2.05k
  parser->states[2].token = XS_NO_TOKEN;
1714
697k
  while (parser->states[2].token == XS_NO_TOKEN) {
1715
695k
    switch (parser->character) {
1716
574
    case C_EOF:
1717
574
      parser->states[2].token = XS_TOKEN_EOF;
1718
574
      break;
1719
12.3k
    case 10:  
1720
12.5k
    case 0x2028: // <LS>
1721
12.6k
    case 0x2029: // <PS>  
1722
12.6k
      parser->states[2].line++;
1723
12.6k
      if (quote)
1724
7.45k
        p = fxUTF8Buffer(parser, parser->character, p, q);
1725
12.6k
      fxGetNextCharacter(parser);
1726
12.6k
      parser->states[2].crlf = 1;
1727
12.6k
      break;
1728
37.7k
    case 13:  
1729
37.7k
      parser->states[2].line++;
1730
37.7k
      if (quote)
1731
37.7k
        p = fxUTF8Buffer(parser, parser->character, p, q);
1732
37.7k
      fxGetNextCharacter(parser);
1733
37.7k
      if (parser->character == 10) {
1734
579
        if (quote)
1735
531
          p = fxUTF8Buffer(parser, parser->character, p, q);
1736
579
        fxGetNextCharacter(parser);
1737
579
      }
1738
37.7k
      parser->states[2].crlf = 1;
1739
37.7k
      break;
1740
1.01k
    case '\t':
1741
1.14k
    case 11:
1742
1.75k
    case 12:
1743
21.2k
    case ' ':
1744
21.2k
    case 0x00A0:
1745
21.3k
    case 0x1680:
1746
21.3k
    case 0x2000:
1747
21.4k
    case 0x2001:
1748
21.4k
    case 0x2002:
1749
21.8k
    case 0x2003:
1750
21.8k
    case 0x2004:
1751
21.9k
    case 0x2005:
1752
22.0k
    case 0x2006:
1753
22.0k
    case 0x2007:
1754
22.0k
    case 0x2008:
1755
22.0k
    case 0x2009:
1756
22.1k
    case 0x200A:
1757
22.2k
    case 0x202F:
1758
22.2k
    case 0x205F:
1759
22.2k
    case 0x3000:
1760
22.2k
    case 0xFEFF:
1761
22.2k
      if (quote)
1762
22.0k
        p = fxUTF8Buffer(parser, parser->character, p, q);
1763
22.2k
      fxGetNextCharacter(parser);
1764
22.2k
      break;
1765
      
1766
6.10k
    case '{':
1767
6.10k
      if (quote)
1768
6.09k
        p = fxUTF8Buffer(parser, parser->character, p, q);
1769
13
      else
1770
13
        parser->states[2].token = XS_TOKEN_LEFT_BRACE;
1771
6.10k
      fxGetNextCharacter(parser);
1772
6.10k
      break;
1773
      
1774
3.33k
    case '"':
1775
30.5k
    case '\'':
1776
30.5k
      if (quote) {
1777
29.4k
        if (quote == parser->character) {
1778
590
          parser->states[2].stringLength = mxPtrDiff(p - parser->buffer);
1779
590
          parser->states[2].string = fxNewParserString(parser, parser->buffer, parser->states[2].stringLength);
1780
590
          parser->states[2].token = XS_TOKEN_STRING;
1781
590
        }
1782
28.8k
        else
1783
28.8k
          p = fxUTF8Buffer(parser, parser->character, p, q);
1784
29.4k
      }
1785
1.16k
      else
1786
1.16k
        quote = parser->character;
1787
30.5k
      fxGetNextCharacter(parser);
1788
30.5k
      break;
1789
      
1790
30.1k
    case '&':
1791
30.1k
      if (quote)
1792
30.1k
        p = fxGetNextEntity(parser, p, q);
1793
0
      else {
1794
0
        fxReportParserError(parser, parser->states[2].line, "invalid character %d", parser->character);
1795
0
        fxGetNextCharacter(parser);
1796
0
      }
1797
30.1k
      break;
1798
      
1799
555k
    default:
1800
555k
      if (quote)
1801
554k
        p = fxUTF8Buffer(parser, parser->character, p, q);
1802
870
      else
1803
870
        fxReportParserError(parser, parser->states[2].line, "invalid character %d", parser->character);
1804
555k
      fxGetNextCharacter(parser);
1805
555k
      break; 
1806
695k
    } 
1807
695k
  }
1808
1.17k
  parser->states[0] = parser->states[2];
1809
1.17k
  parser->ahead = 0;
1810
1.17k
}
1811
1812
void fxGetNextTokenJSXChild(txParser* parser)
1813
22.2k
{
1814
22.2k
  txString p = parser->buffer;
1815
22.2k
  txString q = p + parser->bufferSize - 1;
1816
22.2k
  txString s = C_NULL;
1817
22.2k
  char c;
1818
22.2k
  txString after = C_NULL;
1819
22.2k
  txString before = C_NULL;
1820
22.2k
  txString text = C_NULL;
1821
22.2k
  parser->states[2].crlf = 0;
1822
22.2k
  parser->states[2].escaped = 0;
1823
22.2k
  parser->states[2].integer = 0;
1824
22.2k
  parser->states[2].modifierLength = 0;
1825
22.2k
  parser->states[2].modifier = parser->emptyString;
1826
22.2k
  parser->states[2].number = 0;
1827
22.2k
  parser->states[2].rawLength = 0;
1828
22.2k
  parser->states[2].raw = parser->emptyString;
1829
22.2k
  parser->states[2].stringLength = 0;
1830
22.2k
  parser->states[2].string = parser->emptyString;
1831
22.2k
  parser->states[2].symbol = C_NULL;
1832
22.2k
  parser->states[2].token = XS_NO_TOKEN;
1833
588k
  while (parser->states[2].token == XS_NO_TOKEN) {
1834
566k
    switch (parser->character) {
1835
117
    case C_EOF:
1836
117
      parser->states[2].token = XS_TOKEN_EOF;
1837
117
      break;
1838
9.09k
    case 10:  
1839
9.32k
    case 0x2028: // <LS>
1840
9.36k
    case 0x2029: // <PS>  
1841
9.36k
      parser->states[2].line++;
1842
9.36k
      p = fxUTF8Buffer(parser, parser->character, p, q);
1843
9.36k
      fxGetNextCharacter(parser);
1844
9.36k
      parser->states[2].crlf = 1;
1845
9.36k
      break;
1846
3.68k
    case 13:  
1847
3.68k
      parser->states[2].line++;
1848
3.68k
      p = fxUTF8Buffer(parser, parser->character, p, q);
1849
3.68k
      fxGetNextCharacter(parser);
1850
3.68k
      if (parser->character == 10) {
1851
3.17k
        p = fxUTF8Buffer(parser, parser->character, p, q);
1852
3.17k
        fxGetNextCharacter(parser);
1853
3.17k
      }
1854
3.68k
      parser->states[2].crlf = 1;
1855
3.68k
      break;
1856
      
1857
18.3k
    case '<':
1858
18.3k
      fxGetNextCharacter(parser);
1859
18.3k
      parser->states[2].token = XS_TOKEN_LESS;
1860
18.3k
      break;
1861
1.13k
    case '>':
1862
1.13k
      fxGetNextCharacter(parser);
1863
1.13k
      parser->states[2].token = XS_TOKEN_MORE;
1864
1.13k
      break;
1865
1.74k
    case '{':
1866
1.74k
      fxGetNextCharacter(parser);
1867
1.74k
      parser->states[2].token = XS_TOKEN_LEFT_BRACE;
1868
1.74k
      break;
1869
835
    case '}':
1870
835
      fxGetNextCharacter(parser);
1871
835
      parser->states[2].token = XS_TOKEN_RIGHT_BRACE;
1872
835
      break;
1873
3.10k
    case '&':
1874
3.10k
      p = fxGetNextEntity(parser, p, q);
1875
3.10k
      break;
1876
528k
    default:
1877
528k
      p = fxUTF8Buffer(parser, parser->character, p, q);
1878
528k
      fxGetNextCharacter(parser);
1879
528k
      break; 
1880
566k
    } 
1881
566k
  }
1882
22.2k
  parser->states[2].rawLength = mxPtrDiff(p - parser->buffer);
1883
22.2k
  parser->states[2].raw = fxNewParserString(parser, parser->buffer, parser->states[2].rawLength);
1884
22.2k
  if (parser->states[2].crlf) {
1885
3.21k
    p = parser->buffer;
1886
3.21k
    q = p + parser->bufferSize - 1;
1887
3.21k
    s = parser->states[2].raw;
1888
3.21k
    c = *s++;
1889
898k
    while (c) {
1890
895k
      if ((c == 10) || (c == 13)) {
1891
10.0k
        if (before)
1892
3.64k
          p = before;
1893
6.41k
        else
1894
6.41k
          before = p;
1895
10.0k
        after = p;
1896
10.0k
      }
1897
885k
      else if ((c == 9) || (c == 32)) {
1898
15.7k
        if (!before)
1899
11.1k
          before = p;
1900
15.7k
        *p++ = c;
1901
15.7k
      }
1902
869k
      else {
1903
869k
        if (after) {
1904
6.33k
          p = after;
1905
6.33k
          if (text)
1906
5.99k
            *p++ = 32;
1907
6.33k
        }
1908
869k
        after = C_NULL;
1909
869k
        before = C_NULL;
1910
869k
        text = p;
1911
869k
        *p++ = c;
1912
869k
      }
1913
895k
      c = *s++;
1914
895k
    }
1915
3.21k
    if (after)
1916
642
      p = after;
1917
3.21k
  }
1918
22.2k
  parser->states[2].stringLength = mxPtrDiff(p - parser->buffer);
1919
22.2k
  parser->states[2].string = fxNewParserString(parser, parser->buffer, parser->states[2].stringLength);
1920
  
1921
22.2k
  parser->states[0] = parser->states[2];
1922
22.2k
  parser->ahead = 0;
1923
22.2k
}
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939