Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
llex.c File Reference
#include "lprefix.h"
#include <locale.h>
#include <string.h>
#include "lua.h"
#include "lctype.h"
#include "ldebug.h"
#include "ldo.h"
#include "lgc.h"
#include "llex.h"
#include "lobject.h"
#include "lparser.h"
#include "lstate.h"
#include "lstring.h"
#include "ltable.h"
#include "lzio.h"

Go to the source code of this file.

Macros

#define llex_c
 
#define LUA_CORE
 
#define next(ls)   (ls->current = zgetc(ls->z))
 
#define currIsNewline(ls)   (ls->current == '\n' || ls->current == '\r')
 
#define save_and_next(ls)   (save(ls, ls->current), next(ls))
 

Functions

static l_noret lexerror (LexState *ls, const char *msg, int token)
 
static void save (LexState *ls, int c)
 
void luaX_init (lua_State *L)
 
const char * luaX_token2str (LexState *ls, int token)
 
static const char * txtToken (LexState *ls, int token)
 
l_noret luaX_syntaxerror (LexState *ls, const char *msg)
 
TStringluaX_newstring (LexState *ls, const char *str, size_t l)
 
static void inclinenumber (LexState *ls)
 
void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source, int firstchar)
 
static int check_next1 (LexState *ls, int c)
 
static int check_next2 (LexState *ls, const char *set)
 
static int read_numeral (LexState *ls, SemInfo *seminfo)
 
static size_t skip_sep (LexState *ls)
 
static void read_long_string (LexState *ls, SemInfo *seminfo, size_t sep)
 
static void esccheck (LexState *ls, int c, const char *msg)
 
static int gethexa (LexState *ls)
 
static int readhexaesc (LexState *ls)
 
static unsigned long readutf8esc (LexState *ls)
 
static void utf8esc (LexState *ls)
 
static int readdecesc (LexState *ls)
 
static void read_string (LexState *ls, int del, SemInfo *seminfo)
 
static int llex (LexState *ls, SemInfo *seminfo)
 
void luaX_next (LexState *ls)
 
int luaX_lookahead (LexState *ls)
 

Variables

static const char *const luaX_tokens []
 

Macro Definition Documentation

◆ currIsNewline

#define currIsNewline ( ls)    (ls->current == '\n' || ls->current == '\r')

Definition at line 36 of file lua-5.4.3/src/llex.c.

Referenced by inclinenumber(), llex(), read_long_string(), and read_string().

◆ llex_c

#define llex_c

Definition at line 7 of file lua-5.4.3/src/llex.c.

◆ LUA_CORE

#define LUA_CORE

Definition at line 8 of file lua-5.4.3/src/llex.c.

◆ next

#define next ( ls)    (ls->current = zgetc(ls->z))

◆ save_and_next

#define save_and_next ( ls)    (save(ls, ls->current), next(ls))

Function Documentation

◆ check_next1()

static int check_next1 ( LexState * ls,
int c )
static

Definition at line 191 of file lua-5.4.3/src/llex.c.

191 {
192 if (ls->current == c) {
193 next(ls);
194 return 1;
195 }
196 else return 0;
197}
#define next(ls)

References LexState::current, and next.

Referenced by llex().

◆ check_next2()

static int check_next2 ( LexState * ls,
const char * set )
static

Definition at line 204 of file lua-5.4.3/src/llex.c.

204 {
205 lua_assert(set[2] == '\0');
206 if (ls->current == set[0] || ls->current == set[1]) {
207 save_and_next(ls);
208 return 1;
209 }
210 else return 0;
211}
#define lua_assert(c)
#define save_and_next(ls)

References LexState::current, lua_assert, and save_and_next.

Referenced by read_numeral().

◆ esccheck()

static void esccheck ( LexState * ls,
int c,
const char * msg )
static

Definition at line 319 of file lua-5.4.3/src/llex.c.

319 {
320 if (!c) {
321 if (ls->current != EOZ)
322 save_and_next(ls); /* add current to buffer for error message */
323 lexerror(ls, msg, TK_STRING);
324 }
325}
#define EOZ
static l_noret lexerror(LexState *ls, const char *msg, int token)
#define TK_STRING
Definition sqlite3.c:14057

References LexState::current, EOZ, lexerror(), save_and_next, and TK_STRING.

Referenced by gethexa(), read_string(), readdecesc(), and readutf8esc().

◆ gethexa()

static int gethexa ( LexState * ls)
static

Definition at line 328 of file lua-5.4.3/src/llex.c.

328 {
329 save_and_next(ls);
330 esccheck (ls, lisxdigit(ls->current), "hexadecimal digit expected");
331 return luaO_hexavalue(ls->current);
332}
#define lisxdigit(c)
int luaO_hexavalue(int c)
static void esccheck(LexState *ls, int c, const char *msg)

References LexState::current, esccheck(), lisxdigit, luaO_hexavalue(), and save_and_next.

Referenced by readhexaesc(), and readutf8esc().

◆ inclinenumber()

static void inclinenumber ( LexState * ls)
static

Definition at line 156 of file lua-5.4.3/src/llex.c.

156 {
157 int old = ls->current;
159 next(ls); /* skip '\n' or '\r' */
160 if (currIsNewline(ls) && ls->current != old)
161 next(ls); /* skip '\n\r' or '\r\n' */
162 if (++ls->linenumber >= MAX_INT)
163 lexerror(ls, "chunk has too many lines", 0);
164}
#define MAX_INT
#define currIsNewline(ls)

References LexState::current, currIsNewline, lexerror(), LexState::linenumber, lua_assert, MAX_INT, and next.

Referenced by llex(), read_long_string(), and read_string().

◆ lexerror()

static l_noret lexerror ( LexState * ls,
const char * msg,
int token )
static

Definition at line 111 of file lua-5.4.3/src/llex.c.

111 {
112 msg = luaG_addinfo(ls->L, msg, ls->source, ls->linenumber);
113 if (token)
114 luaO_pushfstring(ls->L, "%s near %s", msg, txtToken(ls, token));
116}
void luaD_throw(lua_State *L, int errcode)
const char * luaO_pushfstring(lua_State *L, const char *fmt,...)
#define LUA_ERRSYNTAX
const char * luaG_addinfo(lua_State *L, const char *msg, TString *src, int line)
static const char * txtToken(LexState *ls, int token)
struct lua_State * L
TString * source

References LexState::L, LexState::linenumber, LUA_ERRSYNTAX, luaD_throw(), luaG_addinfo(), luaO_pushfstring(), LexState::source, and txtToken().

Referenced by esccheck(), inclinenumber(), llex(), luaX_syntaxerror(), read_long_string(), read_numeral(), read_string(), and save().

◆ llex()

static int llex ( LexState * ls,
SemInfo * seminfo )
static

Definition at line 445 of file lua-5.4.3/src/llex.c.

445 {
447 for (;;) {
448 switch (ls->current) {
449 case '\n': case '\r': { /* line breaks */
450 inclinenumber(ls);
451 break;
452 }
453 case ' ': case '\f': case '\t': case '\v': { /* spaces */
454 next(ls);
455 break;
456 }
457 case '-': { /* '-' or '--' (comment) */
458 next(ls);
459 if (ls->current != '-') return '-';
460 /* else is a comment */
461 next(ls);
462 if (ls->current == '[') { /* long comment? */
463 size_t sep = skip_sep(ls);
464 luaZ_resetbuffer(ls->buff); /* 'skip_sep' may dirty the buffer */
465 if (sep >= 2) {
466 read_long_string(ls, NULL, sep); /* skip long comment */
467 luaZ_resetbuffer(ls->buff); /* previous call may dirty the buff. */
468 break;
469 }
470 }
471 /* else short comment */
472 while (!currIsNewline(ls) && ls->current != EOZ)
473 next(ls); /* skip until end of line (or end of file) */
474 break;
475 }
476 case '[': { /* long string or simply '[' */
477 size_t sep = skip_sep(ls);
478 if (sep >= 2) {
479 read_long_string(ls, seminfo, sep);
480 return TK_STRING;
481 }
482 else if (sep == 0) /* '[=...' missing second bracket? */
483 lexerror(ls, "invalid long string delimiter", TK_STRING);
484 return '[';
485 }
486 case '=': {
487 next(ls);
488 if (check_next1(ls, '=')) return TK_EQ; /* '==' */
489 else return '=';
490 }
491 case '<': {
492 next(ls);
493 if (check_next1(ls, '=')) return TK_LE; /* '<=' */
494 else if (check_next1(ls, '<')) return TK_SHL; /* '<<' */
495 else return '<';
496 }
497 case '>': {
498 next(ls);
499 if (check_next1(ls, '=')) return TK_GE; /* '>=' */
500 else if (check_next1(ls, '>')) return TK_SHR; /* '>>' */
501 else return '>';
502 }
503 case '/': {
504 next(ls);
505 if (check_next1(ls, '/')) return TK_IDIV; /* '//' */
506 else return '/';
507 }
508 case '~': {
509 next(ls);
510 if (check_next1(ls, '=')) return TK_NE; /* '~=' */
511 else return '~';
512 }
513 case ':': {
514 next(ls);
515 if (check_next1(ls, ':')) return TK_DBCOLON; /* '::' */
516 else return ':';
517 }
518 case '"': case '\'': { /* short literal strings */
519 read_string(ls, ls->current, seminfo);
520 return TK_STRING;
521 }
522 case '.': { /* '.', '..', '...', or number */
523 save_and_next(ls);
524 if (check_next1(ls, '.')) {
525 if (check_next1(ls, '.'))
526 return TK_DOTS; /* '...' */
527 else return TK_CONCAT; /* '..' */
528 }
529 else if (!lisdigit(ls->current)) return '.';
530 else return read_numeral(ls, seminfo);
531 }
532 case '0': case '1': case '2': case '3': case '4':
533 case '5': case '6': case '7': case '8': case '9': {
534 return read_numeral(ls, seminfo);
535 }
536 case EOZ: {
537 return TK_EOS;
538 }
539 default: {
540 if (lislalpha(ls->current)) { /* identifier or reserved word? */
541 TString *ts;
542 do {
543 save_and_next(ls);
544 } while (lislalnum(ls->current));
545 ts = luaX_newstring(ls, luaZ_buffer(ls->buff),
546 luaZ_bufflen(ls->buff));
547 seminfo->ts = ts;
548 if (isreserved(ts)) /* reserved word? */
549 return ts->extra - 1 + FIRST_RESERVED;
550 else {
551 return TK_NAME;
552 }
553 }
554 else { /* single-char tokens ('+', '*', '%', '{', '}', ...) */
555 int c = ls->current;
556 next(ls);
557 return c;
558 }
559 }
560 }
561 }
562}
#define NULL
Definition gmacros.h:924
#define FIRST_RESERVED
@ TK_DOTS
@ TK_NAME
#define luaZ_bufflen(buff)
#define luaZ_resetbuffer(buff)
#define luaZ_buffer(buff)
#define lislalpha(c)
#define lislalnum(c)
#define lisdigit(c)
@ TK_DBCOLON
#define isreserved(s)
@ TK_IDIV
TString * luaX_newstring(LexState *ls, const char *str, size_t l)
static void read_string(LexState *ls, int del, SemInfo *seminfo)
static int read_numeral(LexState *ls, SemInfo *seminfo)
static int check_next1(LexState *ls, int c)
static void read_long_string(LexState *ls, SemInfo *seminfo, size_t sep)
static size_t skip_sep(LexState *ls)
static void inclinenumber(LexState *ls)
#define TK_EQ
Definition sqlite3.c:13995
#define TK_GE
Definition sqlite3.c:13999
#define TK_LE
Definition sqlite3.c:13997
#define TK_CONCAT
Definition sqlite3.c:14052
#define TK_NE
Definition sqlite3.c:13994
Mbuffer * buff
TString * ts

References LexState::buff, check_next1(), LexState::current, currIsNewline, EOZ, TString::extra, FIRST_RESERVED, inclinenumber(), isreserved, lexerror(), lisdigit, lislalnum, lislalpha, luaX_newstring(), luaZ_buffer, luaZ_bufflen, luaZ_resetbuffer, next, NULL, read_long_string(), read_numeral(), read_string(), save_and_next, skip_sep(), TK_CONCAT, TK_DBCOLON, TK_DOTS, TK_EOS, TK_EQ, TK_GE, TK_IDIV, TK_LE, TK_NAME, TK_NE, TK_SHL, TK_SHR, TK_STRING, and SemInfo::ts.

Referenced by luaX_lookahead(), and luaX_next().

◆ luaX_init()

void luaX_init ( lua_State * L)

Definition at line 70 of file lua-5.4.3/src/llex.c.

70 {
71 int i;
72 TString *e = luaS_newliteral(L, LUA_ENV); /* create env name */
73 luaC_fix(L, obj2gco(e)); /* never collect this name */
74 for (i=0; i<NUM_RESERVED; i++) {
75 TString *ts = luaS_new(L, luaX_tokens[i]);
76 luaC_fix(L, obj2gco(ts)); /* reserved words are never collected */
77 ts->extra = cast_byte(i+1); /* reserved word */
78 }
79}
#define NUM_RESERVED
#define cast_byte(i)
#define obj2gco(v)
#define luaS_newliteral(L, s)
#define luaS_new(L, s)
#define LUA_ENV
void luaC_fix(lua_State *L, GCObject *o)
static const char *const luaX_tokens[]

References cast_byte, TString::extra, LUA_ENV, luaC_fix(), luaS_new, luaS_newliteral, luaX_tokens, NUM_RESERVED, and obj2gco.

◆ luaX_lookahead()

int luaX_lookahead ( LexState * ls)

Definition at line 576 of file lua-5.4.3/src/llex.c.

576 {
578 ls->lookahead.token = llex(ls, &ls->lookahead.seminfo);
579 return ls->lookahead.token;
580}
static int llex(LexState *ls, SemInfo *seminfo)
SemInfo seminfo

References llex(), LexState::lookahead, lua_assert, Token::seminfo, TK_EOS, and Token::token.

◆ luaX_newstring()

TString * luaX_newstring ( LexState * ls,
const char * str,
size_t l )

Definition at line 134 of file lua-5.4.3/src/llex.c.

134 {
135 lua_State *L = ls->L;
136 TString *ts = luaS_newlstr(L, str, l); /* create new string */
137 const TValue *o = luaH_getstr(ls->h, ts);
138 if (!ttisnil(o)) /* string already present? */
139 ts = keystrval(nodefromval(o)); /* get saved copy */
140 else { /* not in use yet */
141 TValue *stv = s2v(L->top++); /* reserve stack space for string */
142 setsvalue(L, stv, ts); /* temporarily anchor the string */
143 luaH_finishset(L, ls->h, stv, o, stv); /* t[string] = string */
144 /* table is not a metatable, so it does not need to invalidate cache */
145 luaC_checkGC(L);
146 L->top--; /* remove string from stack */
147 }
148 return ts;
149}
#define luaC_checkGC(L)
#define setsvalue(L, obj, x)
#define ttisnil(o)
TString * luaS_newlstr(lua_State *L, const char *str, size_t l)
const TValue * luaH_getstr(Table *t, TString *key)
#define s2v(o)
#define keystrval(node)
void luaH_finishset(lua_State *L, Table *t, const TValue *key, const TValue *slot, TValue *value)
#define nodefromval(v)

References LexState::h, keystrval, LexState::L, luaC_checkGC, luaH_finishset(), luaH_getstr(), luaS_newlstr(), nodefromval, s2v, setsvalue, lua_State::top, and ttisnil.

Referenced by llex(), read_long_string(), and read_string().

◆ luaX_next()

void luaX_next ( LexState * ls)

Definition at line 565 of file lua-5.4.3/src/llex.c.

565 {
566 ls->lastline = ls->linenumber;
567 if (ls->lookahead.token != TK_EOS) { /* is there a look-ahead token? */
568 ls->t = ls->lookahead; /* use this one */
569 ls->lookahead.token = TK_EOS; /* and discharge it */
570 }
571 else
572 ls->t.token = llex(ls, &ls->t.seminfo); /* read next token */
573}

References LexState::lastline, LexState::linenumber, llex(), LexState::lookahead, Token::seminfo, LexState::t, TK_EOS, and Token::token.

◆ luaX_setinput()

void luaX_setinput ( lua_State * L,
LexState * ls,
ZIO * z,
TString * source,
int firstchar )

Definition at line 167 of file lua-5.4.3/src/llex.c.

168 {
169 ls->t.token = 0;
170 ls->L = L;
171 ls->current = firstchar;
172 ls->lookahead.token = TK_EOS; /* no look-ahead token */
173 ls->z = z;
174 ls->fs = NULL;
175 ls->linenumber = 1;
176 ls->lastline = 1;
177 ls->source = source;
178 ls->envn = luaS_newliteral(L, LUA_ENV); /* get env name */
179 luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */
180}
#define LUA_MINBUFFER
#define luaZ_resizebuffer(L, buff, size)
struct FuncState * fs
TString * envn

References LexState::buff, LexState::current, LexState::envn, LexState::fs, LexState::L, LexState::lastline, LexState::linenumber, LexState::lookahead, LUA_ENV, LUA_MINBUFFER, luaS_newliteral, luaZ_resizebuffer, NULL, LexState::source, LexState::t, TK_EOS, Token::token, and LexState::z.

◆ luaX_syntaxerror()

l_noret luaX_syntaxerror ( LexState * ls,
const char * msg )

Definition at line 119 of file lua-5.4.3/src/llex.c.

119 {
120 lexerror(ls, msg, ls->t.token);
121}

References lexerror(), LexState::t, and Token::token.

◆ luaX_token2str()

const char * luaX_token2str ( LexState * ls,
int token )

Definition at line 82 of file lua-5.4.3/src/llex.c.

82 {
83 if (token < FIRST_RESERVED) { /* single-byte symbols? */
84 if (lisprint(token))
85 return luaO_pushfstring(ls->L, "'%c'", token);
86 else /* control character */
87 return luaO_pushfstring(ls->L, "'<\\%d>'", token);
88 }
89 else {
90 const char *s = luaX_tokens[token - FIRST_RESERVED];
91 if (token < TK_EOS) /* fixed format (symbols and reserved words)? */
92 return luaO_pushfstring(ls->L, "'%s'", s);
93 else /* names, strings, and numerals */
94 return s;
95 }
96}
#define lisprint(c)
CURL_EXTERN CURLMcode curl_socket_t s
Definition multi.h:318

References FIRST_RESERVED, LexState::L, lisprint, luaO_pushfstring(), luaX_tokens, s, and TK_EOS.

Referenced by txtToken().

◆ read_long_string()

static void read_long_string ( LexState * ls,
SemInfo * seminfo,
size_t sep )
static

Definition at line 280 of file lua-5.4.3/src/llex.c.

280 {
281 int line = ls->linenumber; /* initial line (for error message) */
282 save_and_next(ls); /* skip 2nd '[' */
283 if (currIsNewline(ls)) /* string starts with a newline? */
284 inclinenumber(ls); /* skip it */
285 for (;;) {
286 switch (ls->current) {
287 case EOZ: { /* error */
288 const char *what = (seminfo ? "string" : "comment");
289 const char *msg = luaO_pushfstring(ls->L,
290 "unfinished long %s (starting at line %d)", what, line);
291 lexerror(ls, msg, TK_EOS);
292 break; /* to avoid warnings */
293 }
294 case ']': {
295 if (skip_sep(ls) == sep) {
296 save_and_next(ls); /* skip 2nd ']' */
297 goto endloop;
298 }
299 break;
300 }
301 case '\n': case '\r': {
302 save(ls, '\n');
303 inclinenumber(ls);
304 if (!seminfo) luaZ_resetbuffer(ls->buff); /* avoid wasting space */
305 break;
306 }
307 default: {
308 if (seminfo) save_and_next(ls);
309 else next(ls);
310 }
311 }
312 } endloop:
313 if (seminfo)
314 seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + sep,
315 luaZ_bufflen(ls->buff) - 2 * sep);
316}
static void save(LexState *ls, int c)

References LexState::buff, LexState::current, currIsNewline, EOZ, inclinenumber(), LexState::L, lexerror(), LexState::linenumber, luaO_pushfstring(), luaX_newstring(), luaZ_buffer, luaZ_bufflen, luaZ_resetbuffer, next, save(), save_and_next, skip_sep(), TK_EOS, and SemInfo::ts.

Referenced by llex().

◆ read_numeral()

static int read_numeral ( LexState * ls,
SemInfo * seminfo )
static

Definition at line 227 of file lua-5.4.3/src/llex.c.

227 {
228 TValue obj;
229 const char *expo = "Ee";
230 int first = ls->current;
232 save_and_next(ls);
233 if (first == '0' && check_next2(ls, "xX")) /* hexadecimal? */
234 expo = "Pp";
235 for (;;) {
236 if (check_next2(ls, expo)) /* exponent mark? */
237 check_next2(ls, "-+"); /* optional exponent sign */
238 else if (lisxdigit(ls->current) || ls->current == '.') /* '%x|%.' */
239 save_and_next(ls);
240 else break;
241 }
242 if (lislalpha(ls->current)) /* is numeral touching a letter? */
243 save_and_next(ls); /* force an error */
244 save(ls, '\0');
245 if (luaO_str2num(luaZ_buffer(ls->buff), &obj) == 0) /* format error? */
246 lexerror(ls, "malformed number", TK_FLT);
247 if (ttisinteger(&obj)) {
248 seminfo->i = ivalue(&obj);
249 return TK_INT;
250 }
251 else {
252 lua_assert(ttisfloat(&obj));
253 seminfo->r = fltvalue(&obj);
254 return TK_FLT;
255 }
256}
size_t luaO_str2num(const char *s, TValue *o)
#define fltvalue(o)
#define ttisinteger(o)
#define ttisfloat(o)
#define ivalue(o)
static int check_next2(LexState *ls, const char *set)
lua_Number r
lua_Integer i

References LexState::buff, check_next2(), LexState::current, fltvalue, SemInfo::i, ivalue, lexerror(), lisdigit, lislalpha, lisxdigit, lua_assert, luaO_str2num(), luaZ_buffer, SemInfo::r, save(), save_and_next, TK_FLT, TK_INT, ttisfloat, and ttisinteger.

Referenced by llex().

◆ read_string()

static void read_string ( LexState * ls,
int del,
SemInfo * seminfo )
static

Definition at line 382 of file lua-5.4.3/src/llex.c.

382 {
383 save_and_next(ls); /* keep delimiter (for error messages) */
384 while (ls->current != del) {
385 switch (ls->current) {
386 case EOZ:
387 lexerror(ls, "unfinished string", TK_EOS);
388 break; /* to avoid warnings */
389 case '\n':
390 case '\r':
391 lexerror(ls, "unfinished string", TK_STRING);
392 break; /* to avoid warnings */
393 case '\\': { /* escape sequences */
394 int c; /* final character to be saved */
395 save_and_next(ls); /* keep '\\' for error messages */
396 switch (ls->current) {
397 case 'a': c = '\a'; goto read_save;
398 case 'b': c = '\b'; goto read_save;
399 case 'f': c = '\f'; goto read_save;
400 case 'n': c = '\n'; goto read_save;
401 case 'r': c = '\r'; goto read_save;
402 case 't': c = '\t'; goto read_save;
403 case 'v': c = '\v'; goto read_save;
404 case 'x': c = readhexaesc(ls); goto read_save;
405 case 'u': utf8esc(ls); goto no_save;
406 case '\n': case '\r':
407 inclinenumber(ls); c = '\n'; goto only_save;
408 case '\\': case '\"': case '\'':
409 c = ls->current; goto read_save;
410 case EOZ: goto no_save; /* will raise an error next loop */
411 case 'z': { /* zap following span of spaces */
412 luaZ_buffremove(ls->buff, 1); /* remove '\\' */
413 next(ls); /* skip the 'z' */
414 while (lisspace(ls->current)) {
415 if (currIsNewline(ls)) inclinenumber(ls);
416 else next(ls);
417 }
418 goto no_save;
419 }
420 default: {
421 esccheck(ls, lisdigit(ls->current), "invalid escape sequence");
422 c = readdecesc(ls); /* digital escape '\ddd' */
423 goto only_save;
424 }
425 }
426 read_save:
427 next(ls);
428 /* go through */
429 only_save:
430 luaZ_buffremove(ls->buff, 1); /* remove '\\' */
431 save(ls, c);
432 /* go through */
433 no_save: break;
434 }
435 default:
436 save_and_next(ls);
437 }
438 }
439 save_and_next(ls); /* skip delimiter */
440 seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1,
441 luaZ_bufflen(ls->buff) - 2);
442}
#define lisspace(c)
#define luaZ_buffremove(buff, i)
static int readhexaesc(LexState *ls)
static int readdecesc(LexState *ls)
static void utf8esc(LexState *ls)

References LexState::buff, LexState::current, currIsNewline, EOZ, esccheck(), inclinenumber(), lexerror(), lisdigit, lisspace, luaX_newstring(), luaZ_buffer, luaZ_bufflen, luaZ_buffremove, next, readdecesc(), readhexaesc(), save(), save_and_next, TK_EOS, TK_STRING, SemInfo::ts, and utf8esc().

Referenced by llex().

◆ readdecesc()

static int readdecesc ( LexState * ls)
static

Definition at line 369 of file lua-5.4.3/src/llex.c.

369 {
370 int i;
371 int r = 0; /* result accumulator */
372 for (i = 0; i < 3 && lisdigit(ls->current); i++) { /* read up to 3 digits */
373 r = 10*r + ls->current - '0';
374 save_and_next(ls);
375 }
376 esccheck(ls, r <= UCHAR_MAX, "decimal escape too large");
377 luaZ_buffremove(ls->buff, i); /* remove read digits from buffer */
378 return r;
379}

References LexState::buff, LexState::current, esccheck(), lisdigit, luaZ_buffremove, and save_and_next.

Referenced by read_string().

◆ readhexaesc()

static int readhexaesc ( LexState * ls)
static

Definition at line 335 of file lua-5.4.3/src/llex.c.

335 {
336 int r = gethexa(ls);
337 r = (r << 4) + gethexa(ls);
338 luaZ_buffremove(ls->buff, 2); /* remove saved chars from buffer */
339 return r;
340}
static int gethexa(LexState *ls)

References LexState::buff, gethexa(), and luaZ_buffremove.

Referenced by read_string().

◆ readutf8esc()

static unsigned long readutf8esc ( LexState * ls)
static

Definition at line 343 of file lua-5.4.3/src/llex.c.

343 {
344 unsigned long r;
345 int i = 4; /* chars to be removed: '\', 'u', '{', and first digit */
346 save_and_next(ls); /* skip 'u' */
347 esccheck(ls, ls->current == '{', "missing '{'");
348 r = gethexa(ls); /* must have at least one digit */
349 while (cast_void(save_and_next(ls)), lisxdigit(ls->current)) {
350 i++;
351 esccheck(ls, r <= (0x7FFFFFFFu >> 4), "UTF-8 value too large");
352 r = (r << 4) + luaO_hexavalue(ls->current);
353 }
354 esccheck(ls, ls->current == '}', "missing '}'");
355 next(ls); /* skip '}' */
356 luaZ_buffremove(ls->buff, i); /* remove saved chars from buffer */
357 return r;
358}
#define cast_void(i)

References LexState::buff, cast_void, LexState::current, esccheck(), gethexa(), lisxdigit, luaO_hexavalue(), luaZ_buffremove, next, and save_and_next.

Referenced by utf8esc().

◆ save()

static void save ( LexState * ls,
int c )
static

Definition at line 57 of file lua-5.4.3/src/llex.c.

57 {
58 Mbuffer *b = ls->buff;
59 if (luaZ_bufflen(b) + 1 > luaZ_sizebuffer(b)) {
60 size_t newsize;
61 if (luaZ_sizebuffer(b) >= MAX_SIZE/2)
62 lexerror(ls, "lexical element too long", 0);
63 newsize = luaZ_sizebuffer(b) * 2;
64 luaZ_resizebuffer(ls->L, b, newsize);
65 }
66 b->buffer[luaZ_bufflen(b)++] = cast_char(c);
67}
#define luaZ_sizebuffer(buff)
#define MAX_SIZE
#define cast_char(i)

References LexState::buff, Mbuffer::buffer, cast_char, LexState::L, lexerror(), luaZ_bufflen, luaZ_resizebuffer, luaZ_sizebuffer, and MAX_SIZE.

Referenced by read_long_string(), read_numeral(), read_string(), txtToken(), and utf8esc().

◆ skip_sep()

static size_t skip_sep ( LexState * ls)
static

Definition at line 265 of file lua-5.4.3/src/llex.c.

265 {
266 size_t count = 0;
267 int s = ls->current;
268 lua_assert(s == '[' || s == ']');
269 save_and_next(ls);
270 while (ls->current == '=') {
271 save_and_next(ls);
272 count++;
273 }
274 return (ls->current == s) ? count + 2
275 : (count == 0) ? 1
276 : 0;
277}

References LexState::current, lua_assert, s, and save_and_next.

Referenced by llex(), and read_long_string().

◆ txtToken()

static const char * txtToken ( LexState * ls,
int token )
static

Definition at line 99 of file lua-5.4.3/src/llex.c.

99 {
100 switch (token) {
101 case TK_NAME: case TK_STRING:
102 case TK_FLT: case TK_INT:
103 save(ls, '\0');
104 return luaO_pushfstring(ls->L, "'%s'", luaZ_buffer(ls->buff));
105 default:
106 return luaX_token2str(ls, token);
107 }
108}
const char * luaX_token2str(LexState *ls, int token)

References LexState::buff, LexState::L, luaO_pushfstring(), luaX_token2str(), luaZ_buffer, save(), TK_FLT, TK_INT, TK_NAME, and TK_STRING.

Referenced by lexerror().

◆ utf8esc()

static void utf8esc ( LexState * ls)
static

Definition at line 361 of file lua-5.4.3/src/llex.c.

361 {
362 char buff[UTF8BUFFSZ];
363 int n = luaO_utf8esc(buff, readutf8esc(ls));
364 for (; n > 0; n--) /* add 'buff' to string */
365 save(ls, buff[UTF8BUFFSZ - n]);
366}
int luaO_utf8esc(char *buff, unsigned long x)
#define UTF8BUFFSZ
static unsigned long readutf8esc(LexState *ls)

References luaO_utf8esc(), readutf8esc(), save(), and UTF8BUFFSZ.

Referenced by read_string().

Variable Documentation

◆ luaX_tokens

const char* const luaX_tokens[]
static
Initial value:
= {
"and", "break", "do", "else", "elseif",
"end", "false", "for", "function", "goto", "if",
"in", "local", "nil", "not", "or", "repeat",
"return", "then", "true", "until", "while",
"//", "..", "...", "==", ">=", "<=", "~=",
"<<", ">>", "::", "<eof>",
"<number>", "<integer>", "<name>", "<string>"
}

Definition at line 40 of file lua-5.4.3/src/llex.c.

40 {
41 "and", "break", "do", "else", "elseif",
42 "end", "false", "for", "function", "goto", "if",
43 "in", "local", "nil", "not", "or", "repeat",
44 "return", "then", "true", "until", "while",
45 "//", "..", "...", "==", ">=", "<=", "~=",
46 "<<", ">>", "::", "<eof>",
47 "<number>", "<integer>", "<name>", "<string>"
48};

Referenced by luaX_init(), and luaX_token2str().