Coverage Report

Created: 2023-09-20 06:32

/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
46.7M
#define next(ls)  (ls->current = zgetc(ls->z))
33
34
35
36
10.2M
#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
32.3M
#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
33.2M
static void save (LexState *ls, int c) {
58
33.2M
  Mbuffer *b = ls->buff;
59
33.2M
  if (luaZ_bufflen(b) + 1 > luaZ_sizebuffer(b)) {
60
1.36k
    size_t newsize;
61
1.36k
    if (luaZ_sizebuffer(b) >= MAX_SIZE/2)
62
0
      lexerror(ls, "lexical element too long", 0);
63
1.36k
    newsize = luaZ_sizebuffer(b) * 2;
64
1.36k
    luaZ_resizebuffer(ls->L, b, newsize);
65
1.36k
  }
66
33.2M
  b->buffer[luaZ_bufflen(b)++] = cast_char(c);
67
33.2M
}
68
69
70
308
void luaX_init (lua_State *L) {
71
308
  int i;
72
308
  TString *e = luaS_newliteral(L, LUA_ENV);  /* create env name */
73
308
  luaC_fix(L, obj2gco(e));  /* never collect this name */
74
7.08k
  for (i=0; i<NUM_RESERVED; i++) {
75
6.77k
    TString *ts = luaS_new(L, luaX_tokens[i]);
76
6.77k
    luaC_fix(L, obj2gco(ts));  /* reserved words are never collected */
77
6.77k
    ts->extra = cast_byte(i+1);  /* reserved word */
78
6.77k
  }
79
308
}
80
81
82
249
const char *luaX_token2str (LexState *ls, int token) {
83
249
  if (token < FIRST_RESERVED) {  /* single-byte symbols? */
84
168
    if (lisprint(token))
85
117
      return luaO_pushfstring(ls->L, "'%c'", token);
86
51
    else  /* control character */
87
51
      return luaO_pushfstring(ls->L, "'<\\%d>'", token);
88
168
  }
89
81
  else {
90
81
    const char *s = luaX_tokens[token - FIRST_RESERVED];
91
81
    if (token < TK_EOS)  /* fixed format (symbols and reserved words)? */
92
39
      return luaO_pushfstring(ls->L, "'%s'", s);
93
42
    else  /* names, strings, and numerals */
94
42
      return s;
95
81
  }
96
249
}
97
98
99
248
static const char *txtToken (LexState *ls, int token) {
100
248
  switch (token) {
101
48
    case TK_NAME: case TK_STRING:
102
85
    case TK_FLT: case TK_INT:
103
85
      save(ls, '\0');
104
85
      return luaO_pushfstring(ls->L, "'%s'", luaZ_buffer(ls->buff));
105
163
    default:
106
163
      return luaX_token2str(ls, token);
107
248
  }
108
248
}
109
110
111
258
static l_noret lexerror (LexState *ls, const char *msg, int token) {
112
258
  msg = luaG_addinfo(ls->L, msg, ls->source, ls->linenumber);
113
258
  if (token)
114
248
    luaO_pushfstring(ls->L, "%s near %s", msg, txtToken(ls, token));
115
258
  luaD_throw(ls->L, LUA_ERRSYNTAX);
116
258
}
117
118
119
176
l_noret luaX_syntaxerror (LexState *ls, const char *msg) {
120
176
  lexerror(ls, msg, ls->t.token);
121
176
}
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
9.00M
TString *luaX_newstring (LexState *ls, const char *str, size_t l) {
135
9.00M
  lua_State *L = ls->L;
136
9.00M
  TString *ts = luaS_newlstr(L, str, l);  /* create new string */
137
9.00M
  const TValue *o = luaH_getstr(ls->h, ts);
138
9.00M
  if (!ttisnil(o))  /* string already present? */
139
8.98M
    ts = keystrval(nodefromval(o));  /* get saved copy */
140
16.9k
  else {  /* not in use yet */
141
16.9k
    TValue *stv = s2v(L->top.p++);  /* reserve stack space for string */
142
16.9k
    setsvalue(L, stv, ts);  /* temporarily anchor the string */
143
16.9k
    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
16.9k
    luaC_checkGC(L);
146
16.9k
    L->top.p--;  /* remove string from stack */
147
16.9k
  }
148
9.00M
  return ts;
149
9.00M
}
150
151
152
/*
153
** increment line number and skips newline sequence (any of
154
** \n, \r, \n\r, or \r\n)
155
*/
156
820k
static void inclinenumber (LexState *ls) {
157
820k
  int old = ls->current;
158
820k
  lua_assert(currIsNewline(ls));
159
820k
  next(ls);  /* skip '\n' or '\r' */
160
820k
  if (currIsNewline(ls) && ls->current != old)
161
49.6k
    next(ls);  /* skip '\n\r' or '\r\n' */
162
820k
  if (++ls->linenumber >= MAX_INT)
163
0
    lexerror(ls, "chunk has too many lines", 0);
164
820k
}
165
166
167
void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source,
168
308
                    int firstchar) {
169
308
  ls->t.token = 0;
170
308
  ls->L = L;
171
308
  ls->current = firstchar;
172
308
  ls->lookahead.token = TK_EOS;  /* no look-ahead token */
173
308
  ls->z = z;
174
308
  ls->fs = NULL;
175
308
  ls->linenumber = 1;
176
308
  ls->lastline = 1;
177
308
  ls->source = source;
178
308
  ls->envn = luaS_newliteral(L, LUA_ENV);  /* get env name */
179
308
  luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER);  /* initialize buffer */
180
308
}
181
182
183
184
/*
185
** =======================================================
186
** LEXICAL ANALYZER
187
** =======================================================
188
*/
189
190
191
11.6M
static int check_next1 (LexState *ls, int c) {
192
11.6M
  if (ls->current == c) {
193
237k
    next(ls);
194
237k
    return 1;
195
237k
  }
196
11.4M
  else return 0;
197
11.6M
}
198
199
200
/*
201
** Check whether current char is in set 'set' (with two chars) and
202
** saves it
203
*/
204
1.29M
static int check_next2 (LexState *ls, const char *set) {
205
1.29M
  lua_assert(set[2] == '\0');
206
1.29M
  if (ls->current == set[0] || ls->current == set[1]) {
207
1.10k
    save_and_next(ls);
208
1.10k
    return 1;
209
1.10k
  }
210
1.29M
  else return 0;
211
1.29M
}
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
249k
static int read_numeral (LexState *ls, SemInfo *seminfo) {
228
249k
  TValue obj;
229
249k
  const char *expo = "Ee";
230
249k
  int first = ls->current;
231
249k
  lua_assert(lisdigit(ls->current));
232
249k
  save_and_next(ls);
233
249k
  if (first == '0' && check_next2(ls, "xX"))  /* hexadecimal? */
234
3
    expo = "Pp";
235
1.25M
  for (;;) {
236
1.25M
    if (check_next2(ls, expo))  /* exponent mark? */
237
1.09k
      check_next2(ls, "-+");  /* optional exponent sign */
238
1.25M
    else if (lisxdigit(ls->current) || ls->current == '.')  /* '%x|%.' */
239
1.00M
      save_and_next(ls);
240
249k
    else break;
241
1.25M
  }
242
249k
  if (lislalpha(ls->current))  /* is numeral touching a letter? */
243
25
    save_and_next(ls);  /* force an error */
244
249k
  save(ls, '\0');
245
249k
  if (luaO_str2num(luaZ_buffer(ls->buff), &obj) == 0)  /* format error? */
246
29
    lexerror(ls, "malformed number", TK_FLT);
247
249k
  if (ttisinteger(&obj)) {
248
221k
    seminfo->i = ivalue(&obj);
249
221k
    return TK_INT;
250
221k
  }
251
28.1k
  else {
252
28.1k
    lua_assert(ttisfloat(&obj));
253
28.1k
    seminfo->r = fltvalue(&obj);
254
28.1k
    return TK_FLT;
255
28.1k
  }
256
249k
}
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
277k
static size_t skip_sep (LexState *ls) {
266
277k
  size_t count = 0;
267
277k
  int s = ls->current;
268
277k
  lua_assert(s == '[' || s == ']');
269
277k
  save_and_next(ls);
270
278k
  while (ls->current == '=') {
271
478
    save_and_next(ls);
272
478
    count++;
273
478
  }
274
277k
  return (ls->current == s) ? count + 2
275
277k
         : (count == 0) ? 1
276
20.9k
         : 0;
277
277k
}
278
279
280
128k
static void read_long_string (LexState *ls, SemInfo *seminfo, size_t sep) {
281
128k
  int line = ls->linenumber;  /* initial line (for error message) */
282
128k
  save_and_next(ls);  /* skip 2nd '[' */
283
128k
  if (currIsNewline(ls))  /* string starts with a newline? */
284
123k
    inclinenumber(ls);  /* skip it */
285
6.69M
  for (;;) {
286
6.69M
    switch (ls->current) {
287
12
      case EOZ: {  /* error */
288
12
        const char *what = (seminfo ? "string" : "comment");
289
12
        const char *msg = luaO_pushfstring(ls->L,
290
12
                     "unfinished long %s (starting at line %d)", what, line);
291
12
        lexerror(ls, msg, TK_EOS);
292
0
        break;  /* to avoid warnings */
293
0
      }
294
134k
      case ']': {
295
134k
        if (skip_sep(ls) == sep) {
296
128k
          save_and_next(ls);  /* skip 2nd ']' */
297
128k
          goto endloop;
298
128k
        }
299
6.38k
        break;
300
134k
      }
301
538k
      case '\n': case '\r': {
302
538k
        save(ls, '\n');
303
538k
        inclinenumber(ls);
304
538k
        if (!seminfo) luaZ_resetbuffer(ls->buff);  /* avoid wasting space */
305
538k
        break;
306
80.1k
      }
307
6.02M
      default: {
308
6.02M
        if (seminfo) save_and_next(ls);
309
46
        else next(ls);
310
6.02M
      }
311
6.69M
    }
312
6.69M
  } endloop:
313
128k
  if (seminfo)
314
128k
    seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + sep,
315
128k
                                     luaZ_bufflen(ls->buff) - 2 * sep);
316
128k
}
317
318
319
78.4k
static void esccheck (LexState *ls, int c, const char *msg) {
320
78.4k
  if (!c) {
321
26
    if (ls->current != EOZ)
322
26
      save_and_next(ls);  /* add current to buffer for error message */
323
26
    lexerror(ls, msg, TK_STRING);
324
26
  }
325
78.4k
}
326
327
328
8.07k
static int gethexa (LexState *ls) {
329
8.07k
  save_and_next(ls);
330
8.07k
  esccheck (ls, lisxdigit(ls->current), "hexadecimal digit expected");
331
8.07k
  return luaO_hexavalue(ls->current);
332
8.07k
}
333
334
335
1.03k
static int readhexaesc (LexState *ls) {
336
1.03k
  int r = gethexa(ls);
337
1.03k
  r = (r << 4) + gethexa(ls);
338
1.03k
  luaZ_buffremove(ls->buff, 2);  /* remove saved chars from buffer */
339
1.03k
  return r;
340
1.03k
}
341
342
343
6.01k
static unsigned long readutf8esc (LexState *ls) {
344
6.01k
  unsigned long r;
345
6.01k
  int i = 4;  /* chars to be removed: '\', 'u', '{', and first digit */
346
6.01k
  save_and_next(ls);  /* skip 'u' */
347
6.01k
  esccheck(ls, ls->current == '{', "missing '{'");
348
6.01k
  r = gethexa(ls);  /* must have at least one digit */
349
36.4k
  while (cast_void(save_and_next(ls)), lisxdigit(ls->current)) {
350
30.4k
    i++;
351
30.4k
    esccheck(ls, r <= (0x7FFFFFFFu >> 4), "UTF-8 value too large");
352
30.4k
    r = (r << 4) + luaO_hexavalue(ls->current);
353
30.4k
  }
354
6.01k
  esccheck(ls, ls->current == '}', "missing '}'");
355
6.01k
  next(ls);  /* skip '}' */
356
6.01k
  luaZ_buffremove(ls->buff, i);  /* remove saved chars from buffer */
357
6.01k
  return r;
358
6.01k
}
359
360
361
6.01k
static void utf8esc (LexState *ls) {
362
6.01k
  char buff[UTF8BUFFSZ];
363
6.01k
  int n = luaO_utf8esc(buff, readutf8esc(ls));
364
36.4k
  for (; n > 0; n--)  /* add 'buff' to string */
365
30.3k
    save(ls, buff[UTF8BUFFSZ - n]);
366
6.01k
}
367
368
369
13.9k
static int readdecesc (LexState *ls) {
370
13.9k
  int i;
371
13.9k
  int r = 0;  /* result accumulator */
372
48.2k
  for (i = 0; i < 3 && lisdigit(ls->current); i++) {  /* read up to 3 digits */
373
34.3k
    r = 10*r + ls->current - '0';
374
34.3k
    save_and_next(ls);
375
34.3k
  }
376
13.9k
  esccheck(ls, r <= UCHAR_MAX, "decimal escape too large");
377
13.9k
  luaZ_buffremove(ls->buff, i);  /* remove read digits from buffer */
378
13.9k
  return r;
379
13.9k
}
380
381
382
220k
static void read_string (LexState *ls, int del, SemInfo *seminfo) {
383
220k
  save_and_next(ls);  /* keep delimiter (for error messages) */
384
10.8M
  while (ls->current != del) {
385
10.6M
    switch (ls->current) {
386
9
      case EOZ:
387
9
        lexerror(ls, "unfinished string", TK_EOS);
388
0
        break;  /* to avoid warnings */
389
5
      case '\n':
390
6
      case '\r':
391
6
        lexerror(ls, "unfinished string", TK_STRING);
392
0
        break;  /* to avoid warnings */
393
31.7k
      case '\\': {  /* escape sequences */
394
31.7k
        int c;  /* final character to be saved */
395
31.7k
        save_and_next(ls);  /* keep '\\' for error messages */
396
31.7k
        switch (ls->current) {
397
539
          case 'a': c = '\a'; goto read_save;
398
34
          case 'b': c = '\b'; goto read_save;
399
4.72k
          case 'f': c = '\f'; goto read_save;
400
67
          case 'n': c = '\n'; goto read_save;
401
2.33k
          case 'r': c = '\r'; goto read_save;
402
60
          case 't': c = '\t'; goto read_save;
403
6
          case 'v': c = '\v'; goto read_save;
404
1.03k
          case 'x': c = readhexaesc(ls); goto read_save;
405
6.01k
          case 'u': utf8esc(ls);  goto no_save;
406
0
          case '\n': case '\r':
407
0
            inclinenumber(ls); c = '\n'; goto only_save;
408
2.91k
          case '\\': case '\"': case '\'':
409
2.91k
            c = ls->current; goto read_save;
410
0
          case EOZ: goto no_save;  /* will raise an error next loop */
411
51
          case 'z': {  /* zap following span of spaces */
412
51
            luaZ_buffremove(ls->buff, 1);  /* remove '\\' */
413
51
            next(ls);  /* skip the 'z' */
414
51
            while (lisspace(ls->current)) {
415
48
              if (currIsNewline(ls)) inclinenumber(ls);
416
12
              else next(ls);
417
48
            }
418
51
            goto no_save;
419
2.91k
          }
420
13.9k
          default: {
421
13.9k
            esccheck(ls, lisdigit(ls->current), "invalid escape sequence");
422
13.9k
            c = readdecesc(ls);  /* digital escape '\ddd' */
423
13.9k
            goto only_save;
424
2.91k
          }
425
31.7k
        }
426
11.7k
       read_save:
427
11.7k
         next(ls);
428
         /* go through */
429
25.6k
       only_save:
430
25.6k
         luaZ_buffremove(ls->buff, 1);  /* remove '\\' */
431
25.6k
         save(ls, c);
432
         /* go through */
433
31.7k
       no_save: break;
434
25.6k
      }
435
10.5M
      default:
436
10.5M
        save_and_next(ls);
437
10.6M
    }
438
10.6M
  }
439
220k
  save_and_next(ls);  /* skip delimiter */
440
220k
  seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1,
441
220k
                                   luaZ_bufflen(ls->buff) - 2);
442
220k
}
443
444
445
18.1M
static int llex (LexState *ls, SemInfo *seminfo) {
446
18.1M
  luaZ_resetbuffer(ls->buff);
447
18.4M
  for (;;) {
448
18.4M
    switch (ls->current) {
449
158k
      case '\n': case '\r': {  /* line breaks */
450
158k
        inclinenumber(ls);
451
158k
        break;
452
59.5k
      }
453
86.2k
      case ' ': case '\f': case '\t': case '\v': {  /* spaces */
454
86.2k
        next(ls);
455
86.2k
        break;
456
74.7k
      }
457
143k
      case '-': {  /* '-' or '--' (comment) */
458
143k
        next(ls);
459
143k
        if (ls->current != '-') return '-';
460
        /* else is a comment */
461
23.6k
        next(ls);
462
23.6k
        if (ls->current == '[') {  /* long comment? */
463
47
          size_t sep = skip_sep(ls);
464
47
          luaZ_resetbuffer(ls->buff);  /* 'skip_sep' may dirty the buffer */
465
47
          if (sep >= 2) {
466
2
            read_long_string(ls, NULL, sep);  /* skip long comment */
467
2
            luaZ_resetbuffer(ls->buff);  /* previous call may dirty the buff. */
468
2
            break;
469
2
          }
470
47
        }
471
        /* else short comment */
472
4.25M
        while (!currIsNewline(ls) && ls->current != EOZ)
473
4.22M
          next(ls);  /* skip until end of line (or end of file) */
474
23.6k
        break;
475
23.6k
      }
476
143k
      case '[': {  /* long string or simply '[' */
477
143k
        size_t sep = skip_sep(ls);
478
143k
        if (sep >= 2) {
479
128k
          read_long_string(ls, seminfo, sep);
480
128k
          return TK_STRING;
481
128k
        }
482
14.5k
        else if (sep == 0)  /* '[=...' missing second bracket? */
483
0
          lexerror(ls, "invalid long string delimiter", TK_STRING);
484
14.5k
        return '[';
485
143k
      }
486
22.5k
      case '=': {
487
22.5k
        next(ls);
488
22.5k
        if (check_next1(ls, '=')) return TK_EQ;  /* '==' */
489
19.9k
        else return '=';
490
22.5k
      }
491
3.40M
      case '<': {
492
3.40M
        next(ls);
493
3.40M
        if (check_next1(ls, '=')) return TK_LE;  /* '<=' */
494
3.39M
        else if (check_next1(ls, '<')) return TK_SHL;  /* '<<' */
495
3.22M
        else return '<';
496
3.40M
      }
497
31.7k
      case '>': {
498
31.7k
        next(ls);
499
31.7k
        if (check_next1(ls, '=')) return TK_GE;  /* '>=' */
500
30.7k
        else if (check_next1(ls, '>')) return TK_SHR;  /* '>>' */
501
27.0k
        else return '>';
502
31.7k
      }
503
4.61M
      case '/': {
504
4.61M
        next(ls);
505
4.61M
        if (check_next1(ls, '/')) return TK_IDIV;  /* '//' */
506
4.59M
        else return '/';
507
4.61M
      }
508
110k
      case '~': {
509
110k
        next(ls);
510
110k
        if (check_next1(ls, '=')) return TK_NE;  /* '~=' */
511
107k
        else return '~';
512
110k
      }
513
1.16k
      case ':': {
514
1.16k
        next(ls);
515
1.16k
        if (check_next1(ls, ':')) return TK_DBCOLON;  /* '::' */
516
774
        else return ':';
517
1.16k
      }
518
220k
      case '"': case '\'': {  /* short literal strings */
519
220k
        read_string(ls, ls->current, seminfo);
520
220k
        return TK_STRING;
521
84.4k
      }
522
29.6k
      case '.': {  /* '.', '..', '...', or number */
523
29.6k
        save_and_next(ls);
524
29.6k
        if (check_next1(ls, '.')) {
525
22.7k
          if (check_next1(ls, '.'))
526
468
            return TK_DOTS;   /* '...' */
527
22.3k
          else return TK_CONCAT;   /* '..' */
528
22.7k
        }
529
6.88k
        else if (!lisdigit(ls->current)) return '.';
530
2.56k
        else return read_numeral(ls, seminfo);
531
29.6k
      }
532
178k
      case '0': case '1': case '2': case '3': case '4':
533
246k
      case '5': case '6': case '7': case '8': case '9': {
534
246k
        return read_numeral(ls, seminfo);
535
229k
      }
536
65
      case EOZ: {
537
65
        return TK_EOS;
538
229k
      }
539
9.24M
      default: {
540
9.24M
        if (lislalpha(ls->current)) {  /* identifier or reserved word? */
541
8.65M
          TString *ts;
542
13.4M
          do {
543
13.4M
            save_and_next(ls);
544
13.4M
          } while (lislalnum(ls->current));
545
8.65M
          ts = luaX_newstring(ls, luaZ_buffer(ls->buff),
546
8.65M
                                  luaZ_bufflen(ls->buff));
547
8.65M
          seminfo->ts = ts;
548
8.65M
          if (isreserved(ts))  /* reserved word? */
549
199k
            return ts->extra - 1 + FIRST_RESERVED;
550
8.45M
          else {
551
8.45M
            return TK_NAME;
552
8.45M
          }
553
8.65M
        }
554
585k
        else {  /* single-char tokens ('+', '*', '%', '{', '}', ...) */
555
585k
          int c = ls->current;
556
585k
          next(ls);
557
585k
          return c;
558
585k
        }
559
9.24M
      }
560
18.4M
    }
561
18.4M
  }
562
18.1M
}
563
564
565
18.1M
void luaX_next (LexState *ls) {
566
18.1M
  ls->lastline = ls->linenumber;
567
18.1M
  if (ls->lookahead.token != TK_EOS) {  /* is there a look-ahead token? */
568
223
    ls->t = ls->lookahead;  /* use this one */
569
223
    ls->lookahead.token = TK_EOS;  /* and discharge it */
570
223
  }
571
18.1M
  else
572
18.1M
    ls->t.token = llex(ls, &ls->t.seminfo);  /* read next token */
573
18.1M
}
574
575
576
223
int luaX_lookahead (LexState *ls) {
577
223
  lua_assert(ls->lookahead.token == TK_EOS);
578
223
  ls->lookahead.token = llex(ls, &ls->lookahead.seminfo);
579
223
  return ls->lookahead.token;
580
223
}
581