Coverage Report

Created: 2025-08-28 06:30

/src/testdir/build/lua-master/source/llex.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
** $Id: llex.c $
3
** Lexical Analyzer
4
** See Copyright Notice in lua.h
5
*/
6
7
#define llex_c
8
#define LUA_CORE
9
10
#include "lprefix.h"
11
12
13
#include <locale.h>
14
#include <string.h>
15
16
#include "lua.h"
17
18
#include "lctype.h"
19
#include "ldebug.h"
20
#include "ldo.h"
21
#include "lgc.h"
22
#include "llex.h"
23
#include "lobject.h"
24
#include "lparser.h"
25
#include "lstate.h"
26
#include "lstring.h"
27
#include "ltable.h"
28
#include "lzio.h"
29
30
31
32
2.34G
#define next(ls)  (ls->current = zgetc(ls->z))
33
34
35
/* minimum size for string buffer */
36
#if !defined(LUA_MINBUFFER)
37
#define LUA_MINBUFFER   32
38
#endif
39
40
41
276M
#define currIsNewline(ls) (ls->current == '\n' || ls->current == '\r')
42
43
44
/* ORDER RESERVED */
45
static const char *const luaX_tokens [] = {
46
    "and", "break", "do", "else", "elseif",
47
    "end", "false", "for", "function", "global", "goto", "if",
48
    "in", "local", "nil", "not", "or", "repeat",
49
    "return", "then", "true", "until", "while",
50
    "//", "..", "...", "==", ">=", "<=", "~=",
51
    "<<", ">>", "::", "<eof>",
52
    "<number>", "<integer>", "<name>", "<string>"
53
};
54
55
56
1.95G
#define save_and_next(ls) (save(ls, ls->current), next(ls))
57
58
59
static l_noret lexerror (LexState *ls, const char *msg, int token);
60
61
62
1.99G
static void save (LexState *ls, int c) {
63
1.99G
  Mbuffer *b = ls->buff;
64
1.99G
  if (luaZ_bufflen(b) + 1 > luaZ_sizebuffer(b)) {
65
975k
    size_t newsize = luaZ_sizebuffer(b);  /* get old size */;
66
975k
    if (newsize >= (MAX_SIZE/3 * 2))  /* larger than MAX_SIZE/1.5 ? */
67
0
      lexerror(ls, "lexical element too long", 0);
68
975k
    newsize += (newsize >> 1);  /* new size is 1.5 times the old one */
69
975k
    luaZ_resizebuffer(ls->L, b, newsize);
70
975k
  }
71
1.99G
  b->buffer[luaZ_bufflen(b)++] = cast_char(c);
72
1.99G
}
73
74
75
58.1k
void luaX_init (lua_State *L) {
76
58.1k
  int i;
77
58.1k
  TString *e = luaS_newliteral(L, LUA_ENV);  /* create env name */
78
58.1k
  luaC_fix(L, obj2gco(e));  /* never collect this name */
79
1.39M
  for (i=0; i<NUM_RESERVED; i++) {
80
1.33M
    TString *ts = luaS_new(L, luaX_tokens[i]);
81
1.33M
    luaC_fix(L, obj2gco(ts));  /* reserved words are never collected */
82
1.33M
    ts->extra = cast_byte(i+1);  /* reserved word */
83
1.33M
  }
84
58.1k
}
85
86
87
2.53M
const char *luaX_token2str (LexState *ls, int token) {
88
2.53M
  if (token < FIRST_RESERVED) {  /* single-byte symbols? */
89
1.78M
    if (lisprint(token))
90
891k
      return luaO_pushfstring(ls->L, "'%c'", token);
91
889k
    else  /* control character */
92
889k
      return luaO_pushfstring(ls->L, "'<\\%d>'", token);
93
1.78M
  }
94
754k
  else {
95
754k
    const char *s = luaX_tokens[token - FIRST_RESERVED];
96
754k
    if (token < TK_EOS)  /* fixed format (symbols and reserved words)? */
97
133k
      return luaO_pushfstring(ls->L, "'%s'", s);
98
620k
    else  /* names, strings, and numerals */
99
620k
      return s;
100
754k
  }
101
2.53M
}
102
103
104
4.35M
static const char *txtToken (LexState *ls, int token) {
105
4.35M
  switch (token) {
106
312k
    case TK_NAME: case TK_STRING:
107
2.36M
    case TK_FLT: case TK_INT:
108
2.36M
      save(ls, '\0');
109
2.36M
      return luaO_pushfstring(ls->L, "'%s'", luaZ_buffer(ls->buff));
110
1.98M
    default:
111
1.98M
      return luaX_token2str(ls, token);
112
4.35M
  }
113
4.35M
}
114
115
116
4.54M
static l_noret lexerror (LexState *ls, const char *msg, int token) {
117
4.54M
  msg = luaG_addinfo(ls->L, msg, ls->source, ls->linenumber);
118
4.54M
  if (token)
119
4.35M
    luaO_pushfstring(ls->L, "%s near %s", msg, txtToken(ls, token));
120
4.54M
  luaD_throw(ls->L, LUA_ERRSYNTAX);
121
4.54M
}
122
123
124
4.07M
l_noret luaX_syntaxerror (LexState *ls, const char *msg) {
125
4.07M
  lexerror(ls, msg, ls->t.token);
126
4.07M
}
127
128
129
/*
130
** Anchors a string in scanner's table so that it will not be collected
131
** until the end of the compilation; by that time it should be anchored
132
** somewhere. It also internalizes long strings, ensuring there is only
133
** one copy of each unique string.
134
*/
135
180M
static TString *anchorstr (LexState *ls, TString *ts) {
136
180M
  lua_State *L = ls->L;
137
180M
  TValue oldts;
138
180M
  int tag = luaH_getstr(ls->h, ts, &oldts);
139
180M
  if (!tagisempty(tag))  /* string already present? */
140
180M
    return tsvalue(&oldts);  /* use stored value */
141
13.1M
  else {  /* create a new entry */
142
13.1M
    TValue *stv = s2v(L->top.p++);  /* reserve stack space for string */
143
13.1M
    setsvalue(L, stv, ts);  /* push (anchor) the string on the stack */
144
13.1M
    luaH_set(L, ls->h, stv, stv);  /* t[string] = string */
145
    /* table is not a metatable, so it does not need to invalidate cache */
146
13.1M
    luaC_checkGC(L);
147
13.1M
    L->top.p--;  /* remove string from stack */
148
13.1M
    return ts;
149
13.1M
  }
150
180M
}
151
152
153
/*
154
** Creates a new string and anchors it in scanner's table.
155
*/
156
2.57M
TString *luaX_newstring (LexState *ls, const char *str, size_t l) {
157
2.57M
  return anchorstr(ls, luaS_newlstr(ls->L, str, l));
158
2.57M
}
159
160
161
/*
162
** increment line number and skips newline sequence (any of
163
** \n, \r, \n\r, or \r\n)
164
*/
165
46.4M
static void inclinenumber (LexState *ls) {
166
46.4M
  int old = ls->current;
167
46.4M
  lua_assert(currIsNewline(ls));
168
46.4M
  next(ls);  /* skip '\n' or '\r' */
169
46.4M
  if (currIsNewline(ls) && ls->current != old)
170
52.9k
    next(ls);  /* skip '\n\r' or '\r\n' */
171
46.4M
  if (++ls->linenumber >= INT_MAX)
172
0
    lexerror(ls, "chunk has too many lines", 0);
173
46.4M
}
174
175
176
void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source,
177
7.92M
                    int firstchar) {
178
7.92M
  ls->t.token = 0;
179
7.92M
  ls->L = L;
180
7.92M
  ls->current = firstchar;
181
7.92M
  ls->lookahead.token = TK_EOS;  /* no look-ahead token */
182
7.92M
  ls->z = z;
183
7.92M
  ls->fs = NULL;
184
7.92M
  ls->linenumber = 1;
185
7.92M
  ls->lastline = 1;
186
7.92M
  ls->source = source;
187
  /* all three strings here ("_ENV", "break", "global") were fixed,
188
     so they cannot be collected */
189
7.92M
  ls->envn = luaS_newliteral(L, LUA_ENV);  /* get env string */
190
7.92M
  ls->brkn = luaS_newliteral(L, "break");  /* get "break" string */
191
7.92M
#if defined(LUA_COMPAT_GLOBAL)
192
  /* compatibility mode: "global" is not a reserved word */
193
7.92M
  ls->glbn = luaS_newliteral(L, "global");  /* get "global" string */
194
7.92M
  ls->glbn->extra = 0;  /* mark it as not reserved */
195
7.92M
#endif
196
7.92M
  luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER);  /* initialize buffer */
197
7.92M
}
198
199
200
201
/*
202
** =======================================================
203
** LEXICAL ANALYZER
204
** =======================================================
205
*/
206
207
208
296M
static int check_next1 (LexState *ls, int c) {
209
296M
  if (ls->current == c) {
210
4.79M
    next(ls);
211
4.79M
    return 1;
212
4.79M
  }
213
292M
  else return 0;
214
296M
}
215
216
217
/*
218
** Check whether current char is in set 'set' (with two chars) and
219
** saves it
220
*/
221
190M
static int check_next2 (LexState *ls, const char *set) {
222
190M
  lua_assert(set[2] == '\0');
223
190M
  if (ls->current == set[0] || ls->current == set[1]) {
224
3.06M
    save_and_next(ls);
225
3.06M
    return 1;
226
3.06M
  }
227
187M
  else return 0;
228
190M
}
229
230
231
/* LUA_NUMBER */
232
/*
233
** This function is quite liberal in what it accepts, as 'luaO_str2num'
234
** will reject ill-formed numerals. Roughly, it accepts the following
235
** pattern:
236
**
237
**   %d(%x|%.|([Ee][+-]?))* | 0[Xx](%x|%.|([Pp][+-]?))*
238
**
239
** The only tricky part is to accept [+-] only after a valid exponent
240
** mark, to avoid reading '3-4' or '0xe+1' as a single number.
241
**
242
** The caller might have already read an initial dot.
243
*/
244
15.8M
static int read_numeral (LexState *ls, SemInfo *seminfo) {
245
15.8M
  TValue obj;
246
15.8M
  const char *expo = "Ee";
247
15.8M
  int first = ls->current;
248
15.8M
  lua_assert(lisdigit(ls->current));
249
15.8M
  save_and_next(ls);
250
15.8M
  if (first == '0' && check_next2(ls, "xX"))  /* hexadecimal? */
251
82.8k
    expo = "Pp";
252
182M
  for (;;) {
253
182M
    if (check_next2(ls, expo))  /* exponent mark? */
254
2.95M
      check_next2(ls, "-+");  /* optional exponent sign */
255
179M
    else if (lisxdigit(ls->current) || ls->current == '.')  /* '%x|%.' */
256
163M
      save_and_next(ls);
257
15.8M
    else break;
258
182M
  }
259
15.8M
  if (lislalpha(ls->current))  /* is numeral touching a letter? */
260
88.9k
    save_and_next(ls);  /* force an error */
261
15.8M
  save(ls, '\0');
262
15.8M
  if (luaO_str2num(luaZ_buffer(ls->buff), &obj) == 0)  /* format error? */
263
177k
    lexerror(ls, "malformed number", TK_FLT);
264
15.6M
  if (ttisinteger(&obj)) {
265
13.4M
    seminfo->i = ivalue(&obj);
266
0
    return TK_INT;
267
13.4M
  }
268
2.17M
  else {
269
2.17M
    lua_assert(ttisfloat(&obj));
270
2.17M
    seminfo->r = fltvalue(&obj);
271
0
    return TK_FLT;
272
2.17M
  }
273
15.6M
}
274
275
276
/*
277
** read a sequence '[=*[' or ']=*]', leaving the last bracket. If
278
** sequence is well formed, return its number of '='s + 2; otherwise,
279
** return 1 if it is a single bracket (no '='s and no 2nd bracket);
280
** otherwise (an unfinished '[==...') return 0.
281
*/
282
1.93M
static size_t skip_sep (LexState *ls) {
283
1.93M
  size_t count = 0;
284
1.93M
  int s = ls->current;
285
1.93M
  lua_assert(s == '[' || s == ']');
286
1.93M
  save_and_next(ls);
287
9.70M
  while (ls->current == '=') {
288
7.76M
    save_and_next(ls);
289
7.76M
    count++;
290
7.76M
  }
291
1.93M
  return (ls->current == s) ? count + 2
292
1.93M
         : (count == 0) ? 1
293
729k
         : 0;
294
1.93M
}
295
296
297
246k
static void read_long_string (LexState *ls, SemInfo *seminfo, size_t sep) {
298
246k
  int line = ls->linenumber;  /* initial line (for error message) */
299
246k
  save_and_next(ls);  /* skip 2nd '[' */
300
246k
  if (currIsNewline(ls))  /* string starts with a newline? */
301
173k
    inclinenumber(ls);  /* skip it */
302
493M
  for (;;) {
303
493M
    switch (ls->current) {
304
23.0k
      case EOZ: {  /* error */
305
23.0k
        const char *what = (seminfo ? "string" : "comment");
306
23.0k
        const char *msg = luaO_pushfstring(ls->L,
307
23.0k
                     "unfinished long %s (starting at line %d)", what, line);
308
23.0k
        lexerror(ls, msg, TK_EOS);
309
0
        break;  /* to avoid warnings */
310
0
      }
311
1.20M
      case ']': {
312
1.20M
        if (skip_sep(ls) == sep) {
313
223k
          save_and_next(ls);  /* skip 2nd ']' */
314
223k
          goto endloop;
315
223k
        }
316
983k
        break;
317
1.20M
      }
318
25.7M
      case '\n': case '\r': {
319
25.7M
        save(ls, '\n');
320
25.7M
        inclinenumber(ls);
321
25.7M
        if (!seminfo) luaZ_resetbuffer(ls->buff);  /* avoid wasting space */
322
25.7M
        break;
323
22.1M
      }
324
466M
      default: {
325
466M
        if (seminfo) save_and_next(ls);
326
1.05M
        else next(ls);
327
466M
      }
328
493M
    }
329
493M
  } endloop:
330
223k
  if (seminfo)
331
221k
    seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + sep,
332
221k
                                     luaZ_bufflen(ls->buff) - 2 * sep);
333
223k
}
334
335
336
1.34M
static void esccheck (LexState *ls, int c, const char *msg) {
337
1.34M
  if (!c) {
338
44.2k
    if (ls->current != EOZ)
339
40.8k
      save_and_next(ls);  /* add current to buffer for error message */
340
44.2k
    lexerror(ls, msg, TK_STRING);
341
44.2k
  }
342
1.34M
}
343
344
345
408k
static int gethexa (LexState *ls) {
346
408k
  save_and_next(ls);
347
408k
  esccheck (ls, lisxdigit(ls->current), "hexadecimal digit expected");
348
408k
  return luaO_hexavalue(ls->current);
349
408k
}
350
351
352
154k
static int readhexaesc (LexState *ls) {
353
154k
  int r = gethexa(ls);
354
154k
  r = (r << 4) + gethexa(ls);
355
154k
  luaZ_buffremove(ls->buff, 2);  /* remove saved chars from buffer */
356
154k
  return r;
357
154k
}
358
359
360
/*
361
** When reading a UTF-8 escape sequence, save everything to the buffer
362
** for error reporting in case of errors; 'i' counts the number of
363
** saved characters, so that they can be removed if case of success.
364
*/
365
104k
static l_uint32 readutf8esc (LexState *ls) {
366
104k
  l_uint32 r;
367
104k
  int i = 4;  /* number of chars to be removed: start with #"\u{X" */
368
104k
  save_and_next(ls);  /* skip 'u' */
369
104k
  esccheck(ls, ls->current == '{', "missing '{'");
370
104k
  r = cast_uint(gethexa(ls));  /* must have at least one digit */
371
410k
  while (cast_void(save_and_next(ls)), lisxdigit(ls->current)) {
372
306k
    i++;
373
306k
    esccheck(ls, r <= (0x7FFFFFFFu >> 4), "UTF-8 value too large");
374
306k
    r = (r << 4) + luaO_hexavalue(ls->current);
375
306k
  }
376
104k
  esccheck(ls, ls->current == '}', "missing '}'");
377
104k
  next(ls);  /* skip '}' */
378
104k
  luaZ_buffremove(ls->buff, i);  /* remove saved chars from buffer */
379
104k
  return r;
380
104k
}
381
382
383
104k
static void utf8esc (LexState *ls) {
384
104k
  char buff[UTF8BUFFSZ];
385
104k
  int n = luaO_utf8esc(buff, readutf8esc(ls));
386
277k
  for (; n > 0; n--)  /* add 'buff' to string */
387
173k
    save(ls, buff[UTF8BUFFSZ - n]);
388
104k
}
389
390
391
207k
static int readdecesc (LexState *ls) {
392
207k
  int i;
393
207k
  int r = 0;  /* result accumulator */
394
687k
  for (i = 0; i < 3 && lisdigit(ls->current); i++) {  /* read up to 3 digits */
395
480k
    r = 10*r + ls->current - '0';
396
480k
    save_and_next(ls);
397
480k
  }
398
207k
  esccheck(ls, r <= UCHAR_MAX, "decimal escape too large");
399
207k
  luaZ_buffremove(ls->buff, i);  /* remove read digits from buffer */
400
207k
  return r;
401
207k
}
402
403
404
2.26M
static void read_string (LexState *ls, int del, SemInfo *seminfo) {
405
2.26M
  save_and_next(ls);  /* keep delimiter (for error messages) */
406
210M
  while (ls->current != del) {
407
208M
    switch (ls->current) {
408
143k
      case EOZ:
409
143k
        lexerror(ls, "unfinished string", TK_EOS);
410
0
        break;  /* to avoid warnings */
411
22.8k
      case '\n':
412
31.7k
      case '\r':
413
31.7k
        lexerror(ls, "unfinished string", TK_STRING);
414
0
        break;  /* to avoid warnings */
415
884k
      case '\\': {  /* escape sequences */
416
884k
        int c;  /* final character to be saved */
417
884k
        save_and_next(ls);  /* keep '\\' for error messages */
418
884k
        switch (ls->current) {
419
3.64k
          case 'a': c = '\a'; goto read_save;
420
4.81k
          case 'b': c = '\b'; goto read_save;
421
3.65k
          case 'f': c = '\f'; goto read_save;
422
48.6k
          case 'n': c = '\n'; goto read_save;
423
28.2k
          case 'r': c = '\r'; goto read_save;
424
17.5k
          case 't': c = '\t'; goto read_save;
425
11.7k
          case 'v': c = '\v'; goto read_save;
426
154k
          case 'x': c = readhexaesc(ls); goto read_save;
427
104k
          case 'u': utf8esc(ls);  goto no_save;
428
4.89k
          case '\n': case '\r':
429
4.89k
            inclinenumber(ls); c = '\n'; goto only_save;
430
254k
          case '\\': case '\"': case '\'':
431
254k
            c = ls->current; goto read_save;
432
362
          case EOZ: goto no_save;  /* will raise an error next loop */
433
23.9k
          case 'z': {  /* zap following span of spaces */
434
23.9k
            luaZ_buffremove(ls->buff, 1);  /* remove '\\' */
435
23.9k
            next(ls);  /* skip the 'z' */
436
28.1k
            while (lisspace(ls->current)) {
437
28.1k
              if (currIsNewline(ls)) inclinenumber(ls);
438
26.6k
              else next(ls);
439
28.1k
            }
440
23.9k
            goto no_save;
441
249k
          }
442
223k
          default: {
443
223k
            esccheck(ls, lisdigit(ls->current), "invalid escape sequence");
444
223k
            c = readdecesc(ls);  /* digital escape '\ddd' */
445
223k
            goto only_save;
446
249k
          }
447
884k
        }
448
525k
       read_save:
449
525k
         next(ls);
450
         /* go through */
451
732k
       only_save:
452
732k
         luaZ_buffremove(ls->buff, 1);  /* remove '\\' */
453
732k
         save(ls, c);
454
         /* go through */
455
840k
       no_save: break;
456
732k
      }
457
207M
      default:
458
207M
        save_and_next(ls);
459
208M
    }
460
208M
  }
461
2.04M
  save_and_next(ls);  /* skip delimiter */
462
2.04M
  seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1,
463
2.04M
                                   luaZ_bufflen(ls->buff) - 2);
464
2.04M
}
465
466
467
417M
static int llex (LexState *ls, SemInfo *seminfo) {
468
417M
  luaZ_resetbuffer(ls->buff);
469
480M
  for (;;) {
470
480M
    switch (ls->current) {
471
20.5M
      case '\n': case '\r': {  /* line breaks */
472
20.5M
        inclinenumber(ls);
473
20.5M
        break;
474
19.1M
      }
475
42.1M
      case ' ': case '\f': case '\t': case '\v': {  /* spaces */
476
42.1M
        next(ls);
477
42.1M
        break;
478
33.7M
      }
479
3.89M
      case '-': {  /* '-' or '--' (comment) */
480
3.89M
        next(ls);
481
3.89M
        if (ls->current != '-') return '-';
482
        /* else is a comment */
483
427k
        next(ls);
484
427k
        if (ls->current == '[') {  /* long comment? */
485
4.56k
          size_t sep = skip_sep(ls);
486
4.56k
          luaZ_resetbuffer(ls->buff);  /* 'skip_sep' may dirty the buffer */
487
4.56k
          if (sep >= 2) {
488
2.77k
            read_long_string(ls, NULL, sep);  /* skip long comment */
489
2.77k
            luaZ_resetbuffer(ls->buff);  /* previous call may dirty the buff. */
490
2.77k
            break;
491
2.77k
          }
492
4.56k
        }
493
        /* else short comment */
494
91.4M
        while (!currIsNewline(ls) && ls->current != EOZ)
495
91.0M
          next(ls);  /* skip until end of line (or end of file) */
496
424k
        break;
497
427k
      }
498
721k
      case '[': {  /* long string or simply '[' */
499
721k
        size_t sep = skip_sep(ls);
500
721k
        if (sep >= 2) {
501
244k
          read_long_string(ls, seminfo, sep);
502
244k
          return TK_STRING;
503
244k
        }
504
477k
        else if (sep == 0)  /* '[=...' missing second bracket? */
505
54.3k
          lexerror(ls, "invalid long string delimiter", TK_STRING);
506
423k
        return '[';
507
721k
      }
508
6.81M
      case '=': {
509
6.81M
        next(ls);
510
6.81M
        if (check_next1(ls, '=')) return TK_EQ;  /* '==' */
511
6.34M
        else return '=';
512
6.81M
      }
513
11.2M
      case '<': {
514
11.2M
        next(ls);
515
11.2M
        if (check_next1(ls, '=')) return TK_LE;  /* '<=' */
516
11.0M
        else if (check_next1(ls, '<')) return TK_SHL;  /* '<<' */
517
10.2M
        else return '<';
518
11.2M
      }
519
120M
      case '>': {
520
120M
        next(ls);
521
120M
        if (check_next1(ls, '=')) return TK_GE;  /* '>=' */
522
120M
        else if (check_next1(ls, '>')) return TK_SHR;  /* '>>' */
523
118M
        else return '>';
524
120M
      }
525
8.85M
      case '/': {
526
8.85M
        next(ls);
527
8.85M
        if (check_next1(ls, '/')) return TK_IDIV;  /* '//' */
528
8.30M
        else return '/';
529
8.85M
      }
530
11.6M
      case '~': {
531
11.6M
        next(ls);
532
11.6M
        if (check_next1(ls, '=')) return TK_NE;  /* '~=' */
533
11.5M
        else return '~';
534
11.6M
      }
535
538k
      case ':': {
536
538k
        next(ls);
537
538k
        if (check_next1(ls, ':')) return TK_DBCOLON;  /* '::' */
538
360k
        else return ':';
539
538k
      }
540
2.26M
      case '"': case '\'': {  /* short literal strings */
541
2.26M
        read_string(ls, ls->current, seminfo);
542
2.26M
        return TK_STRING;
543
1.00M
      }
544
5.50M
      case '.': {  /* '.', '..', '...', or number */
545
5.50M
        save_and_next(ls);
546
5.50M
        if (check_next1(ls, '.')) {
547
735k
          if (check_next1(ls, '.'))
548
302k
            return TK_DOTS;   /* '...' */
549
433k
          else return TK_CONCAT;   /* '..' */
550
735k
        }
551
4.77M
        else if (!lisdigit(ls->current)) return '.';
552
309k
        else return read_numeral(ls, seminfo);
553
5.50M
      }
554
12.2M
      case '0': case '1': case '2': case '3': case '4':
555
15.5M
      case '5': case '6': case '7': case '8': case '9': {
556
15.5M
        return read_numeral(ls, seminfo);
557
14.9M
      }
558
3.65M
      case EOZ: {
559
3.65M
        return TK_EOS;
560
14.9M
      }
561
226M
      default: {
562
226M
        if (lislalpha(ls->current)) {  /* identifier or reserved word? */
563
185M
          TString *ts;
564
1.07G
          do {
565
1.07G
            save_and_next(ls);
566
1.07G
          } while (lislalnum(ls->current));
567
          /* find or create string */
568
185M
          ts = luaS_newlstr(ls->L, luaZ_buffer(ls->buff),
569
185M
                                   luaZ_bufflen(ls->buff));
570
185M
          if (isreserved(ts))   /* reserved word? */
571
8.37M
            return ts->extra - 1 + FIRST_RESERVED;
572
177M
          else {
573
177M
            seminfo->ts = anchorstr(ls, ts);
574
177M
            return TK_NAME;
575
177M
          }
576
185M
        }
577
40.7M
        else {  /* single-char tokens ('+', '*', '%', '{', '}', ...) */
578
40.7M
          int c = ls->current;
579
40.7M
          next(ls);
580
40.7M
          return c;
581
40.7M
        }
582
226M
      }
583
480M
    }
584
480M
  }
585
417M
}
586
587
588
417M
void luaX_next (LexState *ls) {
589
417M
  ls->lastline = ls->linenumber;
590
417M
  if (ls->lookahead.token != TK_EOS) {  /* is there a look-ahead token? */
591
9.74M
    ls->t = ls->lookahead;  /* use this one */
592
9.74M
    ls->lookahead.token = TK_EOS;  /* and discharge it */
593
9.74M
  }
594
407M
  else
595
407M
    ls->t.token = llex(ls, &ls->t.seminfo);  /* read next token */
596
417M
}
597
598
599
9.76M
int luaX_lookahead (LexState *ls) {
600
9.76M
  lua_assert(ls->lookahead.token == TK_EOS);
601
9.76M
  ls->lookahead.token = llex(ls, &ls->lookahead.seminfo);
602
9.76M
  return ls->lookahead.token;
603
9.76M
}
604