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