Coverage Report

Created: 2023-09-15 06:20

/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
65.6M
#define next(ls)  (ls->current = zgetc(ls->z))
33
34
35
36
15.3M
#define currIsNewline(ls) (ls->current == '\n' || ls->current == '\r')
37
38
39
/* ORDER RESERVED */
40
static const char *const luaX_tokens [] = {
41
    "and", "break", "do", "else", "elseif",
42
    "end", "false", "for", "function", "goto", "if",
43
    "in", "local", "nil", "not", "or", "repeat",
44
    "return", "then", "true", "until", "while",
45
    "//", "..", "...", "==", ">=", "<=", "~=",
46
    "<<", ">>", "::", "<eof>",
47
    "<number>", "<integer>", "<name>", "<string>"
48
};
49
50
51
43.8M
#define save_and_next(ls) (save(ls, ls->current), next(ls))
52
53
54
static l_noret lexerror (LexState *ls, const char *msg, int token);
55
56
57
45.9M
static void save (LexState *ls, int c) {
58
45.9M
  Mbuffer *b = ls->buff;
59
45.9M
  if (luaZ_bufflen(b) + 1 > luaZ_sizebuffer(b)) {
60
1.73k
    size_t newsize;
61
1.73k
    if (luaZ_sizebuffer(b) >= MAX_SIZE/2)
62
0
      lexerror(ls, "lexical element too long", 0);
63
1.73k
    newsize = luaZ_sizebuffer(b) * 2;
64
1.73k
    luaZ_resizebuffer(ls->L, b, newsize);
65
1.73k
  }
66
45.9M
  b->buffer[luaZ_bufflen(b)++] = cast_char(c);
67
45.9M
}
68
69
70
390
void luaX_init (lua_State *L) {
71
390
  int i;
72
390
  TString *e = luaS_newliteral(L, LUA_ENV);  /* create env name */
73
390
  luaC_fix(L, obj2gco(e));  /* never collect this name */
74
8.97k
  for (i=0; i<NUM_RESERVED; i++) {
75
8.58k
    TString *ts = luaS_new(L, luaX_tokens[i]);
76
8.58k
    luaC_fix(L, obj2gco(ts));  /* reserved words are never collected */
77
8.58k
    ts->extra = cast_byte(i+1);  /* reserved word */
78
8.58k
  }
79
390
}
80
81
82
291
const char *luaX_token2str (LexState *ls, int token) {
83
291
  if (token < FIRST_RESERVED) {  /* single-byte symbols? */
84
205
    if (lisprint(token))
85
132
      return luaO_pushfstring(ls->L, "'%c'", token);
86
73
    else  /* control character */
87
73
      return luaO_pushfstring(ls->L, "'<\\%d>'", token);
88
205
  }
89
86
  else {
90
86
    const char *s = luaX_tokens[token - FIRST_RESERVED];
91
86
    if (token < TK_EOS)  /* fixed format (symbols and reserved words)? */
92
40
      return luaO_pushfstring(ls->L, "'%s'", s);
93
46
    else  /* names, strings, and numerals */
94
46
      return s;
95
86
  }
96
291
}
97
98
99
300
static const char *txtToken (LexState *ls, int token) {
100
300
  switch (token) {
101
72
    case TK_NAME: case TK_STRING:
102
115
    case TK_FLT: case TK_INT:
103
115
      save(ls, '\0');
104
115
      return luaO_pushfstring(ls->L, "'%s'", luaZ_buffer(ls->buff));
105
185
    default:
106
185
      return luaX_token2str(ls, token);
107
300
  }
108
300
}
109
110
111
321
static l_noret lexerror (LexState *ls, const char *msg, int token) {
112
321
  msg = luaG_addinfo(ls->L, msg, ls->source, ls->linenumber);
113
321
  if (token)
114
300
    luaO_pushfstring(ls->L, "%s near %s", msg, txtToken(ls, token));
115
321
  luaD_throw(ls->L, LUA_ERRSYNTAX);
116
321
}
117
118
119
208
l_noret luaX_syntaxerror (LexState *ls, const char *msg) {
120
208
  lexerror(ls, msg, ls->t.token);
121
208
}
122
123
124
/*
125
** Creates a new string and anchors it in scanner's table so that it
126
** will not be collected until the end of the compilation; by that time
127
** it should be anchored somewhere. It also internalizes long strings,
128
** ensuring there is only one copy of each unique string.  The table
129
** here is used as a set: the string enters as the key, while its value
130
** is irrelevant. We use the string itself as the value only because it
131
** is a TValue readily available. Later, the code generation can change
132
** this value.
133
*/
134
13.5M
TString *luaX_newstring (LexState *ls, const char *str, size_t l) {
135
13.5M
  lua_State *L = ls->L;
136
13.5M
  TString *ts = luaS_newlstr(L, str, l);  /* create new string */
137
13.5M
  const TValue *o = luaH_getstr(ls->h, ts);
138
13.5M
  if (!ttisnil(o))  /* string already present? */
139
13.5M
    ts = keystrval(nodefromval(o));  /* get saved copy */
140
22.5k
  else {  /* not in use yet */
141
22.5k
    TValue *stv = s2v(L->top.p++);  /* reserve stack space for string */
142
22.5k
    setsvalue(L, stv, ts);  /* temporarily anchor the string */
143
22.5k
    luaH_finishset(L, ls->h, stv, o, stv);  /* t[string] = string */
144
    /* table is not a metatable, so it does not need to invalidate cache */
145
22.5k
    luaC_checkGC(L);
146
22.5k
    L->top.p--;  /* remove string from stack */
147
22.5k
  }
148
13.5M
  return ts;
149
13.5M
}
150
151
152
/*
153
** increment line number and skips newline sequence (any of
154
** \n, \r, \n\r, or \r\n)
155
*/
156
1.97M
static void inclinenumber (LexState *ls) {
157
1.97M
  int old = ls->current;
158
1.97M
  lua_assert(currIsNewline(ls));
159
1.97M
  next(ls);  /* skip '\n' or '\r' */
160
1.97M
  if (currIsNewline(ls) && ls->current != old)
161
80.0k
    next(ls);  /* skip '\n\r' or '\r\n' */
162
1.97M
  if (++ls->linenumber >= MAX_INT)
163
0
    lexerror(ls, "chunk has too many lines", 0);
164
1.97M
}
165
166
167
void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source,
168
390
                    int firstchar) {
169
390
  ls->t.token = 0;
170
390
  ls->L = L;
171
390
  ls->current = firstchar;
172
390
  ls->lookahead.token = TK_EOS;  /* no look-ahead token */
173
390
  ls->z = z;
174
390
  ls->fs = NULL;
175
390
  ls->linenumber = 1;
176
390
  ls->lastline = 1;
177
390
  ls->source = source;
178
390
  ls->envn = luaS_newliteral(L, LUA_ENV);  /* get env name */
179
390
  luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER);  /* initialize buffer */
180
390
}
181
182
183
184
/*
185
** =======================================================
186
** LEXICAL ANALYZER
187
** =======================================================
188
*/
189
190
191
19.1M
static int check_next1 (LexState *ls, int c) {
192
19.1M
  if (ls->current == c) {
193
439k
    next(ls);
194
439k
    return 1;
195
439k
  }
196
18.6M
  else return 0;
197
19.1M
}
198
199
200
/*
201
** Check whether current char is in set 'set' (with two chars) and
202
** saves it
203
*/
204
2.23M
static int check_next2 (LexState *ls, const char *set) {
205
2.23M
  lua_assert(set[2] == '\0');
206
2.23M
  if (ls->current == set[0] || ls->current == set[1]) {
207
883
    save_and_next(ls);
208
883
    return 1;
209
883
  }
210
2.22M
  else return 0;
211
2.23M
}
212
213
214
/* LUA_NUMBER */
215
/*
216
** This function is quite liberal in what it accepts, as 'luaO_str2num'
217
** will reject ill-formed numerals. Roughly, it accepts the following
218
** pattern:
219
**
220
**   %d(%x|%.|([Ee][+-]?))* | 0[Xx](%x|%.|([Pp][+-]?))*
221
**
222
** The only tricky part is to accept [+-] only after a valid exponent
223
** mark, to avoid reading '3-4' or '0xe+1' as a single number.
224
**
225
** The caller might have already read an initial dot.
226
*/
227
349k
static int read_numeral (LexState *ls, SemInfo *seminfo) {
228
349k
  TValue obj;
229
349k
  const char *expo = "Ee";
230
349k
  int first = ls->current;
231
349k
  lua_assert(lisdigit(ls->current));
232
349k
  save_and_next(ls);
233
349k
  if (first == '0' && check_next2(ls, "xX"))  /* hexadecimal? */
234
3
    expo = "Pp";
235
2.16M
  for (;;) {
236
2.16M
    if (check_next2(ls, expo))  /* exponent mark? */
237
854
      check_next2(ls, "-+");  /* optional exponent sign */
238
2.16M
    else if (lisxdigit(ls->current) || ls->current == '.')  /* '%x|%.' */
239
1.81M
      save_and_next(ls);
240
349k
    else break;
241
2.16M
  }
242
349k
  if (lislalpha(ls->current))  /* is numeral touching a letter? */
243
35
    save_and_next(ls);  /* force an error */
244
349k
  save(ls, '\0');
245
349k
  if (luaO_str2num(luaZ_buffer(ls->buff), &obj) == 0)  /* format error? */
246
39
    lexerror(ls, "malformed number", TK_FLT);
247
349k
  if (ttisinteger(&obj)) {
248
308k
    seminfo->i = ivalue(&obj);
249
308k
    return TK_INT;
250
308k
  }
251
40.9k
  else {
252
40.9k
    lua_assert(ttisfloat(&obj));
253
40.9k
    seminfo->r = fltvalue(&obj);
254
40.9k
    return TK_FLT;
255
40.9k
  }
256
349k
}
257
258
259
/*
260
** read a sequence '[=*[' or ']=*]', leaving the last bracket. If
261
** sequence is well formed, return its number of '='s + 2; otherwise,
262
** return 1 if it is a single bracket (no '='s and no 2nd bracket);
263
** otherwise (an unfinished '[==...') return 0.
264
*/
265
441k
static size_t skip_sep (LexState *ls) {
266
441k
  size_t count = 0;
267
441k
  int s = ls->current;
268
441k
  lua_assert(s == '[' || s == ']');
269
441k
  save_and_next(ls);
270
442k
  while (ls->current == '=') {
271
602
    save_and_next(ls);
272
602
    count++;
273
602
  }
274
441k
  return (ls->current == s) ? count + 2
275
441k
         : (count == 0) ? 1
276
32.6k
         : 0;
277
441k
}
278
279
280
204k
static void read_long_string (LexState *ls, SemInfo *seminfo, size_t sep) {
281
204k
  int line = ls->linenumber;  /* initial line (for error message) */
282
204k
  save_and_next(ls);  /* skip 2nd '[' */
283
204k
  if (currIsNewline(ls))  /* string starts with a newline? */
284
197k
    inclinenumber(ls);  /* skip it */
285
7.91M
  for (;;) {
286
7.91M
    switch (ls->current) {
287
11
      case EOZ: {  /* error */
288
11
        const char *what = (seminfo ? "string" : "comment");
289
11
        const char *msg = luaO_pushfstring(ls->L,
290
11
                     "unfinished long %s (starting at line %d)", what, line);
291
11
        lexerror(ls, msg, TK_EOS);
292
0
        break;  /* to avoid warnings */
293
0
      }
294
213k
      case ']': {
295
213k
        if (skip_sep(ls) == sep) {
296
204k
          save_and_next(ls);  /* skip 2nd ']' */
297
204k
          goto endloop;
298
204k
        }
299
9.24k
        break;
300
213k
      }
301
1.55M
      case '\n': case '\r': {
302
1.55M
        save(ls, '\n');
303
1.55M
        inclinenumber(ls);
304
1.55M
        if (!seminfo) luaZ_resetbuffer(ls->buff);  /* avoid wasting space */
305
1.55M
        break;
306
123k
      }
307
6.14M
      default: {
308
6.14M
        if (seminfo) save_and_next(ls);
309
69
        else next(ls);
310
6.14M
      }
311
7.91M
    }
312
7.91M
  } endloop:
313
204k
  if (seminfo)
314
204k
    seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + sep,
315
204k
                                     luaZ_bufflen(ls->buff) - 2 * sep);
316
204k
}
317
318
319
131k
static void esccheck (LexState *ls, int c, const char *msg) {
320
131k
  if (!c) {
321
46
    if (ls->current != EOZ)
322
46
      save_and_next(ls);  /* add current to buffer for error message */
323
46
    lexerror(ls, msg, TK_STRING);
324
46
  }
325
131k
}
326
327
328
13.0k
static int gethexa (LexState *ls) {
329
13.0k
  save_and_next(ls);
330
13.0k
  esccheck (ls, lisxdigit(ls->current), "hexadecimal digit expected");
331
13.0k
  return luaO_hexavalue(ls->current);
332
13.0k
}
333
334
335
1.76k
static int readhexaesc (LexState *ls) {
336
1.76k
  int r = gethexa(ls);
337
1.76k
  r = (r << 4) + gethexa(ls);
338
1.76k
  luaZ_buffremove(ls->buff, 2);  /* remove saved chars from buffer */
339
1.76k
  return r;
340
1.76k
}
341
342
343
9.48k
static unsigned long readutf8esc (LexState *ls) {
344
9.48k
  unsigned long r;
345
9.48k
  int i = 4;  /* chars to be removed: '\', 'u', '{', and first digit */
346
9.48k
  save_and_next(ls);  /* skip 'u' */
347
9.48k
  esccheck(ls, ls->current == '{', "missing '{'");
348
9.48k
  r = gethexa(ls);  /* must have at least one digit */
349
57.4k
  while (cast_void(save_and_next(ls)), lisxdigit(ls->current)) {
350
48.0k
    i++;
351
48.0k
    esccheck(ls, r <= (0x7FFFFFFFu >> 4), "UTF-8 value too large");
352
48.0k
    r = (r << 4) + luaO_hexavalue(ls->current);
353
48.0k
  }
354
9.48k
  esccheck(ls, ls->current == '}', "missing '}'");
355
9.48k
  next(ls);  /* skip '}' */
356
9.48k
  luaZ_buffremove(ls->buff, i);  /* remove saved chars from buffer */
357
9.48k
  return r;
358
9.48k
}
359
360
361
9.48k
static void utf8esc (LexState *ls) {
362
9.48k
  char buff[UTF8BUFFSZ];
363
9.48k
  int n = luaO_utf8esc(buff, readutf8esc(ls));
364
57.4k
  for (; n > 0; n--)  /* add 'buff' to string */
365
47.9k
    save(ls, buff[UTF8BUFFSZ - n]);
366
9.48k
}
367
368
369
25.9k
static int readdecesc (LexState *ls) {
370
25.9k
  int i;
371
25.9k
  int r = 0;  /* result accumulator */
372
88.2k
  for (i = 0; i < 3 && lisdigit(ls->current); i++) {  /* read up to 3 digits */
373
62.2k
    r = 10*r + ls->current - '0';
374
62.2k
    save_and_next(ls);
375
62.2k
  }
376
25.9k
  esccheck(ls, r <= UCHAR_MAX, "decimal escape too large");
377
25.9k
  luaZ_buffremove(ls->buff, i);  /* remove read digits from buffer */
378
25.9k
  return r;
379
25.9k
}
380
381
382
200k
static void read_string (LexState *ls, int del, SemInfo *seminfo) {
383
200k
  save_and_next(ls);  /* keep delimiter (for error messages) */
384
13.4M
  while (ls->current != del) {
385
13.2M
    switch (ls->current) {
386
8
      case EOZ:
387
8
        lexerror(ls, "unfinished string", TK_EOS);
388
0
        break;  /* to avoid warnings */
389
6
      case '\n':
390
9
      case '\r':
391
9
        lexerror(ls, "unfinished string", TK_STRING);
392
0
        break;  /* to avoid warnings */
393
57.4k
      case '\\': {  /* escape sequences */
394
57.4k
        int c;  /* final character to be saved */
395
57.4k
        save_and_next(ls);  /* keep '\\' for error messages */
396
57.4k
        switch (ls->current) {
397
1.31k
          case 'a': c = '\a'; goto read_save;
398
192
          case 'b': c = '\b'; goto read_save;
399
7.94k
          case 'f': c = '\f'; goto read_save;
400
25
          case 'n': c = '\n'; goto read_save;
401
4.12k
          case 'r': c = '\r'; goto read_save;
402
361
          case 't': c = '\t'; goto read_save;
403
81
          case 'v': c = '\v'; goto read_save;
404
1.76k
          case 'x': c = readhexaesc(ls); goto read_save;
405
9.48k
          case 'u': utf8esc(ls);  goto no_save;
406
273
          case '\n': case '\r':
407
273
            inclinenumber(ls); c = '\n'; goto only_save;
408
5.63k
          case '\\': case '\"': case '\'':
409
5.63k
            c = ls->current; goto read_save;
410
0
          case EOZ: goto no_save;  /* will raise an error next loop */
411
263
          case 'z': {  /* zap following span of spaces */
412
263
            luaZ_buffremove(ls->buff, 1);  /* remove '\\' */
413
263
            next(ls);  /* skip the 'z' */
414
263
            while (lisspace(ls->current)) {
415
112
              if (currIsNewline(ls)) inclinenumber(ls);
416
28
              else next(ls);
417
112
            }
418
263
            goto no_save;
419
5.63k
          }
420
25.9k
          default: {
421
25.9k
            esccheck(ls, lisdigit(ls->current), "invalid escape sequence");
422
25.9k
            c = readdecesc(ls);  /* digital escape '\ddd' */
423
25.9k
            goto only_save;
424
5.63k
          }
425
57.4k
        }
426
21.4k
       read_save:
427
21.4k
         next(ls);
428
         /* go through */
429
47.6k
       only_save:
430
47.6k
         luaZ_buffremove(ls->buff, 1);  /* remove '\\' */
431
47.6k
         save(ls, c);
432
         /* go through */
433
57.3k
       no_save: break;
434
47.6k
      }
435
13.2M
      default:
436
13.2M
        save_and_next(ls);
437
13.2M
    }
438
13.2M
  }
439
200k
  save_and_next(ls);  /* skip delimiter */
440
200k
  seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1,
441
200k
                                   luaZ_bufflen(ls->buff) - 2);
442
200k
}
443
444
445
27.4M
static int llex (LexState *ls, SemInfo *seminfo) {
446
27.4M
  luaZ_resetbuffer(ls->buff);
447
27.8M
  for (;;) {
448
27.8M
    switch (ls->current) {
449
220k
      case '\n': case '\r': {  /* line breaks */
450
220k
        inclinenumber(ls);
451
220k
        break;
452
99.3k
      }
453
131k
      case ' ': case '\f': case '\t': case '\v': {  /* spaces */
454
131k
        next(ls);
455
131k
        break;
456
117k
      }
457
254k
      case '-': {  /* '-' or '--' (comment) */
458
254k
        next(ls);
459
254k
        if (ls->current != '-') return '-';
460
        /* else is a comment */
461
41.3k
        next(ls);
462
41.3k
        if (ls->current == '[') {  /* long comment? */
463
17
          size_t sep = skip_sep(ls);
464
17
          luaZ_resetbuffer(ls->buff);  /* 'skip_sep' may dirty the buffer */
465
17
          if (sep >= 2) {
466
3
            read_long_string(ls, NULL, sep);  /* skip long comment */
467
3
            luaZ_resetbuffer(ls->buff);  /* previous call may dirty the buff. */
468
3
            break;
469
3
          }
470
17
        }
471
        /* else short comment */
472
5.57M
        while (!currIsNewline(ls) && ls->current != EOZ)
473
5.53M
          next(ls);  /* skip until end of line (or end of file) */
474
41.3k
        break;
475
41.3k
      }
476
227k
      case '[': {  /* long string or simply '[' */
477
227k
        size_t sep = skip_sep(ls);
478
227k
        if (sep >= 2) {
479
204k
          read_long_string(ls, seminfo, sep);
480
204k
          return TK_STRING;
481
204k
        }
482
23.3k
        else if (sep == 0)  /* '[=...' missing second bracket? */
483
0
          lexerror(ls, "invalid long string delimiter", TK_STRING);
484
23.3k
        return '[';
485
227k
      }
486
32.3k
      case '=': {
487
32.3k
        next(ls);
488
32.3k
        if (check_next1(ls, '=')) return TK_EQ;  /* '==' */
489
27.1k
        else return '=';
490
32.3k
      }
491
6.76M
      case '<': {
492
6.76M
        next(ls);
493
6.76M
        if (check_next1(ls, '=')) return TK_LE;  /* '<=' */
494
6.75M
        else if (check_next1(ls, '<')) return TK_SHL;  /* '<<' */
495
6.39M
        else return '<';
496
6.76M
      }
497
60.0k
      case '>': {
498
60.0k
        next(ls);
499
60.0k
        if (check_next1(ls, '=')) return TK_GE;  /* '>=' */
500
58.8k
        else if (check_next1(ls, '>')) return TK_SHR;  /* '>>' */
501
52.3k
        else return '>';
502
60.0k
      }
503
5.25M
      case '/': {
504
5.25M
        next(ls);
505
5.25M
        if (check_next1(ls, '/')) return TK_IDIV;  /* '//' */
506
5.21M
        else return '/';
507
5.25M
      }
508
161k
      case '~': {
509
161k
        next(ls);
510
161k
        if (check_next1(ls, '=')) return TK_NE;  /* '~=' */
511
156k
        else return '~';
512
161k
      }
513
1.73k
      case ':': {
514
1.73k
        next(ls);
515
1.73k
        if (check_next1(ls, ':')) return TK_DBCOLON;  /* '::' */
516
1.18k
        else return ':';
517
1.73k
      }
518
200k
      case '"': case '\'': {  /* short literal strings */
519
200k
        read_string(ls, ls->current, seminfo);
520
200k
        return TK_STRING;
521
163k
      }
522
28.3k
      case '.': {  /* '.', '..', '...', or number */
523
28.3k
        save_and_next(ls);
524
28.3k
        if (check_next1(ls, '.')) {
525
20.0k
          if (check_next1(ls, '.'))
526
1.30k
            return TK_DOTS;   /* '...' */
527
18.7k
          else return TK_CONCAT;   /* '..' */
528
20.0k
        }
529
8.23k
        else if (!lisdigit(ls->current)) return '.';
530
3.17k
        else return read_numeral(ls, seminfo);
531
28.3k
      }
532
250k
      case '0': case '1': case '2': case '3': case '4':
533
346k
      case '5': case '6': case '7': case '8': case '9': {
534
346k
        return read_numeral(ls, seminfo);
535
324k
      }
536
93
      case EOZ: {
537
93
        return TK_EOS;
538
324k
      }
539
14.1M
      default: {
540
14.1M
        if (lislalpha(ls->current)) {  /* identifier or reserved word? */
541
13.1M
          TString *ts;
542
20.9M
          do {
543
20.9M
            save_and_next(ls);
544
20.9M
          } while (lislalnum(ls->current));
545
13.1M
          ts = luaX_newstring(ls, luaZ_buffer(ls->buff),
546
13.1M
                                  luaZ_bufflen(ls->buff));
547
13.1M
          seminfo->ts = ts;
548
13.1M
          if (isreserved(ts))  /* reserved word? */
549
370k
            return ts->extra - 1 + FIRST_RESERVED;
550
12.7M
          else {
551
12.7M
            return TK_NAME;
552
12.7M
          }
553
13.1M
        }
554
997k
        else {  /* single-char tokens ('+', '*', '%', '{', '}', ...) */
555
997k
          int c = ls->current;
556
997k
          next(ls);
557
997k
          return c;
558
997k
        }
559
14.1M
      }
560
27.8M
    }
561
27.8M
  }
562
27.4M
}
563
564
565
27.4M
void luaX_next (LexState *ls) {
566
27.4M
  ls->lastline = ls->linenumber;
567
27.4M
  if (ls->lookahead.token != TK_EOS) {  /* is there a look-ahead token? */
568
134
    ls->t = ls->lookahead;  /* use this one */
569
134
    ls->lookahead.token = TK_EOS;  /* and discharge it */
570
134
  }
571
27.4M
  else
572
27.4M
    ls->t.token = llex(ls, &ls->t.seminfo);  /* read next token */
573
27.4M
}
574
575
576
134
int luaX_lookahead (LexState *ls) {
577
134
  lua_assert(ls->lookahead.token == TK_EOS);
578
134
  ls->lookahead.token = llex(ls, &ls->lookahead.seminfo);
579
134
  return ls->lookahead.token;
580
134
}
581