Coverage Report

Created: 2026-01-10 06:59

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.33G
#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
279M
#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.92G
#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.97G
static void save (LexState *ls, int c) {
63
1.97G
  Mbuffer *b = ls->buff;
64
1.97G
  if (luaZ_bufflen(b) + 1 > luaZ_sizebuffer(b)) {
65
1.16M
    size_t newsize = luaZ_sizebuffer(b);  /* get old size */;
66
1.16M
    if (newsize >= (MAX_SIZE/3 * 2))  /* larger than MAX_SIZE/1.5 ? */
67
0
      lexerror(ls, "lexical element too long", 0);
68
1.16M
    newsize += (newsize >> 1);  /* new size is 1.5 times the old one */
69
1.16M
    luaZ_resizebuffer(ls->L, b, newsize);
70
1.16M
  }
71
1.97G
  b->buffer[luaZ_bufflen(b)++] = cast_char(c);
72
1.97G
}
73
74
75
49.0k
void luaX_init (lua_State *L) {
76
49.0k
  int i;
77
49.0k
  TString *e = luaS_newliteral(L, LUA_ENV);  /* create env name */
78
49.0k
  luaC_fix(L, obj2gco(e));  /* never collect this name */
79
1.17M
  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
49.0k
}
85
86
87
3.25M
const char *luaX_token2str (LexState *ls, int token) {
88
3.25M
  if (token < FIRST_RESERVED) {  /* single-byte symbols? */
89
2.40M
    if (lisprint(token))
90
1.31M
      return luaO_pushfstring(ls->L, "'%c'", token);
91
1.08M
    else  /* control character */
92
1.08M
      return luaO_pushfstring(ls->L, "'<\\%d>'", token);
93
2.40M
  }
94
852k
  else {
95
852k
    const char *s = luaX_tokens[token - FIRST_RESERVED];
96
852k
    if (token < TK_EOS)  /* fixed format (symbols and reserved words)? */
97
180k
      return luaO_pushfstring(ls->L, "'%s'", s);
98
672k
    else  /* names, strings, and numerals */
99
672k
      return s;
100
852k
  }
101
3.25M
}
102
103
104
3.27M
static const char *txtToken (LexState *ls, int token) {
105
3.27M
  switch (token) {
106
270k
    case TK_NAME: case TK_STRING:
107
869k
    case TK_FLT: case TK_INT:
108
869k
      save(ls, '\0');
109
869k
      return luaO_pushfstring(ls->L, "'%s'", luaZ_buffer(ls->buff));
110
2.40M
    default:
111
2.40M
      return luaX_token2str(ls, token);
112
3.27M
  }
113
3.27M
}
114
115
116
3.51M
static l_noret lexerror (LexState *ls, const char *msg, int token) {
117
3.51M
  msg = luaG_addinfo(ls->L, msg, ls->source, ls->linenumber);
118
3.51M
  if (token)
119
3.27M
    luaO_pushfstring(ls->L, "%s near %s", msg, txtToken(ls, token));
120
3.51M
  luaD_throw(ls->L, LUA_ERRSYNTAX);
121
3.51M
}
122
123
124
2.89M
l_noret luaX_syntaxerror (LexState *ls, const char *msg) {
125
2.89M
  lexerror(ls, msg, ls->t.token);
126
2.89M
}
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
204M
static TString *anchorstr (LexState *ls, TString *ts) {
136
204M
  lua_State *L = ls->L;
137
204M
  TValue oldts;
138
204M
  int tag = luaH_getstr(ls->h, ts, &oldts);
139
204M
  if (!tagisempty(tag))  /* string already present? */
140
204M
    return tsvalue(&oldts);  /* use stored value */
141
17.1M
  else {  /* create a new entry */
142
17.1M
    TValue *stv = s2v(L->top.p++);  /* reserve stack space for string */
143
17.1M
    setsvalue(L, stv, ts);  /* push (anchor) the string on the stack */
144
17.1M
    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.1M
    luaC_checkGC(L);
147
17.1M
    L->top.p--;  /* remove string from stack */
148
17.1M
    return ts;
149
17.1M
  }
150
204M
}
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
43.4M
static void inclinenumber (LexState *ls) {
166
43.4M
  int old = ls->current;
167
43.4M
  lua_assert(currIsNewline(ls));
168
43.4M
  next(ls);  /* skip '\n' or '\r' */
169
43.4M
  if (currIsNewline(ls) && ls->current != old)
170
71.6k
    next(ls);  /* skip '\n\r' or '\r\n' */
171
43.4M
  if (++ls->linenumber >= INT_MAX)
172
0
    lexerror(ls, "chunk has too many lines", 0);
173
43.4M
}
174
175
176
void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source,
177
5.68M
                    int firstchar) {
178
5.68M
  ls->t.token = 0;
179
5.68M
  ls->L = L;
180
5.68M
  ls->current = firstchar;
181
5.68M
  ls->lookahead.token = TK_EOS;  /* no look-ahead token */
182
5.68M
  ls->z = z;
183
5.68M
  ls->fs = NULL;
184
5.68M
  ls->linenumber = 1;
185
5.68M
  ls->lastline = 1;
186
5.68M
  ls->source = source;
187
  /* all three strings here ("_ENV", "break", "global") were fixed,
188
     so they cannot be collected */
189
5.68M
  ls->envn = luaS_newliteral(L, LUA_ENV);  /* get env string */
190
5.68M
  ls->brkn = luaS_newliteral(L, "break");  /* get "break" string */
191
5.68M
#if defined(LUA_COMPAT_GLOBAL)
192
  /* compatibility mode: "global" is not a reserved word */
193
5.68M
  ls->glbn = luaS_newliteral(L, "global");  /* get "global" string */
194
5.68M
  ls->glbn->extra = 0;  /* mark it as not reserved */
195
5.68M
#endif
196
5.68M
  luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER);  /* initialize buffer */
197
5.68M
}
198
199
200
201
/*
202
** =======================================================
203
** LEXICAL ANALYZER
204
** =======================================================
205
*/
206
207
208
344M
static int check_next1 (LexState *ls, int c) {
209
344M
  if (ls->current == c) {
210
4.37M
    next(ls);
211
4.37M
    return 1;
212
4.37M
  }
213
339M
  else return 0;
214
344M
}
215
216
217
/*
218
** Check whether current char is in set 'set' (with two chars) and
219
** saves it
220
*/
221
298M
static int check_next2 (LexState *ls, const char *set) {
222
298M
  lua_assert(set[2] == '\0');
223
298M
  if (ls->current == set[0] || ls->current == set[1]) {
224
3.77M
    save_and_next(ls);
225
3.77M
    return 1;
226
3.77M
  }
227
295M
  else return 0;
228
298M
}
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.8M
static int read_numeral (LexState *ls, SemInfo *seminfo) {
245
18.8M
  TValue obj;
246
18.8M
  const char *expo = "Ee";
247
18.8M
  int first = ls->current;
248
18.8M
  lua_assert(lisdigit(ls->current));
249
18.8M
  save_and_next(ls);
250
18.8M
  if (first == '0' && check_next2(ls, "xX"))  /* hexadecimal? */
251
44.1k
    expo = "Pp";
252
290M
  for (;;) {
253
290M
    if (check_next2(ls, expo))  /* exponent mark? */
254
3.50M
      check_next2(ls, "-+");  /* optional exponent sign */
255
287M
    else if (lisxdigit(ls->current) || ls->current == '.')  /* '%x|%.' */
256
268M
      save_and_next(ls);
257
18.8M
    else break;
258
290M
  }
259
18.8M
  if (lislalpha(ls->current))  /* is numeral touching a letter? */
260
175k
    save_and_next(ls);  /* force an error */
261
18.8M
  save(ls, '\0');
262
18.8M
  if (luaO_str2num(luaZ_buffer(ls->buff), &obj) == 0)  /* format error? */
263
261k
    lexerror(ls, "malformed number", TK_FLT);
264
18.5M
  if (ttisinteger(&obj)) {
265
12.2M
    seminfo->i = ivalue(&obj);
266
12.2M
    return TK_INT;
267
12.2M
  }
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.5M
}
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.81M
static size_t skip_sep (LexState *ls) {
283
1.81M
  size_t count = 0;
284
1.81M
  int s = ls->current;
285
1.81M
  lua_assert(s == '[' || s == ']');
286
1.81M
  save_and_next(ls);
287
11.5M
  while (ls->current == '=') {
288
9.72M
    save_and_next(ls);
289
9.72M
    count++;
290
9.72M
  }
291
1.81M
  return (ls->current == s) ? count + 2
292
1.81M
         : (count == 0) ? 1
293
742k
         : 0;
294
1.81M
}
295
296
297
263k
static void read_long_string (LexState *ls, SemInfo *seminfo, size_t sep) {
298
263k
  int line = ls->linenumber;  /* initial line (for error message) */
299
263k
  save_and_next(ls);  /* skip 2nd '[' */
300
263k
  if (currIsNewline(ls))  /* string starts with a newline? */
301
60.5k
    inclinenumber(ls);  /* skip it */
302
701M
  for (;;) {
303
701M
    switch (ls->current) {
304
140k
      case EOZ: {  /* error */
305
140k
        const char *what = (seminfo ? "string" : "comment");
306
140k
        const char *msg = luaO_pushfstring(ls->L,
307
140k
                     "unfinished long %s (starting at line %d)", what, line);
308
140k
        lexerror(ls, msg, TK_EOS);
309
0
        break;  /* to avoid warnings */
310
0
      }
311
1.08M
      case ']': {
312
1.08M
        if (skip_sep(ls) == sep) {
313
122k
          save_and_next(ls);  /* skip 2nd ']' */
314
122k
          goto endloop;
315
122k
        }
316
958k
        break;
317
1.08M
      }
318
33.2M
      case '\n': case '\r': {
319
33.2M
        save(ls, '\n');
320
33.2M
        inclinenumber(ls);
321
33.2M
        if (!seminfo) luaZ_resetbuffer(ls->buff);  /* avoid wasting space */
322
33.2M
        break;
323
29.7M
      }
324
666M
      default: {
325
666M
        if (seminfo) save_and_next(ls);
326
5.05M
        else next(ls);
327
666M
      }
328
701M
    }
329
701M
  } endloop:
330
122k
  if (seminfo)
331
119k
    seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + sep,
332
119k
                                     luaZ_bufflen(ls->buff) - 2 * sep);
333
122k
}
334
335
336
1.15M
static void esccheck (LexState *ls, int c, const char *msg) {
337
1.15M
  if (!c) {
338
62.0k
    if (ls->current != EOZ)
339
55.6k
      save_and_next(ls);  /* add current to buffer for error message */
340
62.0k
    lexerror(ls, msg, TK_STRING);
341
62.0k
  }
342
1.15M
}
343
344
345
421k
static int gethexa (LexState *ls) {
346
421k
  save_and_next(ls);
347
421k
  esccheck (ls, lisxdigit(ls->current), "hexadecimal digit expected");
348
421k
  return luaO_hexavalue(ls->current);
349
421k
}
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
50.7k
static l_uint32 readutf8esc (LexState *ls) {
366
50.7k
  l_uint32 r;
367
50.7k
  int i = 4;  /* number of chars to be removed: start with #"\u{X" */
368
50.7k
  save_and_next(ls);  /* skip 'u' */
369
50.7k
  esccheck(ls, ls->current == '{', "missing '{'");
370
50.7k
  r = cast_uint(gethexa(ls));  /* must have at least one digit */
371
294k
  while (cast_void(save_and_next(ls)), lisxdigit(ls->current)) {
372
243k
    i++;
373
243k
    esccheck(ls, r <= (0x7FFFFFFFu >> 4), "UTF-8 value too large");
374
243k
    r = (r << 4) + luaO_hexavalue(ls->current);
375
243k
  }
376
50.7k
  esccheck(ls, ls->current == '}', "missing '}'");
377
50.7k
  next(ls);  /* skip '}' */
378
50.7k
  luaZ_buffremove(ls->buff, i);  /* remove saved chars from buffer */
379
50.7k
  return r;
380
50.7k
}
381
382
383
50.7k
static void utf8esc (LexState *ls) {
384
50.7k
  char buff[UTF8BUFFSZ];
385
50.7k
  int n = luaO_utf8esc(buff, readutf8esc(ls));
386
134k
  for (; n > 0; n--)  /* add 'buff' to string */
387
83.6k
    save(ls, buff[UTF8BUFFSZ - n]);
388
50.7k
}
389
390
391
196k
static int readdecesc (LexState *ls) {
392
196k
  int i;
393
196k
  int r = 0;  /* result accumulator */
394
662k
  for (i = 0; i < 3 && lisdigit(ls->current); i++) {  /* read up to 3 digits */
395
466k
    r = 10*r + ls->current - '0';
396
466k
    save_and_next(ls);
397
466k
  }
398
196k
  esccheck(ls, r <= UCHAR_MAX, "decimal escape too large");
399
196k
  luaZ_buffremove(ls->buff, i);  /* remove read digits from buffer */
400
196k
  return r;
401
196k
}
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
285M
  while (ls->current != del) {
407
282M
    switch (ls->current) {
408
135k
      case EOZ:
409
135k
        lexerror(ls, "unfinished string", TK_EOS);
410
0
        break;  /* to avoid warnings */
411
8.47k
      case '\n':
412
12.0k
      case '\r':
413
12.0k
        lexerror(ls, "unfinished string", TK_STRING);
414
0
        break;  /* to avoid warnings */
415
1.60M
      case '\\': {  /* escape sequences */
416
1.60M
        int c;  /* final character to be saved */
417
1.60M
        save_and_next(ls);  /* keep '\\' for error messages */
418
1.60M
        switch (ls->current) {
419
3.24k
          case 'a': c = '\a'; goto read_save;
420
1.95k
          case 'b': c = '\b'; goto read_save;
421
8.10k
          case 'f': c = '\f'; goto read_save;
422
220k
          case 'n': c = '\n'; goto read_save;
423
18.8k
          case 'r': c = '\r'; goto read_save;
424
20.4k
          case 't': c = '\t'; goto read_save;
425
6.49k
          case 'v': c = '\v'; goto read_save;
426
189k
          case 'x': c = readhexaesc(ls); goto read_save;
427
50.7k
          case 'u': utf8esc(ls);  goto no_save;
428
24.4k
          case '\n': case '\r':
429
24.4k
            inclinenumber(ls); c = '\n'; goto only_save;
430
825k
          case '\\': case '\"': case '\'':
431
825k
            c = ls->current; goto read_save;
432
3.39k
          case EOZ: goto no_save;  /* will raise an error next loop */
433
26.8k
          case 'z': {  /* zap following span of spaces */
434
26.8k
            luaZ_buffremove(ls->buff, 1);  /* remove '\\' */
435
26.8k
            next(ls);  /* skip the 'z' */
436
28.7k
            while (lisspace(ls->current)) {
437
28.7k
              if (currIsNewline(ls)) inclinenumber(ls);
438
25.8k
              else next(ls);
439
28.7k
            }
440
26.8k
            goto no_save;
441
811k
          }
442
203k
          default: {
443
203k
            esccheck(ls, lisdigit(ls->current), "invalid escape sequence");
444
203k
            c = readdecesc(ls);  /* digital escape '\ddd' */
445
203k
            goto only_save;
446
811k
          }
447
1.60M
        }
448
1.29M
       read_save:
449
1.29M
         next(ls);
450
         /* go through */
451
1.48M
       only_save:
452
1.48M
         luaZ_buffremove(ls->buff, 1);  /* remove '\\' */
453
1.48M
         save(ls, c);
454
         /* go through */
455
1.54M
       no_save: break;
456
1.48M
      }
457
280M
      default:
458
280M
        save_and_next(ls);
459
282M
    }
460
282M
  }
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
469M
static int llex (LexState *ls, SemInfo *seminfo) {
468
469M
  luaZ_resetbuffer(ls->buff);
469
506M
  for (;;) {
470
506M
    switch (ls->current) {
471
10.1M
      case '\n': case '\r': {  /* line breaks */
472
10.1M
        inclinenumber(ls);
473
10.1M
        break;
474
9.13M
      }
475
26.2M
      case ' ': case '\f': case '\t': case '\v': {  /* spaces */
476
26.2M
        next(ls);
477
26.2M
        break;
478
25.6M
      }
479
4.33M
      case '-': {  /* '-' or '--' (comment) */
480
4.33M
        next(ls);
481
4.33M
        if (ls->current != '-') return '-';
482
        /* else is a comment */
483
441k
        next(ls);
484
441k
        if (ls->current == '[') {  /* long comment? */
485
7.97k
          size_t sep = skip_sep(ls);
486
7.97k
          luaZ_resetbuffer(ls->buff);  /* 'skip_sep' may dirty the buffer */
487
7.97k
          if (sep >= 2) {
488
3.88k
            read_long_string(ls, NULL, sep);  /* skip long comment */
489
3.88k
            luaZ_resetbuffer(ls->buff);  /* previous call may dirty the buff. */
490
3.88k
            break;
491
3.88k
          }
492
7.97k
        }
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
441k
      }
498
724k
      case '[': {  /* long string or simply '[' */
499
724k
        size_t sep = skip_sep(ls);
500
724k
        if (sep >= 2) {
501
259k
          read_long_string(ls, seminfo, sep);
502
259k
          return TK_STRING;
503
259k
        }
504
465k
        else if (sep == 0)  /* '[=...' missing second bracket? */
505
8.78k
          lexerror(ls, "invalid long string delimiter", TK_STRING);
506
456k
        return '[';
507
724k
      }
508
8.56M
      case '=': {
509
8.56M
        next(ls);
510
8.56M
        if (check_next1(ls, '=')) return TK_EQ;  /* '==' */
511
8.36M
        else return '=';
512
8.56M
      }
513
9.58M
      case '<': {
514
9.58M
        next(ls);
515
9.58M
        if (check_next1(ls, '=')) return TK_LE;  /* '<=' */
516
9.12M
        else if (check_next1(ls, '<')) return TK_SHL;  /* '<<' */
517
8.54M
        else return '<';
518
9.58M
      }
519
143M
      case '>': {
520
143M
        next(ls);
521
143M
        if (check_next1(ls, '=')) return TK_GE;  /* '>=' */
522
143M
        else if (check_next1(ls, '>')) return TK_SHR;  /* '>>' */
523
141M
        else return '>';
524
143M
      }
525
10.5M
      case '/': {
526
10.5M
        next(ls);
527
10.5M
        if (check_next1(ls, '/')) return TK_IDIV;  /* '//' */
528
10.1M
        else return '/';
529
10.5M
      }
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
530k
      case ':': {
536
530k
        next(ls);
537
530k
        if (check_next1(ls, ':')) return TK_DBCOLON;  /* '::' */
538
303k
        else return ':';
539
530k
      }
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
6.94M
      case '.': {  /* '.', '..', '...', or number */
545
6.94M
        save_and_next(ls);
546
6.94M
        if (check_next1(ls, '.')) {
547
763k
          if (check_next1(ls, '.'))
548
142k
            return TK_DOTS;   /* '...' */
549
620k
          else return TK_CONCAT;   /* '..' */
550
763k
        }
551
6.17M
        else if (!lisdigit(ls->current)) return '.';
552
343k
        else return read_numeral(ls, seminfo);
553
6.94M
      }
554
14.0M
      case '0': case '1': case '2': case '3': case '4':
555
18.5M
      case '5': case '6': case '7': case '8': case '9': {
556
18.5M
        return read_numeral(ls, seminfo);
557
17.7M
      }
558
2.34M
      case EOZ: {
559
2.34M
        return TK_EOS;
560
17.7M
      }
561
249M
      default: {
562
249M
        if (lislalpha(ls->current)) {  /* identifier or reserved word? */
563
208M
          TString *ts;
564
662M
          do {
565
662M
            save_and_next(ls);
566
662M
          } while (lislalnum(ls->current));
567
          /* find or create string */
568
208M
          ts = luaS_newlstr(ls->L, luaZ_buffer(ls->buff),
569
208M
                                   luaZ_bufflen(ls->buff));
570
208M
          if (isreserved(ts))   /* reserved word? */
571
7.20M
            return ts->extra - 1 + FIRST_RESERVED;
572
201M
          else {
573
201M
            seminfo->ts = anchorstr(ls, ts);
574
201M
            return TK_NAME;
575
201M
          }
576
208M
        }
577
41.2M
        else {  /* single-char tokens ('+', '*', '%', '{', '}', ...) */
578
41.2M
          int c = ls->current;
579
41.2M
          next(ls);
580
41.2M
          return c;
581
41.2M
        }
582
249M
      }
583
506M
    }
584
506M
  }
585
469M
}
586
587
588
469M
void luaX_next (LexState *ls) {
589
469M
  ls->lastline = ls->linenumber;
590
469M
  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
456M
  else
595
456M
    ls->t.token = llex(ls, &ls->t.seminfo);  /* read next token */
596
469M
}
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