Coverage Report

Created: 2025-10-10 06:38

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/testdir/build/lua-master/source/llex.c
Line
Count
Source
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
101M
#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
4.47M
#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
68.8M
#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
71.0M
static void save (LexState *ls, int c) {
63
71.0M
  Mbuffer *b = ls->buff;
64
71.0M
  if (luaZ_bufflen(b) + 1 > luaZ_sizebuffer(b)) {
65
3.63k
    size_t newsize = luaZ_sizebuffer(b);  /* get old size */;
66
3.63k
    if (newsize >= (MAX_SIZE/3 * 2))  /* larger than MAX_SIZE/1.5 ? */
67
0
      lexerror(ls, "lexical element too long", 0);
68
3.63k
    newsize += (newsize >> 1);  /* new size is 1.5 times the old one */
69
3.63k
    luaZ_resizebuffer(ls->L, b, newsize);
70
3.63k
  }
71
71.0M
  b->buffer[luaZ_bufflen(b)++] = cast_char(c);
72
71.0M
}
73
74
75
456
void luaX_init (lua_State *L) {
76
456
  int i;
77
456
  TString *e = luaS_newliteral(L, LUA_ENV);  /* create env name */
78
456
  luaC_fix(L, obj2gco(e));  /* never collect this name */
79
10.9k
  for (i=0; i<NUM_RESERVED; i++) {
80
10.4k
    TString *ts = luaS_new(L, luaX_tokens[i]);
81
10.4k
    luaC_fix(L, obj2gco(ts));  /* reserved words are never collected */
82
10.4k
    ts->extra = cast_byte(i+1);  /* reserved word */
83
10.4k
  }
84
456
}
85
86
87
276
const char *luaX_token2str (LexState *ls, int token) {
88
276
  if (token < FIRST_RESERVED) {  /* single-byte symbols? */
89
221
    if (lisprint(token))
90
175
      return luaO_pushfstring(ls->L, "'%c'", token);
91
46
    else  /* control character */
92
46
      return luaO_pushfstring(ls->L, "'<\\%d>'", token);
93
221
  }
94
55
  else {
95
55
    const char *s = luaX_tokens[token - FIRST_RESERVED];
96
55
    if (token < TK_EOS)  /* fixed format (symbols and reserved words)? */
97
11
      return luaO_pushfstring(ls->L, "'%s'", s);
98
44
    else  /* names, strings, and numerals */
99
44
      return s;
100
55
  }
101
276
}
102
103
104
291
static const char *txtToken (LexState *ls, int token) {
105
291
  switch (token) {
106
56
    case TK_NAME: case TK_STRING:
107
73
    case TK_FLT: case TK_INT:
108
73
      save(ls, '\0');
109
73
      return luaO_pushfstring(ls->L, "'%s'", luaZ_buffer(ls->buff));
110
218
    default:
111
218
      return luaX_token2str(ls, token);
112
291
  }
113
291
}
114
115
116
302
static l_noret lexerror (LexState *ls, const char *msg, int token) {
117
302
  msg = luaG_addinfo(ls->L, msg, ls->source, ls->linenumber);
118
302
  if (token)
119
291
    luaO_pushfstring(ls->L, "%s near %s", msg, txtToken(ls, token));
120
302
  luaD_throw(ls->L, LUA_ERRSYNTAX);
121
302
}
122
123
124
230
l_noret luaX_syntaxerror (LexState *ls, const char *msg) {
125
230
  lexerror(ls, msg, ls->t.token);
126
230
}
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
27.8M
static TString *anchorstr (LexState *ls, TString *ts) {
136
27.8M
  lua_State *L = ls->L;
137
27.8M
  TValue oldts;
138
27.8M
  int tag = luaH_getstr(ls->h, ts, &oldts);
139
27.8M
  if (!tagisempty(tag))  /* string already present? */
140
27.8M
    return tsvalue(&oldts);  /* use stored value */
141
21.9k
  else {  /* create a new entry */
142
21.9k
    TValue *stv = s2v(L->top.p++);  /* reserve stack space for string */
143
21.9k
    setsvalue(L, stv, ts);  /* push (anchor) the string on the stack */
144
21.9k
    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
21.9k
    luaC_checkGC(L);
147
21.9k
    L->top.p--;  /* remove string from stack */
148
21.9k
    return ts;
149
21.9k
  }
150
27.8M
}
151
152
153
/*
154
** Creates a new string and anchors it in scanner's table.
155
*/
156
25.7k
TString *luaX_newstring (LexState *ls, const char *str, size_t l) {
157
25.7k
  return anchorstr(ls, luaS_newlstr(ls->L, str, l));
158
25.7k
}
159
160
161
/*
162
** increment line number and skips newline sequence (any of
163
** \n, \r, \n\r, or \r\n)
164
*/
165
1.05M
static void inclinenumber (LexState *ls) {
166
1.05M
  int old = ls->current;
167
1.05M
  lua_assert(currIsNewline(ls));
168
1.05M
  next(ls);  /* skip '\n' or '\r' */
169
1.05M
  if (currIsNewline(ls) && ls->current != old)
170
2.78k
    next(ls);  /* skip '\n\r' or '\r\n' */
171
1.05M
  if (++ls->linenumber >= INT_MAX)
172
0
    lexerror(ls, "chunk has too many lines", 0);
173
1.05M
}
174
175
176
void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source,
177
456
                    int firstchar) {
178
456
  ls->t.token = 0;
179
456
  ls->L = L;
180
456
  ls->current = firstchar;
181
456
  ls->lookahead.token = TK_EOS;  /* no look-ahead token */
182
456
  ls->z = z;
183
456
  ls->fs = NULL;
184
456
  ls->linenumber = 1;
185
456
  ls->lastline = 1;
186
456
  ls->source = source;
187
  /* all three strings here ("_ENV", "break", "global") were fixed,
188
     so they cannot be collected */
189
456
  ls->envn = luaS_newliteral(L, LUA_ENV);  /* get env string */
190
456
  ls->brkn = luaS_newliteral(L, "break");  /* get "break" string */
191
456
#if defined(LUA_COMPAT_GLOBAL)
192
  /* compatibility mode: "global" is not a reserved word */
193
456
  ls->glbn = luaS_newliteral(L, "global");  /* get "global" string */
194
456
  ls->glbn->extra = 0;  /* mark it as not reserved */
195
456
#endif
196
456
  luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER);  /* initialize buffer */
197
456
}
198
199
200
201
/*
202
** =======================================================
203
** LEXICAL ANALYZER
204
** =======================================================
205
*/
206
207
208
53.5M
static int check_next1 (LexState *ls, int c) {
209
53.5M
  if (ls->current == c) {
210
495k
    next(ls);
211
495k
    return 1;
212
495k
  }
213
53.0M
  else return 0;
214
53.5M
}
215
216
217
/*
218
** Check whether current char is in set 'set' (with two chars) and
219
** saves it
220
*/
221
3.53M
static int check_next2 (LexState *ls, const char *set) {
222
3.53M
  lua_assert(set[2] == '\0');
223
3.53M
  if (ls->current == set[0] || ls->current == set[1]) {
224
1.87k
    save_and_next(ls);
225
1.87k
    return 1;
226
1.87k
  }
227
3.53M
  else return 0;
228
3.53M
}
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
1.09M
static int read_numeral (LexState *ls, SemInfo *seminfo) {
245
1.09M
  TValue obj;
246
1.09M
  const char *expo = "Ee";
247
1.09M
  int first = ls->current;
248
1.09M
  lua_assert(lisdigit(ls->current));
249
1.09M
  save_and_next(ls);
250
1.09M
  if (first == '0' && check_next2(ls, "xX"))  /* hexadecimal? */
251
10
    expo = "Pp";
252
2.75M
  for (;;) {
253
2.75M
    if (check_next2(ls, expo))  /* exponent mark? */
254
1.85k
      check_next2(ls, "-+");  /* optional exponent sign */
255
2.75M
    else if (lisxdigit(ls->current) || ls->current == '.')  /* '%x|%.' */
256
1.66M
      save_and_next(ls);
257
1.09M
    else break;
258
2.75M
  }
259
1.09M
  if (lislalpha(ls->current))  /* is numeral touching a letter? */
260
5
    save_and_next(ls);  /* force an error */
261
1.09M
  save(ls, '\0');
262
1.09M
  if (luaO_str2num(luaZ_buffer(ls->buff), &obj) == 0)  /* format error? */
263
6
    lexerror(ls, "malformed number", TK_FLT);
264
1.09M
  if (ttisinteger(&obj)) {
265
1.07M
    seminfo->i = ivalue(&obj);
266
1.07M
    return TK_INT;
267
1.07M
  }
268
14.9k
  else {
269
14.9k
    lua_assert(ttisfloat(&obj));
270
14.9k
    seminfo->r = fltvalue(&obj);
271
14.9k
    return TK_FLT;
272
14.9k
  }
273
1.09M
}
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
30.4k
static size_t skip_sep (LexState *ls) {
283
30.4k
  size_t count = 0;
284
30.4k
  int s = ls->current;
285
30.4k
  lua_assert(s == '[' || s == ']');
286
30.4k
  save_and_next(ls);
287
1.09M
  while (ls->current == '=') {
288
1.06M
    save_and_next(ls);
289
1.06M
    count++;
290
1.06M
  }
291
30.4k
  return (ls->current == s) ? count + 2
292
30.4k
         : (count == 0) ? 1
293
24.6k
         : 0;
294
30.4k
}
295
296
297
1.45k
static void read_long_string (LexState *ls, SemInfo *seminfo, size_t sep) {
298
1.45k
  int line = ls->linenumber;  /* initial line (for error message) */
299
1.45k
  save_and_next(ls);  /* skip 2nd '[' */
300
1.45k
  if (currIsNewline(ls))  /* string starts with a newline? */
301
53
    inclinenumber(ls);  /* skip it */
302
11.0M
  for (;;) {
303
11.0M
    switch (ls->current) {
304
21
      case EOZ: {  /* error */
305
21
        const char *what = (seminfo ? "string" : "comment");
306
21
        const char *msg = luaO_pushfstring(ls->L,
307
21
                     "unfinished long %s (starting at line %d)", what, line);
308
21
        lexerror(ls, msg, TK_EOS);
309
0
        break;  /* to avoid warnings */
310
0
      }
311
27.9k
      case ']': {
312
27.9k
        if (skip_sep(ls) == sep) {
313
1.43k
          save_and_next(ls);  /* skip 2nd ']' */
314
1.43k
          goto endloop;
315
1.43k
        }
316
26.5k
        break;
317
27.9k
      }
318
1.00M
      case '\n': case '\r': {
319
1.00M
        save(ls, '\n');
320
1.00M
        inclinenumber(ls);
321
1.00M
        if (!seminfo) luaZ_resetbuffer(ls->buff);  /* avoid wasting space */
322
1.00M
        break;
323
944k
      }
324
10.0M
      default: {
325
10.0M
        if (seminfo) save_and_next(ls);
326
902k
        else next(ls);
327
10.0M
      }
328
11.0M
    }
329
11.0M
  } endloop:
330
1.43k
  if (seminfo)
331
1.43k
    seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + sep,
332
1.43k
                                     luaZ_bufflen(ls->buff) - 2 * sep);
333
1.43k
}
334
335
336
152k
static void esccheck (LexState *ls, int c, const char *msg) {
337
152k
  if (!c) {
338
30
    if (ls->current != EOZ)
339
29
      save_and_next(ls);  /* add current to buffer for error message */
340
30
    lexerror(ls, msg, TK_STRING);
341
30
  }
342
152k
}
343
344
345
59.6k
static int gethexa (LexState *ls) {
346
59.6k
  save_and_next(ls);
347
59.6k
  esccheck (ls, lisxdigit(ls->current), "hexadecimal digit expected");
348
59.6k
  return luaO_hexavalue(ls->current);
349
59.6k
}
350
351
352
28.7k
static int readhexaesc (LexState *ls) {
353
28.7k
  int r = gethexa(ls);
354
28.7k
  r = (r << 4) + gethexa(ls);
355
28.7k
  luaZ_buffremove(ls->buff, 2);  /* remove saved chars from buffer */
356
28.7k
  return r;
357
28.7k
}
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
2.28k
static l_uint32 readutf8esc (LexState *ls) {
366
2.28k
  l_uint32 r;
367
2.28k
  int i = 4;  /* number of chars to be removed: start with #"\u{X" */
368
2.28k
  save_and_next(ls);  /* skip 'u' */
369
2.28k
  esccheck(ls, ls->current == '{', "missing '{'");
370
2.28k
  r = cast_uint(gethexa(ls));  /* must have at least one digit */
371
3.35k
  while (cast_void(save_and_next(ls)), lisxdigit(ls->current)) {
372
1.07k
    i++;
373
1.07k
    esccheck(ls, r <= (0x7FFFFFFFu >> 4), "UTF-8 value too large");
374
1.07k
    r = (r << 4) + luaO_hexavalue(ls->current);
375
1.07k
  }
376
2.28k
  esccheck(ls, ls->current == '}', "missing '}'");
377
2.28k
  next(ls);  /* skip '}' */
378
2.28k
  luaZ_buffremove(ls->buff, i);  /* remove saved chars from buffer */
379
2.28k
  return r;
380
2.28k
}
381
382
383
2.28k
static void utf8esc (LexState *ls) {
384
2.28k
  char buff[UTF8BUFFSZ];
385
2.28k
  int n = luaO_utf8esc(buff, readutf8esc(ls));
386
4.72k
  for (; n > 0; n--)  /* add 'buff' to string */
387
2.43k
    save(ls, buff[UTF8BUFFSZ - n]);
388
2.28k
}
389
390
391
43.7k
static int readdecesc (LexState *ls) {
392
43.7k
  int i;
393
43.7k
  int r = 0;  /* result accumulator */
394
123k
  for (i = 0; i < 3 && lisdigit(ls->current); i++) {  /* read up to 3 digits */
395
79.9k
    r = 10*r + ls->current - '0';
396
79.9k
    save_and_next(ls);
397
79.9k
  }
398
43.7k
  esccheck(ls, r <= UCHAR_MAX, "decimal escape too large");
399
43.7k
  luaZ_buffremove(ls->buff, i);  /* remove read digits from buffer */
400
43.7k
  return r;
401
43.7k
}
402
403
404
22.2k
static void read_string (LexState *ls, int del, SemInfo *seminfo) {
405
22.2k
  save_and_next(ls);  /* keep delimiter (for error messages) */
406
24.2M
  while (ls->current != del) {
407
24.2M
    switch (ls->current) {
408
7
      case EOZ:
409
7
        lexerror(ls, "unfinished string", TK_EOS);
410
0
        break;  /* to avoid warnings */
411
6
      case '\n':
412
6
      case '\r':
413
6
        lexerror(ls, "unfinished string", TK_STRING);
414
0
        break;  /* to avoid warnings */
415
86.9k
      case '\\': {  /* escape sequences */
416
86.9k
        int c;  /* final character to be saved */
417
86.9k
        save_and_next(ls);  /* keep '\\' for error messages */
418
86.9k
        switch (ls->current) {
419
659
          case 'a': c = '\a'; goto read_save;
420
2
          case 'b': c = '\b'; goto read_save;
421
0
          case 'f': c = '\f'; goto read_save;
422
461
          case 'n': c = '\n'; goto read_save;
423
175
          case 'r': c = '\r'; goto read_save;
424
7.55k
          case 't': c = '\t'; goto read_save;
425
2.19k
          case 'v': c = '\v'; goto read_save;
426
28.7k
          case 'x': c = readhexaesc(ls); goto read_save;
427
2.28k
          case 'u': utf8esc(ls);  goto no_save;
428
0
          case '\n': case '\r':
429
0
            inclinenumber(ls); c = '\n'; goto only_save;
430
617
          case '\\': case '\"': case '\'':
431
617
            c = ls->current; goto read_save;
432
1
          case EOZ: goto no_save;  /* will raise an error next loop */
433
541
          case 'z': {  /* zap following span of spaces */
434
541
            luaZ_buffremove(ls->buff, 1);  /* remove '\\' */
435
541
            next(ls);  /* skip the 'z' */
436
541
            while (lisspace(ls->current)) {
437
272
              if (currIsNewline(ls)) inclinenumber(ls);
438
272
              else next(ls);
439
272
            }
440
541
            goto no_save;
441
596
          }
442
43.7k
          default: {
443
43.7k
            esccheck(ls, lisdigit(ls->current), "invalid escape sequence");
444
43.7k
            c = readdecesc(ls);  /* digital escape '\ddd' */
445
43.7k
            goto only_save;
446
596
          }
447
86.9k
        }
448
40.3k
       read_save:
449
40.3k
         next(ls);
450
         /* go through */
451
84.1k
       only_save:
452
84.1k
         luaZ_buffremove(ls->buff, 1);  /* remove '\\' */
453
84.1k
         save(ls, c);
454
         /* go through */
455
86.9k
       no_save: break;
456
84.1k
      }
457
24.1M
      default:
458
24.1M
        save_and_next(ls);
459
24.2M
    }
460
24.2M
  }
461
22.2k
  save_and_next(ls);  /* skip delimiter */
462
22.2k
  seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1,
463
22.2k
                                   luaZ_bufflen(ls->buff) - 2);
464
22.2k
}
465
466
467
58.1M
static int llex (LexState *ls, SemInfo *seminfo) {
468
58.1M
  luaZ_resetbuffer(ls->buff);
469
58.2M
  for (;;) {
470
58.2M
    switch (ls->current) {
471
49.3k
      case '\n': case '\r': {  /* line breaks */
472
49.3k
        inclinenumber(ls);
473
49.3k
        break;
474
22.8k
      }
475
35.5k
      case ' ': case '\f': case '\t': case '\v': {  /* spaces */
476
35.5k
        next(ls);
477
35.5k
        break;
478
32.0k
      }
479
85.3k
      case '-': {  /* '-' or '--' (comment) */
480
85.3k
        next(ls);
481
85.3k
        if (ls->current != '-') return '-';
482
        /* else is a comment */
483
8.26k
        next(ls);
484
8.26k
        if (ls->current == '[') {  /* long comment? */
485
13
          size_t sep = skip_sep(ls);
486
13
          luaZ_resetbuffer(ls->buff);  /* 'skip_sep' may dirty the buffer */
487
13
          if (sep >= 2) {
488
5
            read_long_string(ls, NULL, sep);  /* skip long comment */
489
5
            luaZ_resetbuffer(ls->buff);  /* previous call may dirty the buff. */
490
5
            break;
491
5
          }
492
13
        }
493
        /* else short comment */
494
1.18M
        while (!currIsNewline(ls) && ls->current != EOZ)
495
1.17M
          next(ls);  /* skip until end of line (or end of file) */
496
8.26k
        break;
497
8.26k
      }
498
2.52k
      case '[': {  /* long string or simply '[' */
499
2.52k
        size_t sep = skip_sep(ls);
500
2.52k
        if (sep >= 2) {
501
1.45k
          read_long_string(ls, seminfo, sep);
502
1.45k
          return TK_STRING;
503
1.45k
        }
504
1.07k
        else if (sep == 0)  /* '[=...' missing second bracket? */
505
2
          lexerror(ls, "invalid long string delimiter", TK_STRING);
506
1.07k
        return '[';
507
2.52k
      }
508
17.9k
      case '=': {
509
17.9k
        next(ls);
510
17.9k
        if (check_next1(ls, '=')) return TK_EQ;  /* '==' */
511
15.5k
        else return '=';
512
17.9k
      }
513
559k
      case '<': {
514
559k
        next(ls);
515
559k
        if (check_next1(ls, '=')) return TK_LE;  /* '<=' */
516
554k
        else if (check_next1(ls, '<')) return TK_SHL;  /* '<<' */
517
517k
        else return '<';
518
559k
      }
519
25.3M
      case '>': {
520
25.3M
        next(ls);
521
25.3M
        if (check_next1(ls, '=')) return TK_GE;  /* '>=' */
522
25.3M
        else if (check_next1(ls, '>')) return TK_SHR;  /* '>>' */
523
24.8M
        else return '>';
524
25.3M
      }
525
1.56M
      case '/': {
526
1.56M
        next(ls);
527
1.56M
        if (check_next1(ls, '/')) return TK_IDIV;  /* '//' */
528
1.54M
        else return '/';
529
1.56M
      }
530
158k
      case '~': {
531
158k
        next(ls);
532
158k
        if (check_next1(ls, '=')) return TK_NE;  /* '~=' */
533
158k
        else return '~';
534
158k
      }
535
1.34k
      case ':': {
536
1.34k
        next(ls);
537
1.34k
        if (check_next1(ls, ':')) return TK_DBCOLON;  /* '::' */
538
581
        else return ':';
539
1.34k
      }
540
22.2k
      case '"': case '\'': {  /* short literal strings */
541
22.2k
        read_string(ls, ls->current, seminfo);
542
22.2k
        return TK_STRING;
543
15.7k
      }
544
21.0k
      case '.': {  /* '.', '..', '...', or number */
545
21.0k
        save_and_next(ls);
546
21.0k
        if (check_next1(ls, '.')) {
547
7.96k
          if (check_next1(ls, '.'))
548
3.60k
            return TK_DOTS;   /* '...' */
549
4.35k
          else return TK_CONCAT;   /* '..' */
550
7.96k
        }
551
13.1k
        else if (!lisdigit(ls->current)) return '.';
552
371
        else return read_numeral(ls, seminfo);
553
21.0k
      }
554
917k
      case '0': case '1': case '2': case '3': case '4':
555
1.09M
      case '5': case '6': case '7': case '8': case '9': {
556
1.09M
        return read_numeral(ls, seminfo);
557
1.00M
      }
558
165
      case EOZ: {
559
165
        return TK_EOS;
560
1.00M
      }
561
29.2M
      default: {
562
29.2M
        if (lislalpha(ls->current)) {  /* identifier or reserved word? */
563
27.9M
          TString *ts;
564
31.4M
          do {
565
31.4M
            save_and_next(ls);
566
31.4M
          } while (lislalnum(ls->current));
567
          /* find or create string */
568
27.9M
          ts = luaS_newlstr(ls->L, luaZ_buffer(ls->buff),
569
27.9M
                                   luaZ_bufflen(ls->buff));
570
27.9M
          if (isreserved(ts))   /* reserved word? */
571
52.7k
            return ts->extra - 1 + FIRST_RESERVED;
572
27.8M
          else {
573
27.8M
            seminfo->ts = anchorstr(ls, ts);
574
27.8M
            return TK_NAME;
575
27.8M
          }
576
27.9M
        }
577
1.36M
        else {  /* single-char tokens ('+', '*', '%', '{', '}', ...) */
578
1.36M
          int c = ls->current;
579
1.36M
          next(ls);
580
1.36M
          return c;
581
1.36M
        }
582
29.2M
      }
583
58.2M
    }
584
58.2M
  }
585
58.1M
}
586
587
588
58.1M
void luaX_next (LexState *ls) {
589
58.1M
  ls->lastline = ls->linenumber;
590
58.1M
  if (ls->lookahead.token != TK_EOS) {  /* is there a look-ahead token? */
591
891k
    ls->t = ls->lookahead;  /* use this one */
592
891k
    ls->lookahead.token = TK_EOS;  /* and discharge it */
593
891k
  }
594
57.2M
  else
595
57.2M
    ls->t.token = llex(ls, &ls->t.seminfo);  /* read next token */
596
58.1M
}
597
598
599
891k
int luaX_lookahead (LexState *ls) {
600
891k
  lua_assert(ls->lookahead.token == TK_EOS);
601
891k
  ls->lookahead.token = llex(ls, &ls->lookahead.seminfo);
602
891k
  return ls->lookahead.token;
603
891k
}
604