Coverage Report

Created: 2025-08-25 06:57

/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
94.6M
#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
8.84M
#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
63.9M
#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
67.5M
static void save (LexState *ls, int c) {
63
67.5M
  Mbuffer *b = ls->buff;
64
67.5M
  if (luaZ_bufflen(b) + 1 > luaZ_sizebuffer(b)) {
65
3.70k
    size_t newsize = luaZ_sizebuffer(b);  /* get old size */;
66
3.70k
    if (newsize >= (MAX_SIZE/3 * 2))  /* larger than MAX_SIZE/1.5 ? */
67
0
      lexerror(ls, "lexical element too long", 0);
68
3.70k
    newsize += (newsize >> 1);  /* new size is 1.5 times the old one */
69
3.70k
    luaZ_resizebuffer(ls->L, b, newsize);
70
3.70k
  }
71
67.5M
  b->buffer[luaZ_bufflen(b)++] = cast_char(c);
72
67.5M
}
73
74
75
441
void luaX_init (lua_State *L) {
76
441
  int i;
77
441
  TString *e = luaS_newliteral(L, LUA_ENV);  /* create env name */
78
441
  luaC_fix(L, obj2gco(e));  /* never collect this name */
79
10.5k
  for (i=0; i<NUM_RESERVED; i++) {
80
10.1k
    TString *ts = luaS_new(L, luaX_tokens[i]);
81
10.1k
    luaC_fix(L, obj2gco(ts));  /* reserved words are never collected */
82
10.1k
    ts->extra = cast_byte(i+1);  /* reserved word */
83
10.1k
  }
84
441
}
85
86
87
306
const char *luaX_token2str (LexState *ls, int token) {
88
306
  if (token < FIRST_RESERVED) {  /* single-byte symbols? */
89
238
    if (lisprint(token))
90
187
      return luaO_pushfstring(ls->L, "'%c'", token);
91
51
    else  /* control character */
92
51
      return luaO_pushfstring(ls->L, "'<\\%d>'", token);
93
238
  }
94
68
  else {
95
68
    const char *s = luaX_tokens[token - FIRST_RESERVED];
96
68
    if (token < TK_EOS)  /* fixed format (symbols and reserved words)? */
97
14
      return luaO_pushfstring(ls->L, "'%s'", s);
98
54
    else  /* names, strings, and numerals */
99
54
      return s;
100
68
  }
101
306
}
102
103
104
313
static const char *txtToken (LexState *ls, int token) {
105
313
  switch (token) {
106
74
    case TK_NAME: case TK_STRING:
107
108
    case TK_FLT: case TK_INT:
108
108
      save(ls, '\0');
109
108
      return luaO_pushfstring(ls->L, "'%s'", luaZ_buffer(ls->buff));
110
205
    default:
111
205
      return luaX_token2str(ls, token);
112
313
  }
113
313
}
114
115
116
321
static l_noret lexerror (LexState *ls, const char *msg, int token) {
117
321
  msg = luaG_addinfo(ls->L, msg, ls->source, ls->linenumber);
118
321
  if (token)
119
313
    luaO_pushfstring(ls->L, "%s near %s", msg, txtToken(ls, token));
120
321
  luaD_throw(ls->L, LUA_ERRSYNTAX);
121
321
}
122
123
124
249
l_noret luaX_syntaxerror (LexState *ls, const char *msg) {
125
249
  lexerror(ls, msg, ls->t.token);
126
249
}
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
24.6M
static TString *anchorstr (LexState *ls, TString *ts) {
136
24.6M
  lua_State *L = ls->L;
137
24.6M
  TValue oldts;
138
24.6M
  int tag = luaH_getstr(ls->h, ts, &oldts);
139
24.6M
  if (!tagisempty(tag))  /* string already present? */
140
24.6M
    return tsvalue(&oldts);  /* use stored value */
141
19.1k
  else {  /* create a new entry */
142
19.1k
    TValue *stv = s2v(L->top.p++);  /* reserve stack space for string */
143
19.1k
    setsvalue(L, stv, ts);  /* push (anchor) the string on the stack */
144
19.1k
    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
19.1k
    luaC_checkGC(L);
147
19.1k
    L->top.p--;  /* remove string from stack */
148
19.1k
    return ts;
149
19.1k
  }
150
24.6M
}
151
152
153
/*
154
** Creates a new string and anchors it in scanner's table.
155
*/
156
21.8k
TString *luaX_newstring (LexState *ls, const char *str, size_t l) {
157
21.8k
  return anchorstr(ls, luaS_newlstr(ls->L, str, l));
158
21.8k
}
159
160
161
/*
162
** increment line number and skips newline sequence (any of
163
** \n, \r, \n\r, or \r\n)
164
*/
165
3.57M
static void inclinenumber (LexState *ls) {
166
3.57M
  int old = ls->current;
167
3.57M
  lua_assert(currIsNewline(ls));
168
3.57M
  next(ls);  /* skip '\n' or '\r' */
169
3.57M
  if (currIsNewline(ls) && ls->current != old)
170
3.74k
    next(ls);  /* skip '\n\r' or '\r\n' */
171
3.57M
  if (++ls->linenumber >= INT_MAX)
172
0
    lexerror(ls, "chunk has too many lines", 0);
173
3.57M
}
174
175
176
void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source,
177
441
                    int firstchar) {
178
441
  ls->t.token = 0;
179
441
  ls->L = L;
180
441
  ls->current = firstchar;
181
441
  ls->lookahead.token = TK_EOS;  /* no look-ahead token */
182
441
  ls->z = z;
183
441
  ls->fs = NULL;
184
441
  ls->linenumber = 1;
185
441
  ls->lastline = 1;
186
441
  ls->source = source;
187
  /* all three strings here ("_ENV", "break", "global") were fixed,
188
     so they cannot be collected */
189
441
  ls->envn = luaS_newliteral(L, LUA_ENV);  /* get env string */
190
441
  ls->brkn = luaS_newliteral(L, "break");  /* get "break" string */
191
441
#if defined(LUA_COMPAT_GLOBAL)
192
  /* compatibility mode: "global" is not a reserved word */
193
441
  ls->glbn = luaS_newliteral(L, "global");  /* get "global" string */
194
441
  ls->glbn->extra = 0;  /* mark it as not reserved */
195
441
#endif
196
441
  luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER);  /* initialize buffer */
197
441
}
198
199
200
201
/*
202
** =======================================================
203
** LEXICAL ANALYZER
204
** =======================================================
205
*/
206
207
208
47.0M
static int check_next1 (LexState *ls, int c) {
209
47.0M
  if (ls->current == c) {
210
436k
    next(ls);
211
436k
    return 1;
212
436k
  }
213
46.5M
  else return 0;
214
47.0M
}
215
216
217
/*
218
** Check whether current char is in set 'set' (with two chars) and
219
** saves it
220
*/
221
6.88M
static int check_next2 (LexState *ls, const char *set) {
222
6.88M
  lua_assert(set[2] == '\0');
223
6.88M
  if (ls->current == set[0] || ls->current == set[1]) {
224
82.5k
    save_and_next(ls);
225
82.5k
    return 1;
226
82.5k
  }
227
6.79M
  else return 0;
228
6.88M
}
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
997k
static int read_numeral (LexState *ls, SemInfo *seminfo) {
245
997k
  TValue obj;
246
997k
  const char *expo = "Ee";
247
997k
  int first = ls->current;
248
997k
  lua_assert(lisdigit(ls->current));
249
997k
  save_and_next(ls);
250
997k
  if (first == '0' && check_next2(ls, "xX"))  /* hexadecimal? */
251
19
    expo = "Pp";
252
6.08M
  for (;;) {
253
6.08M
    if (check_next2(ls, expo))  /* exponent mark? */
254
82.5k
      check_next2(ls, "-+");  /* optional exponent sign */
255
6.00M
    else if (lisxdigit(ls->current) || ls->current == '.')  /* '%x|%.' */
256
5.00M
      save_and_next(ls);
257
997k
    else break;
258
6.08M
  }
259
997k
  if (lislalpha(ls->current))  /* is numeral touching a letter? */
260
11
    save_and_next(ls);  /* force an error */
261
997k
  save(ls, '\0');
262
997k
  if (luaO_str2num(luaZ_buffer(ls->buff), &obj) == 0)  /* format error? */
263
15
    lexerror(ls, "malformed number", TK_FLT);
264
997k
  if (ttisinteger(&obj)) {
265
984k
    seminfo->i = ivalue(&obj);
266
0
    return TK_INT;
267
984k
  }
268
13.2k
  else {
269
13.2k
    lua_assert(ttisfloat(&obj));
270
13.2k
    seminfo->r = fltvalue(&obj);
271
0
    return TK_FLT;
272
13.2k
  }
273
997k
}
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
51.1k
static size_t skip_sep (LexState *ls) {
283
51.1k
  size_t count = 0;
284
51.1k
  int s = ls->current;
285
51.1k
  lua_assert(s == '[' || s == ']');
286
51.1k
  save_and_next(ls);
287
68.7k
  while (ls->current == '=') {
288
17.6k
    save_and_next(ls);
289
17.6k
    count++;
290
17.6k
  }
291
51.1k
  return (ls->current == s) ? count + 2
292
51.1k
         : (count == 0) ? 1
293
40.3k
         : 0;
294
51.1k
}
295
296
297
1.31k
static void read_long_string (LexState *ls, SemInfo *seminfo, size_t sep) {
298
1.31k
  int line = ls->linenumber;  /* initial line (for error message) */
299
1.31k
  save_and_next(ls);  /* skip 2nd '[' */
300
1.31k
  if (currIsNewline(ls))  /* string starts with a newline? */
301
47
    inclinenumber(ls);  /* skip it */
302
12.4M
  for (;;) {
303
12.4M
    switch (ls->current) {
304
17
      case EOZ: {  /* error */
305
17
        const char *what = (seminfo ? "string" : "comment");
306
17
        const char *msg = luaO_pushfstring(ls->L,
307
17
                     "unfinished long %s (starting at line %d)", what, line);
308
17
        lexerror(ls, msg, TK_EOS);
309
0
        break;  /* to avoid warnings */
310
0
      }
311
48.5k
      case ']': {
312
48.5k
        if (skip_sep(ls) == sep) {
313
1.29k
          save_and_next(ls);  /* skip 2nd ']' */
314
1.29k
          goto endloop;
315
1.29k
        }
316
47.2k
        break;
317
48.5k
      }
318
2.47M
      case '\n': case '\r': {
319
2.47M
        save(ls, '\n');
320
2.47M
        inclinenumber(ls);
321
2.47M
        if (!seminfo) luaZ_resetbuffer(ls->buff);  /* avoid wasting space */
322
2.47M
        break;
323
2.32M
      }
324
9.93M
      default: {
325
9.93M
        if (seminfo) save_and_next(ls);
326
69.2k
        else next(ls);
327
9.93M
      }
328
12.4M
    }
329
12.4M
  } endloop:
330
1.29k
  if (seminfo)
331
1.28k
    seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + sep,
332
1.28k
                                     luaZ_bufflen(ls->buff) - 2 * sep);
333
1.29k
}
334
335
336
171k
static void esccheck (LexState *ls, int c, const char *msg) {
337
171k
  if (!c) {
338
30
    if (ls->current != EOZ)
339
29
      save_and_next(ls);  /* add current to buffer for error message */
340
30
    lexerror(ls, msg, TK_STRING);
341
30
  }
342
171k
}
343
344
345
3.68k
static int gethexa (LexState *ls) {
346
3.68k
  save_and_next(ls);
347
3.68k
  esccheck (ls, lisxdigit(ls->current), "hexadecimal digit expected");
348
3.68k
  return luaO_hexavalue(ls->current);
349
3.68k
}
350
351
352
605
static int readhexaesc (LexState *ls) {
353
605
  int r = gethexa(ls);
354
605
  r = (r << 4) + gethexa(ls);
355
605
  luaZ_buffremove(ls->buff, 2);  /* remove saved chars from buffer */
356
605
  return r;
357
605
}
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.48k
static l_uint32 readutf8esc (LexState *ls) {
366
2.48k
  l_uint32 r;
367
2.48k
  int i = 4;  /* number of chars to be removed: start with #"\u{X" */
368
2.48k
  save_and_next(ls);  /* skip 'u' */
369
2.48k
  esccheck(ls, ls->current == '{', "missing '{'");
370
2.48k
  r = cast_uint(gethexa(ls));  /* must have at least one digit */
371
4.57k
  while (cast_void(save_and_next(ls)), lisxdigit(ls->current)) {
372
2.09k
    i++;
373
2.09k
    esccheck(ls, r <= (0x7FFFFFFFu >> 4), "UTF-8 value too large");
374
2.09k
    r = (r << 4) + luaO_hexavalue(ls->current);
375
2.09k
  }
376
2.48k
  esccheck(ls, ls->current == '}', "missing '}'");
377
2.48k
  next(ls);  /* skip '}' */
378
2.48k
  luaZ_buffremove(ls->buff, i);  /* remove saved chars from buffer */
379
2.48k
  return r;
380
2.48k
}
381
382
383
2.48k
static void utf8esc (LexState *ls) {
384
2.48k
  char buff[UTF8BUFFSZ];
385
2.48k
  int n = luaO_utf8esc(buff, readutf8esc(ls));
386
5.97k
  for (; n > 0; n--)  /* add 'buff' to string */
387
3.49k
    save(ls, buff[UTF8BUFFSZ - n]);
388
2.48k
}
389
390
391
80.5k
static int readdecesc (LexState *ls) {
392
80.5k
  int i;
393
80.5k
  int r = 0;  /* result accumulator */
394
228k
  for (i = 0; i < 3 && lisdigit(ls->current); i++) {  /* read up to 3 digits */
395
148k
    r = 10*r + ls->current - '0';
396
148k
    save_and_next(ls);
397
148k
  }
398
80.5k
  esccheck(ls, r <= UCHAR_MAX, "decimal escape too large");
399
80.5k
  luaZ_buffremove(ls->buff, i);  /* remove read digits from buffer */
400
80.5k
  return r;
401
80.5k
}
402
403
404
19.2k
static void read_string (LexState *ls, int del, SemInfo *seminfo) {
405
19.2k
  save_and_next(ls);  /* keep delimiter (for error messages) */
406
19.5M
  while (ls->current != del) {
407
19.5M
    switch (ls->current) {
408
6
      case EOZ:
409
6
        lexerror(ls, "unfinished string", TK_EOS);
410
0
        break;  /* to avoid warnings */
411
3
      case '\n':
412
4
      case '\r':
413
4
        lexerror(ls, "unfinished string", TK_STRING);
414
0
        break;  /* to avoid warnings */
415
105k
      case '\\': {  /* escape sequences */
416
105k
        int c;  /* final character to be saved */
417
105k
        save_and_next(ls);  /* keep '\\' for error messages */
418
105k
        switch (ls->current) {
419
1.08k
          case 'a': c = '\a'; goto read_save;
420
83
          case 'b': c = '\b'; goto read_save;
421
2.03k
          case 'f': c = '\f'; goto read_save;
422
463
          case 'n': c = '\n'; goto read_save;
423
325
          case 'r': c = '\r'; goto read_save;
424
14.5k
          case 't': c = '\t'; goto read_save;
425
2.14k
          case 'v': c = '\v'; goto read_save;
426
605
          case 'x': c = readhexaesc(ls); goto read_save;
427
2.48k
          case 'u': utf8esc(ls);  goto no_save;
428
0
          case '\n': case '\r':
429
0
            inclinenumber(ls); c = '\n'; goto only_save;
430
867
          case '\\': case '\"': case '\'':
431
867
            c = ls->current; goto read_save;
432
1
          case EOZ: goto no_save;  /* will raise an error next loop */
433
347
          case 'z': {  /* zap following span of spaces */
434
347
            luaZ_buffremove(ls->buff, 1);  /* remove '\\' */
435
347
            next(ls);  /* skip the 'z' */
436
347
            while (lisspace(ls->current)) {
437
89
              if (currIsNewline(ls)) inclinenumber(ls);
438
81
              else next(ls);
439
89
            }
440
347
            goto no_save;
441
846
          }
442
80.5k
          default: {
443
80.5k
            esccheck(ls, lisdigit(ls->current), "invalid escape sequence");
444
80.5k
            c = readdecesc(ls);  /* digital escape '\ddd' */
445
80.5k
            goto only_save;
446
846
          }
447
105k
        }
448
22.1k
       read_save:
449
22.1k
         next(ls);
450
         /* go through */
451
102k
       only_save:
452
102k
         luaZ_buffremove(ls->buff, 1);  /* remove '\\' */
453
102k
         save(ls, c);
454
         /* go through */
455
105k
       no_save: break;
456
102k
      }
457
19.4M
      default:
458
19.4M
        save_and_next(ls);
459
19.5M
    }
460
19.5M
  }
461
19.2k
  save_and_next(ls);  /* skip delimiter */
462
19.2k
  seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1,
463
19.2k
                                   luaZ_bufflen(ls->buff) - 2);
464
19.2k
}
465
466
467
51.4M
static int llex (LexState *ls, SemInfo *seminfo) {
468
51.4M
  luaZ_resetbuffer(ls->buff);
469
52.5M
  for (;;) {
470
52.5M
    switch (ls->current) {
471
1.09M
      case '\n': case '\r': {  /* line breaks */
472
1.09M
        inclinenumber(ls);
473
1.09M
        break;
474
1.07M
      }
475
33.2k
      case ' ': case '\f': case '\t': case '\v': {  /* spaces */
476
33.2k
        next(ls);
477
33.2k
        break;
478
29.1k
      }
479
77.9k
      case '-': {  /* '-' or '--' (comment) */
480
77.9k
        next(ls);
481
77.9k
        if (ls->current != '-') return '-';
482
        /* else is a comment */
483
9.07k
        next(ls);
484
9.07k
        if (ls->current == '[') {  /* long comment? */
485
22
          size_t sep = skip_sep(ls);
486
22
          luaZ_resetbuffer(ls->buff);  /* 'skip_sep' may dirty the buffer */
487
22
          if (sep >= 2) {
488
11
            read_long_string(ls, NULL, sep);  /* skip long comment */
489
11
            luaZ_resetbuffer(ls->buff);  /* previous call may dirty the buff. */
490
11
            break;
491
11
          }
492
22
        }
493
        /* else short comment */
494
846k
        while (!currIsNewline(ls) && ls->current != EOZ)
495
837k
          next(ls);  /* skip until end of line (or end of file) */
496
9.06k
        break;
497
9.07k
      }
498
2.56k
      case '[': {  /* long string or simply '[' */
499
2.56k
        size_t sep = skip_sep(ls);
500
2.56k
        if (sep >= 2) {
501
1.30k
          read_long_string(ls, seminfo, sep);
502
1.30k
          return TK_STRING;
503
1.30k
        }
504
1.26k
        else if (sep == 0)  /* '[=...' missing second bracket? */
505
0
          lexerror(ls, "invalid long string delimiter", TK_STRING);
506
1.26k
        return '[';
507
2.56k
      }
508
15.9k
      case '=': {
509
15.9k
        next(ls);
510
15.9k
        if (check_next1(ls, '=')) return TK_EQ;  /* '==' */
511
13.9k
        else return '=';
512
15.9k
      }
513
430k
      case '<': {
514
430k
        next(ls);
515
430k
        if (check_next1(ls, '=')) return TK_LE;  /* '<=' */
516
425k
        else if (check_next1(ls, '<')) return TK_SHL;  /* '<<' */
517
396k
        else return '<';
518
430k
      }
519
22.3M
      case '>': {
520
22.3M
        next(ls);
521
22.3M
        if (check_next1(ls, '=')) return TK_GE;  /* '>=' */
522
22.3M
        else if (check_next1(ls, '>')) return TK_SHR;  /* '>>' */
523
21.9M
        else return '>';
524
22.3M
      }
525
1.23M
      case '/': {
526
1.23M
        next(ls);
527
1.23M
        if (check_next1(ls, '/')) return TK_IDIV;  /* '//' */
528
1.22M
        else return '/';
529
1.23M
      }
530
144k
      case '~': {
531
144k
        next(ls);
532
144k
        if (check_next1(ls, '=')) return TK_NE;  /* '~=' */
533
143k
        else return '~';
534
144k
      }
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
19.2k
      case '"': case '\'': {  /* short literal strings */
541
19.2k
        read_string(ls, ls->current, seminfo);
542
19.2k
        return TK_STRING;
543
13.7k
      }
544
20.9k
      case '.': {  /* '.', '..', '...', or number */
545
20.9k
        save_and_next(ls);
546
20.9k
        if (check_next1(ls, '.')) {
547
8.06k
          if (check_next1(ls, '.'))
548
4.26k
            return TK_DOTS;   /* '...' */
549
3.80k
          else return TK_CONCAT;   /* '..' */
550
8.06k
        }
551
12.8k
        else if (!lisdigit(ls->current)) return '.';
552
382
        else return read_numeral(ls, seminfo);
553
20.9k
      }
554
835k
      case '0': case '1': case '2': case '3': case '4':
555
997k
      case '5': case '6': case '7': case '8': case '9': {
556
997k
        return read_numeral(ls, seminfo);
557
914k
      }
558
144
      case EOZ: {
559
144
        return TK_EOS;
560
914k
      }
561
26.1M
      default: {
562
26.1M
        if (lislalpha(ls->current)) {  /* identifier or reserved word? */
563
24.6M
          TString *ts;
564
28.1M
          do {
565
28.1M
            save_and_next(ls);
566
28.1M
          } while (lislalnum(ls->current));
567
          /* find or create string */
568
24.6M
          ts = luaS_newlstr(ls->L, luaZ_buffer(ls->buff),
569
24.6M
                                   luaZ_bufflen(ls->buff));
570
24.6M
          if (isreserved(ts))   /* reserved word? */
571
44.8k
            return ts->extra - 1 + FIRST_RESERVED;
572
24.6M
          else {
573
24.6M
            seminfo->ts = anchorstr(ls, ts);
574
24.6M
            return TK_NAME;
575
24.6M
          }
576
24.6M
        }
577
1.43M
        else {  /* single-char tokens ('+', '*', '%', '{', '}', ...) */
578
1.43M
          int c = ls->current;
579
1.43M
          next(ls);
580
1.43M
          return c;
581
1.43M
        }
582
26.1M
      }
583
52.5M
    }
584
52.5M
  }
585
51.4M
}
586
587
588
51.4M
void luaX_next (LexState *ls) {
589
51.4M
  ls->lastline = ls->linenumber;
590
51.4M
  if (ls->lookahead.token != TK_EOS) {  /* is there a look-ahead token? */
591
1.00M
    ls->t = ls->lookahead;  /* use this one */
592
1.00M
    ls->lookahead.token = TK_EOS;  /* and discharge it */
593
1.00M
  }
594
50.3M
  else
595
50.3M
    ls->t.token = llex(ls, &ls->t.seminfo);  /* read next token */
596
51.4M
}
597
598
599
1.00M
int luaX_lookahead (LexState *ls) {
600
1.00M
  lua_assert(ls->lookahead.token == TK_EOS);
601
1.00M
  ls->lookahead.token = llex(ls, &ls->lookahead.seminfo);
602
1.00M
  return ls->lookahead.token;
603
1.00M
}
604