Coverage Report

Created: 2025-11-24 06:29

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