Coverage Report

Created: 2026-01-17 06:33

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