Coverage Report

Created: 2025-07-18 07:03

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