Coverage Report

Created: 2025-12-14 06:40

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