Coverage Report

Created: 2023-09-30 06:10

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