Coverage Report

Created: 2025-12-14 06:44

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