Coverage Report

Created: 2025-08-28 06:25

/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
81.7M
#define next(ls)  (ls->current = zgetc(ls->z))
33
34
35
/* minimum size for string buffer */
36
#if !defined(LUA_MINBUFFER)
37
#define LUA_MINBUFFER   32
38
#endif
39
40
41
6.49M
#define currIsNewline(ls) (ls->current == '\n' || ls->current == '\r')
42
43
44
/* ORDER RESERVED */
45
static const char *const luaX_tokens [] = {
46
    "and", "break", "do", "else", "elseif",
47
    "end", "false", "for", "function", "global", "goto", "if",
48
    "in", "local", "nil", "not", "or", "repeat",
49
    "return", "then", "true", "until", "while",
50
    "//", "..", "...", "==", ">=", "<=", "~=",
51
    "<<", ">>", "::", "<eof>",
52
    "<number>", "<integer>", "<name>", "<string>"
53
};
54
55
56
55.1M
#define save_and_next(ls) (save(ls, ls->current), next(ls))
57
58
59
static l_noret lexerror (LexState *ls, const char *msg, int token);
60
61
62
57.5M
static void save (LexState *ls, int c) {
63
57.5M
  Mbuffer *b = ls->buff;
64
57.5M
  if (luaZ_bufflen(b) + 1 > luaZ_sizebuffer(b)) {
65
3.01k
    size_t newsize = luaZ_sizebuffer(b);  /* get old size */;
66
3.01k
    if (newsize >= (MAX_SIZE/3 * 2))  /* larger than MAX_SIZE/1.5 ? */
67
0
      lexerror(ls, "lexical element too long", 0);
68
3.01k
    newsize += (newsize >> 1);  /* new size is 1.5 times the old one */
69
3.01k
    luaZ_resizebuffer(ls->L, b, newsize);
70
3.01k
  }
71
57.5M
  b->buffer[luaZ_bufflen(b)++] = cast_char(c);
72
57.5M
}
73
74
75
369
void luaX_init (lua_State *L) {
76
369
  int i;
77
369
  TString *e = luaS_newliteral(L, LUA_ENV);  /* create env name */
78
369
  luaC_fix(L, obj2gco(e));  /* never collect this name */
79
8.85k
  for (i=0; i<NUM_RESERVED; i++) {
80
8.48k
    TString *ts = luaS_new(L, luaX_tokens[i]);
81
8.48k
    luaC_fix(L, obj2gco(ts));  /* reserved words are never collected */
82
8.48k
    ts->extra = cast_byte(i+1);  /* reserved word */
83
8.48k
  }
84
369
}
85
86
87
250
const char *luaX_token2str (LexState *ls, int token) {
88
250
  if (token < FIRST_RESERVED) {  /* single-byte symbols? */
89
199
    if (lisprint(token))
90
160
      return luaO_pushfstring(ls->L, "'%c'", token);
91
39
    else  /* control character */
92
39
      return luaO_pushfstring(ls->L, "'<\\%d>'", token);
93
199
  }
94
51
  else {
95
51
    const char *s = luaX_tokens[token - FIRST_RESERVED];
96
51
    if (token < TK_EOS)  /* fixed format (symbols and reserved words)? */
97
9
      return luaO_pushfstring(ls->L, "'%s'", s);
98
42
    else  /* names, strings, and numerals */
99
42
      return s;
100
51
  }
101
250
}
102
103
104
257
static const char *txtToken (LexState *ls, int token) {
105
257
  switch (token) {
106
53
    case TK_NAME: case TK_STRING:
107
81
    case TK_FLT: case TK_INT:
108
81
      save(ls, '\0');
109
81
      return luaO_pushfstring(ls->L, "'%s'", luaZ_buffer(ls->buff));
110
176
    default:
111
176
      return luaX_token2str(ls, token);
112
257
  }
113
257
}
114
115
116
262
static l_noret lexerror (LexState *ls, const char *msg, int token) {
117
262
  msg = luaG_addinfo(ls->L, msg, ls->source, ls->linenumber);
118
262
  if (token)
119
257
    luaO_pushfstring(ls->L, "%s near %s", msg, txtToken(ls, token));
120
262
  luaD_throw(ls->L, LUA_ERRSYNTAX);
121
262
}
122
123
124
209
l_noret luaX_syntaxerror (LexState *ls, const char *msg) {
125
209
  lexerror(ls, msg, ls->t.token);
126
209
}
127
128
129
/*
130
** Anchors a string in scanner's table so that it will not be collected
131
** until the end of the compilation; by that time it should be anchored
132
** somewhere. It also internalizes long strings, ensuring there is only
133
** one copy of each unique string.
134
*/
135
21.8M
static TString *anchorstr (LexState *ls, TString *ts) {
136
21.8M
  lua_State *L = ls->L;
137
21.8M
  TValue oldts;
138
21.8M
  int tag = luaH_getstr(ls->h, ts, &oldts);
139
21.8M
  if (!tagisempty(tag))  /* string already present? */
140
21.8M
    return tsvalue(&oldts);  /* use stored value */
141
16.7k
  else {  /* create a new entry */
142
16.7k
    TValue *stv = s2v(L->top.p++);  /* reserve stack space for string */
143
16.7k
    setsvalue(L, stv, ts);  /* push (anchor) the string on the stack */
144
16.7k
    luaH_set(L, ls->h, stv, stv);  /* t[string] = string */
145
    /* table is not a metatable, so it does not need to invalidate cache */
146
16.7k
    luaC_checkGC(L);
147
16.7k
    L->top.p--;  /* remove string from stack */
148
16.7k
    return ts;
149
16.7k
  }
150
21.8M
}
151
152
153
/*
154
** Creates a new string and anchors it in scanner's table.
155
*/
156
20.6k
TString *luaX_newstring (LexState *ls, const char *str, size_t l) {
157
20.6k
  return anchorstr(ls, luaS_newlstr(ls->L, str, l));
158
20.6k
}
159
160
161
/*
162
** increment line number and skips newline sequence (any of
163
** \n, \r, \n\r, or \r\n)
164
*/
165
2.46M
static void inclinenumber (LexState *ls) {
166
2.46M
  int old = ls->current;
167
2.46M
  lua_assert(currIsNewline(ls));
168
2.46M
  next(ls);  /* skip '\n' or '\r' */
169
2.46M
  if (currIsNewline(ls) && ls->current != old)
170
3.67k
    next(ls);  /* skip '\n\r' or '\r\n' */
171
2.46M
  if (++ls->linenumber >= INT_MAX)
172
0
    lexerror(ls, "chunk has too many lines", 0);
173
2.46M
}
174
175
176
void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source,
177
369
                    int firstchar) {
178
369
  ls->t.token = 0;
179
369
  ls->L = L;
180
369
  ls->current = firstchar;
181
369
  ls->lookahead.token = TK_EOS;  /* no look-ahead token */
182
369
  ls->z = z;
183
369
  ls->fs = NULL;
184
369
  ls->linenumber = 1;
185
369
  ls->lastline = 1;
186
369
  ls->source = source;
187
  /* all three strings here ("_ENV", "break", "global") were fixed,
188
     so they cannot be collected */
189
369
  ls->envn = luaS_newliteral(L, LUA_ENV);  /* get env string */
190
369
  ls->brkn = luaS_newliteral(L, "break");  /* get "break" string */
191
369
#if defined(LUA_COMPAT_GLOBAL)
192
  /* compatibility mode: "global" is not a reserved word */
193
369
  ls->glbn = luaS_newliteral(L, "global");  /* get "global" string */
194
369
  ls->glbn->extra = 0;  /* mark it as not reserved */
195
369
#endif
196
369
  luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER);  /* initialize buffer */
197
369
}
198
199
200
201
/*
202
** =======================================================
203
** LEXICAL ANALYZER
204
** =======================================================
205
*/
206
207
208
41.9M
static int check_next1 (LexState *ls, int c) {
209
41.9M
  if (ls->current == c) {
210
390k
    next(ls);
211
390k
    return 1;
212
390k
  }
213
41.5M
  else return 0;
214
41.9M
}
215
216
217
/*
218
** Check whether current char is in set 'set' (with two chars) and
219
** saves it
220
*/
221
6.61M
static int check_next2 (LexState *ls, const char *set) {
222
6.61M
  lua_assert(set[2] == '\0');
223
6.61M
  if (ls->current == set[0] || ls->current == set[1]) {
224
82.4k
    save_and_next(ls);
225
82.4k
    return 1;
226
82.4k
  }
227
6.53M
  else return 0;
228
6.61M
}
229
230
231
/* LUA_NUMBER */
232
/*
233
** This function is quite liberal in what it accepts, as 'luaO_str2num'
234
** will reject ill-formed numerals. Roughly, it accepts the following
235
** pattern:
236
**
237
**   %d(%x|%.|([Ee][+-]?))* | 0[Xx](%x|%.|([Pp][+-]?))*
238
**
239
** The only tricky part is to accept [+-] only after a valid exponent
240
** mark, to avoid reading '3-4' or '0xe+1' as a single number.
241
**
242
** The caller might have already read an initial dot.
243
*/
244
876k
static int read_numeral (LexState *ls, SemInfo *seminfo) {
245
876k
  TValue obj;
246
876k
  const char *expo = "Ee";
247
876k
  int first = ls->current;
248
876k
  lua_assert(lisdigit(ls->current));
249
876k
  save_and_next(ls);
250
876k
  if (first == '0' && check_next2(ls, "xX"))  /* hexadecimal? */
251
14
    expo = "Pp";
252
5.91M
  for (;;) {
253
5.91M
    if (check_next2(ls, expo))  /* exponent mark? */
254
82.3k
      check_next2(ls, "-+");  /* optional exponent sign */
255
5.83M
    else if (lisxdigit(ls->current) || ls->current == '.')  /* '%x|%.' */
256
4.95M
      save_and_next(ls);
257
876k
    else break;
258
5.91M
  }
259
876k
  if (lislalpha(ls->current))  /* is numeral touching a letter? */
260
9
    save_and_next(ls);  /* force an error */
261
876k
  save(ls, '\0');
262
876k
  if (luaO_str2num(luaZ_buffer(ls->buff), &obj) == 0)  /* format error? */
263
11
    lexerror(ls, "malformed number", TK_FLT);
264
876k
  if (ttisinteger(&obj)) {
265
865k
    seminfo->i = ivalue(&obj);
266
0
    return TK_INT;
267
865k
  }
268
11.6k
  else {
269
11.6k
    lua_assert(ttisfloat(&obj));
270
11.6k
    seminfo->r = fltvalue(&obj);
271
0
    return TK_FLT;
272
11.6k
  }
273
876k
}
274
275
276
/*
277
** read a sequence '[=*[' or ']=*]', leaving the last bracket. If
278
** sequence is well formed, return its number of '='s + 2; otherwise,
279
** return 1 if it is a single bracket (no '='s and no 2nd bracket);
280
** otherwise (an unfinished '[==...') return 0.
281
*/
282
50.2k
static size_t skip_sep (LexState *ls) {
283
50.2k
  size_t count = 0;
284
50.2k
  int s = ls->current;
285
50.2k
  lua_assert(s == '[' || s == ']');
286
50.2k
  save_and_next(ls);
287
66.6k
  while (ls->current == '=') {
288
16.3k
    save_and_next(ls);
289
16.3k
    count++;
290
16.3k
  }
291
50.2k
  return (ls->current == s) ? count + 2
292
50.2k
         : (count == 0) ? 1
293
40.1k
         : 0;
294
50.2k
}
295
296
297
1.26k
static void read_long_string (LexState *ls, SemInfo *seminfo, size_t sep) {
298
1.26k
  int line = ls->linenumber;  /* initial line (for error message) */
299
1.26k
  save_and_next(ls);  /* skip 2nd '[' */
300
1.26k
  if (currIsNewline(ls))  /* string starts with a newline? */
301
37
    inclinenumber(ls);  /* skip it */
302
10.5M
  for (;;) {
303
10.5M
    switch (ls->current) {
304
14
      case EOZ: {  /* error */
305
14
        const char *what = (seminfo ? "string" : "comment");
306
14
        const char *msg = luaO_pushfstring(ls->L,
307
14
                     "unfinished long %s (starting at line %d)", what, line);
308
14
        lexerror(ls, msg, TK_EOS);
309
0
        break;  /* to avoid warnings */
310
0
      }
311
47.8k
      case ']': {
312
47.8k
        if (skip_sep(ls) == sep) {
313
1.25k
          save_and_next(ls);  /* skip 2nd ']' */
314
1.25k
          goto endloop;
315
1.25k
        }
316
46.5k
        break;
317
47.8k
      }
318
1.37M
      case '\n': case '\r': {
319
1.37M
        save(ls, '\n');
320
1.37M
        inclinenumber(ls);
321
1.37M
        if (!seminfo) luaZ_resetbuffer(ls->buff);  /* avoid wasting space */
322
1.37M
        break;
323
1.22M
      }
324
9.12M
      default: {
325
9.12M
        if (seminfo) save_and_next(ls);
326
69.2k
        else next(ls);
327
9.12M
      }
328
10.5M
    }
329
10.5M
  } endloop:
330
1.25k
  if (seminfo)
331
1.24k
    seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + sep,
332
1.24k
                                     luaZ_bufflen(ls->buff) - 2 * sep);
333
1.25k
}
334
335
336
121k
static void esccheck (LexState *ls, int c, const char *msg) {
337
121k
  if (!c) {
338
21
    if (ls->current != EOZ)
339
20
      save_and_next(ls);  /* add current to buffer for error message */
340
21
    lexerror(ls, msg, TK_STRING);
341
21
  }
342
121k
}
343
344
345
2.38k
static int gethexa (LexState *ls) {
346
2.38k
  save_and_next(ls);
347
2.38k
  esccheck (ls, lisxdigit(ls->current), "hexadecimal digit expected");
348
2.38k
  return luaO_hexavalue(ls->current);
349
2.38k
}
350
351
352
2
static int readhexaesc (LexState *ls) {
353
2
  int r = gethexa(ls);
354
2
  r = (r << 4) + gethexa(ls);
355
2
  luaZ_buffremove(ls->buff, 2);  /* remove saved chars from buffer */
356
2
  return r;
357
2
}
358
359
360
/*
361
** When reading a UTF-8 escape sequence, save everything to the buffer
362
** for error reporting in case of errors; 'i' counts the number of
363
** saved characters, so that they can be removed if case of success.
364
*/
365
2.39k
static l_uint32 readutf8esc (LexState *ls) {
366
2.39k
  l_uint32 r;
367
2.39k
  int i = 4;  /* number of chars to be removed: start with #"\u{X" */
368
2.39k
  save_and_next(ls);  /* skip 'u' */
369
2.39k
  esccheck(ls, ls->current == '{', "missing '{'");
370
2.39k
  r = cast_uint(gethexa(ls));  /* must have at least one digit */
371
4.27k
  while (cast_void(save_and_next(ls)), lisxdigit(ls->current)) {
372
1.88k
    i++;
373
1.88k
    esccheck(ls, r <= (0x7FFFFFFFu >> 4), "UTF-8 value too large");
374
1.88k
    r = (r << 4) + luaO_hexavalue(ls->current);
375
1.88k
  }
376
2.39k
  esccheck(ls, ls->current == '}', "missing '}'");
377
2.39k
  next(ls);  /* skip '}' */
378
2.39k
  luaZ_buffremove(ls->buff, i);  /* remove saved chars from buffer */
379
2.39k
  return r;
380
2.39k
}
381
382
383
2.39k
static void utf8esc (LexState *ls) {
384
2.39k
  char buff[UTF8BUFFSZ];
385
2.39k
  int n = luaO_utf8esc(buff, readutf8esc(ls));
386
5.63k
  for (; n > 0; n--)  /* add 'buff' to string */
387
3.24k
    save(ls, buff[UTF8BUFFSZ - n]);
388
2.39k
}
389
390
391
56.1k
static int readdecesc (LexState *ls) {
392
56.1k
  int i;
393
56.1k
  int r = 0;  /* result accumulator */
394
159k
  for (i = 0; i < 3 && lisdigit(ls->current); i++) {  /* read up to 3 digits */
395
102k
    r = 10*r + ls->current - '0';
396
102k
    save_and_next(ls);
397
102k
  }
398
56.1k
  esccheck(ls, r <= UCHAR_MAX, "decimal escape too large");
399
56.1k
  luaZ_buffremove(ls->buff, i);  /* remove read digits from buffer */
400
56.1k
  return r;
401
56.1k
}
402
403
404
18.2k
static void read_string (LexState *ls, int del, SemInfo *seminfo) {
405
18.2k
  save_and_next(ls);  /* keep delimiter (for error messages) */
406
14.7M
  while (ls->current != del) {
407
14.6M
    switch (ls->current) {
408
4
      case EOZ:
409
4
        lexerror(ls, "unfinished string", TK_EOS);
410
0
        break;  /* to avoid warnings */
411
3
      case '\n':
412
3
      case '\r':
413
3
        lexerror(ls, "unfinished string", TK_STRING);
414
0
        break;  /* to avoid warnings */
415
72.6k
      case '\\': {  /* escape sequences */
416
72.6k
        int c;  /* final character to be saved */
417
72.6k
        save_and_next(ls);  /* keep '\\' for error messages */
418
72.6k
        switch (ls->current) {
419
804
          case 'a': c = '\a'; goto read_save;
420
3
          case 'b': c = '\b'; goto read_save;
421
5
          case 'f': c = '\f'; goto read_save;
422
459
          case 'n': c = '\n'; goto read_save;
423
173
          case 'r': c = '\r'; goto read_save;
424
9.72k
          case 't': c = '\t'; goto read_save;
425
2.13k
          case 'v': c = '\v'; goto read_save;
426
2
          case 'x': c = readhexaesc(ls); goto read_save;
427
2.39k
          case 'u': utf8esc(ls);  goto no_save;
428
0
          case '\n': case '\r':
429
0
            inclinenumber(ls); c = '\n'; goto only_save;
430
473
          case '\\': case '\"': case '\'':
431
473
            c = ls->current; goto read_save;
432
1
          case EOZ: goto no_save;  /* will raise an error next loop */
433
319
          case 'z': {  /* zap following span of spaces */
434
319
            luaZ_buffremove(ls->buff, 1);  /* remove '\\' */
435
319
            next(ls);  /* skip the 'z' */
436
319
            while (lisspace(ls->current)) {
437
57
              if (currIsNewline(ls)) inclinenumber(ls);
438
57
              else next(ls);
439
57
            }
440
319
            goto no_save;
441
452
          }
442
56.1k
          default: {
443
56.1k
            esccheck(ls, lisdigit(ls->current), "invalid escape sequence");
444
56.1k
            c = readdecesc(ls);  /* digital escape '\ddd' */
445
56.1k
            goto only_save;
446
452
          }
447
72.6k
        }
448
13.7k
       read_save:
449
13.7k
         next(ls);
450
         /* go through */
451
69.9k
       only_save:
452
69.9k
         luaZ_buffremove(ls->buff, 1);  /* remove '\\' */
453
69.9k
         save(ls, c);
454
         /* go through */
455
72.6k
       no_save: break;
456
69.9k
      }
457
14.6M
      default:
458
14.6M
        save_and_next(ls);
459
14.6M
    }
460
14.6M
  }
461
18.2k
  save_and_next(ls);  /* skip delimiter */
462
18.2k
  seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1,
463
18.2k
                                   luaZ_bufflen(ls->buff) - 2);
464
18.2k
}
465
466
467
45.6M
static int llex (LexState *ls, SemInfo *seminfo) {
468
45.6M
  luaZ_resetbuffer(ls->buff);
469
46.7M
  for (;;) {
470
46.7M
    switch (ls->current) {
471
1.09M
      case '\n': case '\r': {  /* line breaks */
472
1.09M
        inclinenumber(ls);
473
1.09M
        break;
474
1.06M
      }
475
31.1k
      case ' ': case '\f': case '\t': case '\v': {  /* spaces */
476
31.1k
        next(ls);
477
31.1k
        break;
478
27.5k
      }
479
71.1k
      case '-': {  /* '-' or '--' (comment) */
480
71.1k
        next(ls);
481
71.1k
        if (ls->current != '-') return '-';
482
        /* else is a comment */
483
8.54k
        next(ls);
484
8.54k
        if (ls->current == '[') {  /* long comment? */
485
19
          size_t sep = skip_sep(ls);
486
19
          luaZ_resetbuffer(ls->buff);  /* 'skip_sep' may dirty the buffer */
487
19
          if (sep >= 2) {
488
8
            read_long_string(ls, NULL, sep);  /* skip long comment */
489
8
            luaZ_resetbuffer(ls->buff);  /* previous call may dirty the buff. */
490
8
            break;
491
8
          }
492
19
        }
493
        /* else short comment */
494
777k
        while (!currIsNewline(ls) && ls->current != EOZ)
495
768k
          next(ls);  /* skip until end of line (or end of file) */
496
8.53k
        break;
497
8.54k
      }
498
2.38k
      case '[': {  /* long string or simply '[' */
499
2.38k
        size_t sep = skip_sep(ls);
500
2.38k
        if (sep >= 2) {
501
1.25k
          read_long_string(ls, seminfo, sep);
502
1.25k
          return TK_STRING;
503
1.25k
        }
504
1.12k
        else if (sep == 0)  /* '[=...' missing second bracket? */
505
0
          lexerror(ls, "invalid long string delimiter", TK_STRING);
506
1.12k
        return '[';
507
2.38k
      }
508
15.0k
      case '=': {
509
15.0k
        next(ls);
510
15.0k
        if (check_next1(ls, '=')) return TK_EQ;  /* '==' */
511
13.0k
        else return '=';
512
15.0k
      }
513
404k
      case '<': {
514
404k
        next(ls);
515
404k
        if (check_next1(ls, '=')) return TK_LE;  /* '<=' */
516
399k
        else if (check_next1(ls, '<')) return TK_SHL;  /* '<<' */
517
372k
        else return '<';
518
404k
      }
519
19.9M
      case '>': {
520
19.9M
        next(ls);
521
19.9M
        if (check_next1(ls, '=')) return TK_GE;  /* '>=' */
522
19.9M
        else if (check_next1(ls, '>')) return TK_SHR;  /* '>>' */
523
19.5M
        else return '>';
524
19.9M
      }
525
1.19M
      case '/': {
526
1.19M
        next(ls);
527
1.19M
        if (check_next1(ls, '/')) return TK_IDIV;  /* '//' */
528
1.18M
        else return '/';
529
1.19M
      }
530
130k
      case '~': {
531
130k
        next(ls);
532
130k
        if (check_next1(ls, '=')) return TK_NE;  /* '~=' */
533
129k
        else return '~';
534
130k
      }
535
1.35k
      case ':': {
536
1.35k
        next(ls);
537
1.35k
        if (check_next1(ls, ':')) return TK_DBCOLON;  /* '::' */
538
578
        else return ':';
539
1.35k
      }
540
18.2k
      case '"': case '\'': {  /* short literal strings */
541
18.2k
        read_string(ls, ls->current, seminfo);
542
18.2k
        return TK_STRING;
543
12.9k
      }
544
19.4k
      case '.': {  /* '.', '..', '...', or number */
545
19.4k
        save_and_next(ls);
546
19.4k
        if (check_next1(ls, '.')) {
547
7.60k
          if (check_next1(ls, '.'))
548
4.04k
            return TK_DOTS;   /* '...' */
549
3.56k
          else return TK_CONCAT;   /* '..' */
550
7.60k
        }
551
11.8k
        else if (!lisdigit(ls->current)) return '.';
552
297
        else return read_numeral(ls, seminfo);
553
19.4k
      }
554
731k
      case '0': case '1': case '2': case '3': case '4':
555
876k
      case '5': case '6': case '7': case '8': case '9': {
556
876k
        return read_numeral(ls, seminfo);
557
801k
      }
558
124
      case EOZ: {
559
124
        return TK_EOS;
560
801k
      }
561
22.9M
      default: {
562
22.9M
        if (lislalpha(ls->current)) {  /* identifier or reserved word? */
563
21.9M
          TString *ts;
564
25.2M
          do {
565
25.2M
            save_and_next(ls);
566
25.2M
          } while (lislalnum(ls->current));
567
          /* find or create string */
568
21.9M
          ts = luaS_newlstr(ls->L, luaZ_buffer(ls->buff),
569
21.9M
                                   luaZ_bufflen(ls->buff));
570
21.9M
          if (isreserved(ts))   /* reserved word? */
571
42.4k
            return ts->extra - 1 + FIRST_RESERVED;
572
21.8M
          else {
573
21.8M
            seminfo->ts = anchorstr(ls, ts);
574
21.8M
            return TK_NAME;
575
21.8M
          }
576
21.9M
        }
577
1.09M
        else {  /* single-char tokens ('+', '*', '%', '{', '}', ...) */
578
1.09M
          int c = ls->current;
579
1.09M
          next(ls);
580
1.09M
          return c;
581
1.09M
        }
582
22.9M
      }
583
46.7M
    }
584
46.7M
  }
585
45.6M
}
586
587
588
45.6M
void luaX_next (LexState *ls) {
589
45.6M
  ls->lastline = ls->linenumber;
590
45.6M
  if (ls->lookahead.token != TK_EOS) {  /* is there a look-ahead token? */
591
710k
    ls->t = ls->lookahead;  /* use this one */
592
710k
    ls->lookahead.token = TK_EOS;  /* and discharge it */
593
710k
  }
594
44.9M
  else
595
44.9M
    ls->t.token = llex(ls, &ls->t.seminfo);  /* read next token */
596
45.6M
}
597
598
599
710k
int luaX_lookahead (LexState *ls) {
600
710k
  lua_assert(ls->lookahead.token == TK_EOS);
601
710k
  ls->lookahead.token = llex(ls, &ls->lookahead.seminfo);
602
710k
  return ls->lookahead.token;
603
710k
}
604