Coverage Report

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