Coverage Report

Created: 2025-10-10 06:41

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