Coverage Report

Created: 2026-01-29 06:33

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