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.3.6/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.3.6/src/llex.c.

◆ LUA_CORE

#define LUA_CORE

Definition at line 8 of file lua-5.3.6/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 186 of file lua-5.3.6/src/llex.c.

186 {
187 if (ls->current == c) {
188 next(ls);
189 return 1;
190 }
191 else return 0;
192}
#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 199 of file lua-5.3.6/src/llex.c.

199 {
200 lua_assert(set[2] == '\0');
201 if (ls->current == set[0] || ls->current == set[1]) {
202 save_and_next(ls);
203 return 1;
204 }
205 else return 0;
206}
#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 306 of file lua-5.3.6/src/llex.c.

306 {
307 if (!c) {
308 if (ls->current != EOZ)
309 save_and_next(ls); /* add current to buffer for error message */
310 lexerror(ls, msg, TK_STRING);
311 }
312}
#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 315 of file lua-5.3.6/src/llex.c.

315 {
316 save_and_next(ls);
317 esccheck (ls, lisxdigit(ls->current), "hexadecimal digit expected");
318 return luaO_hexavalue(ls->current);
319}
#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 151 of file lua-5.3.6/src/llex.c.

151 {
152 int old = ls->current;
154 next(ls); /* skip '\n' or '\r' */
155 if (currIsNewline(ls) && ls->current != old)
156 next(ls); /* skip '\n\r' or '\r\n' */
157 if (++ls->linenumber >= MAX_INT)
158 lexerror(ls, "chunk has too many lines", 0);
159}
#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 109 of file lua-5.3.6/src/llex.c.

109 {
110 msg = luaG_addinfo(ls->L, msg, ls->source, ls->linenumber);
111 if (token)
112 luaO_pushfstring(ls->L, "%s near %s", msg, txtToken(ls, token));
114}
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 432 of file lua-5.3.6/src/llex.c.

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

563 {
565 ls->lookahead.token = llex(ls, &ls->lookahead.seminfo);
566 return ls->lookahead.token;
567}
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 127 of file lua-5.3.6/src/llex.c.

127 {
128 lua_State *L = ls->L;
129 TValue *o; /* entry for 'str' */
130 TString *ts = luaS_newlstr(L, str, l); /* create new string */
131 setsvalue2s(L, L->top++, ts); /* temporarily anchor it in stack */
132 o = luaH_set(L, ls->h, L->top - 1);
133 if (ttisnil(o)) { /* not in use yet? */
134 /* boolean value does not need GC barrier;
135 table has no metatable, so it does not need to invalidate cache */
136 setbvalue(o, 1); /* t[string] = true */
137 luaC_checkGC(L);
138 }
139 else { /* string already present */
140 ts = tsvalue(keyfromval(o)); /* re-use value previously stored */
141 }
142 L->top--; /* remove string from stack */
143 return ts;
144}
#define luaC_checkGC(L)
#define setbvalue(obj, x)
#define setsvalue2s
#define ttisnil(o)
#define tsvalue(o)
TString * luaS_newlstr(lua_State *L, const char *str, size_t l)
TValue * luaH_set(lua_State *L, Table *t, const TValue *key)
#define keyfromval(v)

References LexState::h, keyfromval, LexState::L, luaC_checkGC, luaH_set(), luaS_newlstr(), setbvalue, setsvalue2s, lua_State::top, tsvalue, and ttisnil.

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

◆ luaX_next()

void luaX_next ( LexState * ls)

Definition at line 552 of file lua-5.3.6/src/llex.c.

552 {
553 ls->lastline = ls->linenumber;
554 if (ls->lookahead.token != TK_EOS) { /* is there a look-ahead token? */
555 ls->t = ls->lookahead; /* use this one */
556 ls->lookahead.token = TK_EOS; /* and discharge it */
557 }
558 else
559 ls->t.token = llex(ls, &ls->t.seminfo); /* read next token */
560}

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 162 of file lua-5.3.6/src/llex.c.

163 {
164 ls->t.token = 0;
165 ls->L = L;
166 ls->current = firstchar;
167 ls->lookahead.token = TK_EOS; /* no look-ahead token */
168 ls->z = z;
169 ls->fs = NULL;
170 ls->linenumber = 1;
171 ls->lastline = 1;
172 ls->source = source;
173 ls->envn = luaS_newliteral(L, LUA_ENV); /* get env name */
174 luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */
175}
#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 117 of file lua-5.3.6/src/llex.c.

117 {
118 lexerror(ls, msg, ls->t.token);
119}

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.3.6/src/llex.c.

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

References cast_uchar, FIRST_RESERVED, LexState::L, lua_assert, 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 267 of file lua-5.3.6/src/llex.c.

267 {
268 int line = ls->linenumber; /* initial line (for error message) */
269 save_and_next(ls); /* skip 2nd '[' */
270 if (currIsNewline(ls)) /* string starts with a newline? */
271 inclinenumber(ls); /* skip it */
272 for (;;) {
273 switch (ls->current) {
274 case EOZ: { /* error */
275 const char *what = (seminfo ? "string" : "comment");
276 const char *msg = luaO_pushfstring(ls->L,
277 "unfinished long %s (starting at line %d)", what, line);
278 lexerror(ls, msg, TK_EOS);
279 break; /* to avoid warnings */
280 }
281 case ']': {
282 if (skip_sep(ls) == sep) {
283 save_and_next(ls); /* skip 2nd ']' */
284 goto endloop;
285 }
286 break;
287 }
288 case '\n': case '\r': {
289 save(ls, '\n');
290 inclinenumber(ls);
291 if (!seminfo) luaZ_resetbuffer(ls->buff); /* avoid wasting space */
292 break;
293 }
294 default: {
295 if (seminfo) save_and_next(ls);
296 else next(ls);
297 }
298 }
299 } endloop:
300 if (seminfo)
301 seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + sep,
302 luaZ_bufflen(ls->buff) - 2 * sep);
303}
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 214 of file lua-5.3.6/src/llex.c.

214 {
215 TValue obj;
216 const char *expo = "Ee";
217 int first = ls->current;
219 save_and_next(ls);
220 if (first == '0' && check_next2(ls, "xX")) /* hexadecimal? */
221 expo = "Pp";
222 for (;;) {
223 if (check_next2(ls, expo)) /* exponent part? */
224 check_next2(ls, "-+"); /* optional exponent sign */
225 if (lisxdigit(ls->current))
226 save_and_next(ls);
227 else if (ls->current == '.')
228 save_and_next(ls);
229 else break;
230 }
231 save(ls, '\0');
232 if (luaO_str2num(luaZ_buffer(ls->buff), &obj) == 0) /* format error? */
233 lexerror(ls, "malformed number", TK_FLT);
234 if (ttisinteger(&obj)) {
235 seminfo->i = ivalue(&obj);
236 return TK_INT;
237 }
238 else {
239 lua_assert(ttisfloat(&obj));
240 seminfo->r = fltvalue(&obj);
241 return TK_FLT;
242 }
243}
static int check_next2(LexState *ls, const char *set)
size_t luaO_str2num(const char *s, TValue *o)
#define fltvalue(o)
#define ttisinteger(o)
#define ttisfloat(o)
#define ivalue(o)
lua_Number r
lua_Integer i

References LexState::buff, check_next2(), LexState::current, fltvalue, SemInfo::i, ivalue, lexerror(), lisdigit, 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 369 of file lua-5.3.6/src/llex.c.

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

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 356 of file lua-5.3.6/src/llex.c.

356 {
357 int i;
358 int r = 0; /* result accumulator */
359 for (i = 0; i < 3 && lisdigit(ls->current); i++) { /* read up to 3 digits */
360 r = 10*r + ls->current - '0';
361 save_and_next(ls);
362 }
363 esccheck(ls, r <= UCHAR_MAX, "decimal escape too large");
364 luaZ_buffremove(ls->buff, i); /* remove read digits from buffer */
365 return r;
366}

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 322 of file lua-5.3.6/src/llex.c.

322 {
323 int r = gethexa(ls);
324 r = (r << 4) + gethexa(ls);
325 luaZ_buffremove(ls->buff, 2); /* remove saved chars from buffer */
326 return r;
327}
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 330 of file lua-5.3.6/src/llex.c.

330 {
331 unsigned long r;
332 int i = 4; /* chars to be removed: '\', 'u', '{', and first digit */
333 save_and_next(ls); /* skip 'u' */
334 esccheck(ls, ls->current == '{', "missing '{'");
335 r = gethexa(ls); /* must have at least one digit */
336 while ((save_and_next(ls), lisxdigit(ls->current))) {
337 i++;
338 r = (r << 4) + luaO_hexavalue(ls->current);
339 esccheck(ls, r <= 0x10FFFF, "UTF-8 value too large");
340 }
341 esccheck(ls, ls->current == '}', "missing '}'");
342 next(ls); /* skip '}' */
343 luaZ_buffremove(ls->buff, i); /* remove saved chars from buffer */
344 return r;
345}

References LexState::buff, 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.3.6/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 cast(t, exp)
#define luaZ_sizebuffer(buff)
#define MAX_SIZE

References LexState::buff, Mbuffer::buffer, cast, 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 251 of file lua-5.3.6/src/llex.c.

251 {
252 size_t count = 0;
253 int s = ls->current;
254 lua_assert(s == '[' || s == ']');
255 save_and_next(ls);
256 while (ls->current == '=') {
257 save_and_next(ls);
258 count++;
259 }
260 return (ls->current == s) ? count + 2
261 : (count == 0) ? 1
262 : 0;
263
264}

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 97 of file lua-5.3.6/src/llex.c.

97 {
98 switch (token) {
99 case TK_NAME: case TK_STRING:
100 case TK_FLT: case TK_INT:
101 save(ls, '\0');
102 return luaO_pushfstring(ls->L, "'%s'", luaZ_buffer(ls->buff));
103 default:
104 return luaX_token2str(ls, token);
105 }
106}
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 348 of file lua-5.3.6/src/llex.c.

348 {
349 char buff[UTF8BUFFSZ];
350 int n = luaO_utf8esc(buff, readutf8esc(ls));
351 for (; n > 0; n--) /* add 'buff' to string */
352 save(ls, buff[UTF8BUFFSZ - n]);
353}
static unsigned long readutf8esc(LexState *ls)
int luaO_utf8esc(char *buff, unsigned long x)
#define UTF8BUFFSZ

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.3.6/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().