Coverage Report

Created: 2026-01-09 06:47

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