Coverage Report

Created: 2026-02-26 07:19

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