Coverage Report

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