Coverage Report

Created: 2026-01-16 06:23

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