Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
llex.c File Reference
#include <locale.h>
#include <string.h>
#include "lua.h"
#include "lctype.h"
#include "ldo.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))
 
#define getlocaledecpoint()   (localeconv()->decimal_point[0])
 
#define buff2d(b, e)   luaO_str2d(luaZ_buffer(b), luaZ_bufflen(b) - 1, e)
 

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_next (LexState *ls, const char *set)
 
static void buffreplace (LexState *ls, char from, char to)
 
static void trydecpoint (LexState *ls, SemInfo *seminfo)
 
static void read_numeral (LexState *ls, SemInfo *seminfo)
 
static int skip_sep (LexState *ls)
 
static void read_long_string (LexState *ls, SemInfo *seminfo, int sep)
 
static void escerror (LexState *ls, int *c, int n, const char *msg)
 
static int readhexaesc (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

◆ buff2d

#define buff2d ( b,
e )   luaO_str2d(luaZ_buffer(b), luaZ_bufflen(b) - 1, e)

Definition at line 209 of file lua-5.2.4/src/llex.c.

Referenced by read_numeral(), and trydecpoint().

◆ currIsNewline

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

Definition at line 32 of file lua-5.2.4/src/llex.c.

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

◆ getlocaledecpoint

#define getlocaledecpoint ( )    (localeconv()->decimal_point[0])

Definition at line 205 of file lua-5.2.4/src/llex.c.

Referenced by trydecpoint().

◆ llex_c

#define llex_c

Definition at line 11 of file lua-5.2.4/src/llex.c.

◆ LUA_CORE

#define LUA_CORE

Definition at line 12 of file lua-5.2.4/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

◆ buffreplace()

static void buffreplace ( LexState * ls,
char from,
char to )
static

Definition at line 196 of file lua-5.2.4/src/llex.c.

196 {
197 size_t n = luaZ_bufflen(ls->buff);
198 char *p = luaZ_buffer(ls->buff);
199 while (n--)
200 if (p[n] == from) p[n] = to;
201}
#define luaZ_bufflen(buff)
#define luaZ_buffer(buff)
Mbuffer * buff

References LexState::buff, luaZ_buffer, and luaZ_bufflen.

Referenced by read_numeral(), and trydecpoint().

◆ check_next()

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

Definition at line 185 of file lua-5.2.4/src/llex.c.

185 {
186 if (ls->current == '\0' || !strchr(set, ls->current))
187 return 0;
188 save_and_next(ls);
189 return 1;
190}
#define save_and_next(ls)

References LexState::current, and save_and_next.

Referenced by llex(), and read_numeral().

◆ escerror()

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

Definition at line 305 of file lua-5.2.4/src/llex.c.

305 {
306 int i;
307 luaZ_resetbuffer(ls->buff); /* prepare error message */
308 save(ls, '\\');
309 for (i = 0; i < n && c[i] != EOZ; i++)
310 save(ls, c[i]);
311 lexerror(ls, msg, TK_STRING);
312}
#define luaZ_resetbuffer(buff)
#define EOZ
static void save(LexState *ls, int c)
static l_noret lexerror(LexState *ls, const char *msg, int token)
#define TK_STRING
Definition sqlite3.c:14057

References LexState::buff, EOZ, lexerror(), luaZ_resetbuffer, save(), and TK_STRING.

Referenced by read_string(), readdecesc(), and readhexaesc().

◆ inclinenumber()

static void inclinenumber ( LexState * ls)
static

Definition at line 148 of file lua-5.2.4/src/llex.c.

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

104 {
105 char buff[LUA_IDSIZE];
107 msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg);
108 if (token)
109 luaO_pushfstring(ls->L, "%s near %s", msg, txtToken(ls, token));
111}
void luaD_throw(lua_State *L, int errcode)
void luaO_chunkid(char *out, const char *source, size_t bufflen)
const char * luaO_pushfstring(lua_State *L, const char *fmt,...)
#define getstr(ts)
#define LUA_ERRSYNTAX
#define LUA_IDSIZE
static const char * txtToken(LexState *ls, int token)
struct lua_State * L
TString * source

References getstr, LexState::L, LexState::linenumber, LUA_ERRSYNTAX, LUA_IDSIZE, luaD_throw(), luaO_chunkid(), luaO_pushfstring(), LexState::source, and txtToken().

Referenced by escerror(), inclinenumber(), llex(), luaX_syntaxerror(), read_long_string(), read_string(), save(), and trydecpoint().

◆ llex()

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

Definition at line 401 of file lua-5.2.4/src/llex.c.

401 {
403 for (;;) {
404 switch (ls->current) {
405 case '\n': case '\r': { /* line breaks */
406 inclinenumber(ls);
407 break;
408 }
409 case ' ': case '\f': case '\t': case '\v': { /* spaces */
410 next(ls);
411 break;
412 }
413 case '-': { /* '-' or '--' (comment) */
414 next(ls);
415 if (ls->current != '-') return '-';
416 /* else is a comment */
417 next(ls);
418 if (ls->current == '[') { /* long comment? */
419 int sep = skip_sep(ls);
420 luaZ_resetbuffer(ls->buff); /* `skip_sep' may dirty the buffer */
421 if (sep >= 0) {
422 read_long_string(ls, NULL, sep); /* skip long comment */
423 luaZ_resetbuffer(ls->buff); /* previous call may dirty the buff. */
424 break;
425 }
426 }
427 /* else short comment */
428 while (!currIsNewline(ls) && ls->current != EOZ)
429 next(ls); /* skip until end of line (or end of file) */
430 break;
431 }
432 case '[': { /* long string or simply '[' */
433 int sep = skip_sep(ls);
434 if (sep >= 0) {
435 read_long_string(ls, seminfo, sep);
436 return TK_STRING;
437 }
438 else if (sep == -1) return '[';
439 else lexerror(ls, "invalid long string delimiter", TK_STRING);
440 }
441 case '=': {
442 next(ls);
443 if (ls->current != '=') return '=';
444 else { next(ls); return TK_EQ; }
445 }
446 case '<': {
447 next(ls);
448 if (ls->current != '=') return '<';
449 else { next(ls); return TK_LE; }
450 }
451 case '>': {
452 next(ls);
453 if (ls->current != '=') return '>';
454 else { next(ls); return TK_GE; }
455 }
456 case '~': {
457 next(ls);
458 if (ls->current != '=') return '~';
459 else { next(ls); return TK_NE; }
460 }
461 case ':': {
462 next(ls);
463 if (ls->current != ':') return ':';
464 else { next(ls); return TK_DBCOLON; }
465 }
466 case '"': case '\'': { /* short literal strings */
467 read_string(ls, ls->current, seminfo);
468 return TK_STRING;
469 }
470 case '.': { /* '.', '..', '...', or number */
471 save_and_next(ls);
472 if (check_next(ls, ".")) {
473 if (check_next(ls, "."))
474 return TK_DOTS; /* '...' */
475 else return TK_CONCAT; /* '..' */
476 }
477 else if (!lisdigit(ls->current)) return '.';
478 /* else go through */
479 }
480 case '0': case '1': case '2': case '3': case '4':
481 case '5': case '6': case '7': case '8': case '9': {
482 read_numeral(ls, seminfo);
483 return TK_NUMBER;
484 }
485 case EOZ: {
486 return TK_EOS;
487 }
488 default: {
489 if (lislalpha(ls->current)) { /* identifier or reserved word? */
490 TString *ts;
491 do {
492 save_and_next(ls);
493 } while (lislalnum(ls->current));
494 ts = luaX_newstring(ls, luaZ_buffer(ls->buff),
495 luaZ_bufflen(ls->buff));
496 seminfo->ts = ts;
497 if (isreserved(ts)) /* reserved word? */
498 return ts->tsv.extra - 1 + FIRST_RESERVED;
499 else {
500 return TK_NAME;
501 }
502 }
503 else { /* single-char tokens (+ - / ...) */
504 int c = ls->current;
505 next(ls);
506 return c;
507 }
508 }
509 }
510 }
511}
#define NULL
Definition gmacros.h:924
#define FIRST_RESERVED
@ TK_NUMBER
@ TK_DOTS
@ TK_NAME
#define lislalpha(c)
#define lislalnum(c)
#define lisdigit(c)
static void read_numeral(LexState *ls, SemInfo *seminfo)
static void read_long_string(LexState *ls, SemInfo *seminfo, int sep)
TString * luaX_newstring(LexState *ls, const char *str, size_t l)
static void read_string(LexState *ls, int del, SemInfo *seminfo)
static int check_next(LexState *ls, const char *set)
static void inclinenumber(LexState *ls)
static int skip_sep(LexState *ls)
@ TK_DBCOLON
#define isreserved(s)
#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
TString * ts
struct TString::@46 tsv

References LexState::buff, check_next(), 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_LE, TK_NAME, TK_NE, TK_NUMBER, TK_STRING, SemInfo::ts, and TString::tsv.

Referenced by luaX_lookahead(), and luaX_next().

◆ luaX_init()

void luaX_init ( lua_State * L)

Definition at line 65 of file lua-5.2.4/src/llex.c.

65 {
66 int i;
67 for (i=0; i<NUM_RESERVED; i++) {
68 TString *ts = luaS_new(L, luaX_tokens[i]);
69 luaS_fix(ts); /* reserved words are never collected */
70 ts->tsv.extra = cast_byte(i+1); /* reserved word */
71 }
72}
#define NUM_RESERVED
#define cast_byte(i)
#define luaS_new(L, s)
#define luaS_fix(s)
static const char *const luaX_tokens[]

References cast_byte, TString::extra, luaS_fix, luaS_new, luaX_tokens, NUM_RESERVED, and TString::tsv.

◆ luaX_lookahead()

int luaX_lookahead ( LexState * ls)

Definition at line 525 of file lua-5.2.4/src/llex.c.

525 {
527 ls->lookahead.token = llex(ls, &ls->lookahead.seminfo);
528 return ls->lookahead.token;
529}
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 124 of file lua-5.2.4/src/llex.c.

124 {
125 lua_State *L = ls->L;
126 TValue *o; /* entry for `str' */
127 TString *ts = luaS_newlstr(L, str, l); /* create new string */
128 setsvalue2s(L, L->top++, ts); /* temporarily anchor it in stack */
129 o = luaH_set(L, ls->fs->h, L->top - 1);
130 if (ttisnil(o)) { /* not in use yet? (see 'addK') */
131 /* boolean value does not need GC barrier;
132 table has no metatable, so it does not need to invalidate cache */
133 setbvalue(o, 1); /* t[string] = true */
134 luaC_checkGC(L);
135 }
136 else { /* string already present */
137 ts = rawtsvalue(keyfromval(o)); /* re-use value previously stored */
138 }
139 L->top--; /* remove string from stack */
140 return ts;
141}
#define luaC_checkGC(L)
#define setbvalue(obj, x)
#define setsvalue2s
#define ttisnil(o)
#define rawtsvalue(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)
struct FuncState * fs

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

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

◆ luaX_next()

void luaX_next ( LexState * ls)

Definition at line 514 of file lua-5.2.4/src/llex.c.

514 {
515 ls->lastline = ls->linenumber;
516 if (ls->lookahead.token != TK_EOS) { /* is there a look-ahead token? */
517 ls->t = ls->lookahead; /* use this one */
518 ls->lookahead.token = TK_EOS; /* and discharge it */
519 }
520 else
521 ls->t.token = llex(ls, &ls->t.seminfo); /* read next token */
522}

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

160 {
161 ls->decpoint = '.';
162 ls->L = L;
163 ls->current = firstchar;
164 ls->lookahead.token = TK_EOS; /* no look-ahead token */
165 ls->z = z;
166 ls->fs = NULL;
167 ls->linenumber = 1;
168 ls->lastline = 1;
169 ls->source = source;
170 ls->envn = luaS_new(L, LUA_ENV); /* create env name */
171 luaS_fix(ls->envn); /* never collect this name */
172 luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */
173}
#define LUA_MINBUFFER
#define luaZ_resizebuffer(L, buff, size)
#define LUA_ENV
TString * envn

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

◆ luaX_syntaxerror()

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

Definition at line 114 of file lua-5.2.4/src/llex.c.

114 {
115 lexerror(ls, msg, ls->t.token);
116}

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

◆ luaX_token2str()

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

Definition at line 75 of file lua-5.2.4/src/llex.c.

75 {
76 if (token < FIRST_RESERVED) { /* single-byte symbols? */
77 lua_assert(token == cast(unsigned char, token));
78 return (lisprint(token)) ? luaO_pushfstring(ls->L, LUA_QL("%c"), token) :
79 luaO_pushfstring(ls->L, "char(%d)", token);
80 }
81 else {
82 const char *s = luaX_tokens[token - FIRST_RESERVED];
83 if (token < TK_EOS) /* fixed format (symbols and reserved words)? */
84 return luaO_pushfstring(ls->L, LUA_QS, s);
85 else /* names, strings, and numerals */
86 return s;
87 }
88}
#define cast(t, exp)
#define LUA_QS
#define LUA_QL(x)
#define lisprint(c)
CURL_EXTERN CURLMcode curl_socket_t s
Definition multi.h:318

References cast, FIRST_RESERVED, LexState::L, lisprint, lua_assert, LUA_QL, LUA_QS, luaO_pushfstring(), luaX_tokens, s, and TK_EOS.

Referenced by txtToken().

◆ read_long_string()

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

Definition at line 270 of file lua-5.2.4/src/llex.c.

270 {
271 save_and_next(ls); /* skip 2nd `[' */
272 if (currIsNewline(ls)) /* string starts with a newline? */
273 inclinenumber(ls); /* skip it */
274 for (;;) {
275 switch (ls->current) {
276 case EOZ:
277 lexerror(ls, (seminfo) ? "unfinished long string" :
278 "unfinished long comment", TK_EOS);
279 break; /* to avoid warnings */
280 case ']': {
281 if (skip_sep(ls) == sep) {
282 save_and_next(ls); /* skip 2nd `]' */
283 goto endloop;
284 }
285 break;
286 }
287 case '\n': case '\r': {
288 save(ls, '\n');
289 inclinenumber(ls);
290 if (!seminfo) luaZ_resetbuffer(ls->buff); /* avoid wasting space */
291 break;
292 }
293 default: {
294 if (seminfo) save_and_next(ls);
295 else next(ls);
296 }
297 }
298 } endloop:
299 if (seminfo)
300 seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + sep),
301 luaZ_bufflen(ls->buff) - 2*(2 + sep));
302}

References LexState::buff, LexState::current, currIsNewline, EOZ, inclinenumber(), lexerror(), 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 void read_numeral ( LexState * ls,
SemInfo * seminfo )
static

Definition at line 232 of file lua-5.2.4/src/llex.c.

232 {
233 const char *expo = "Ee";
234 int first = ls->current;
236 save_and_next(ls);
237 if (first == '0' && check_next(ls, "Xx")) /* hexadecimal? */
238 expo = "Pp";
239 for (;;) {
240 if (check_next(ls, expo)) /* exponent part? */
241 check_next(ls, "+-"); /* optional exponent sign */
242 if (lisxdigit(ls->current) || ls->current == '.')
243 save_and_next(ls);
244 else break;
245 }
246 save(ls, '\0');
247 buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */
248 if (!buff2d(ls->buff, &seminfo->r)) /* format error? */
249 trydecpoint(ls, seminfo); /* try to update decimal point separator */
250}
#define lisxdigit(c)
static void trydecpoint(LexState *ls, SemInfo *seminfo)
#define buff2d(b, e)
static void buffreplace(LexState *ls, char from, char to)
lua_Number r

References LexState::buff, buff2d, buffreplace(), check_next(), LexState::current, LexState::decpoint, lisdigit, lisxdigit, lua_assert, SemInfo::r, save(), save_and_next, and trydecpoint().

Referenced by llex().

◆ read_string()

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

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

343 {
344 save_and_next(ls); /* keep delimiter (for error messages) */
345 while (ls->current != del) {
346 switch (ls->current) {
347 case EOZ:
348 lexerror(ls, "unfinished string", TK_EOS);
349 break; /* to avoid warnings */
350 case '\n':
351 case '\r':
352 lexerror(ls, "unfinished string", TK_STRING);
353 break; /* to avoid warnings */
354 case '\\': { /* escape sequences */
355 int c; /* final character to be saved */
356 next(ls); /* do not save the `\' */
357 switch (ls->current) {
358 case 'a': c = '\a'; goto read_save;
359 case 'b': c = '\b'; goto read_save;
360 case 'f': c = '\f'; goto read_save;
361 case 'n': c = '\n'; goto read_save;
362 case 'r': c = '\r'; goto read_save;
363 case 't': c = '\t'; goto read_save;
364 case 'v': c = '\v'; goto read_save;
365 case 'x': c = readhexaesc(ls); goto read_save;
366 case '\n': case '\r':
367 inclinenumber(ls); c = '\n'; goto only_save;
368 case '\\': case '\"': case '\'':
369 c = ls->current; goto read_save;
370 case EOZ: goto no_save; /* will raise an error next loop */
371 case 'z': { /* zap following span of spaces */
372 next(ls); /* skip the 'z' */
373 while (lisspace(ls->current)) {
374 if (currIsNewline(ls)) inclinenumber(ls);
375 else next(ls);
376 }
377 goto no_save;
378 }
379 default: {
380 if (!lisdigit(ls->current))
381 escerror(ls, &ls->current, 1, "invalid escape sequence");
382 /* digital escape \ddd */
383 c = readdecesc(ls);
384 goto only_save;
385 }
386 }
387 read_save: next(ls); /* read next character */
388 only_save: save(ls, c); /* save 'c' */
389 no_save: break;
390 }
391 default:
392 save_and_next(ls);
393 }
394 }
395 save_and_next(ls); /* skip delimiter */
396 seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1,
397 luaZ_bufflen(ls->buff) - 2);
398}
#define lisspace(c)
static void escerror(LexState *ls, int *c, int n, const char *msg)
static int readhexaesc(LexState *ls)
static int readdecesc(LexState *ls)

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

Referenced by llex().

◆ readdecesc()

static int readdecesc ( LexState * ls)
static

Definition at line 329 of file lua-5.2.4/src/llex.c.

329 {
330 int c[3], i;
331 int r = 0; /* result accumulator */
332 for (i = 0; i < 3 && lisdigit(ls->current); i++) { /* read up to 3 digits */
333 c[i] = ls->current;
334 r = 10*r + c[i] - '0';
335 next(ls);
336 }
337 if (r > UCHAR_MAX)
338 escerror(ls, c, i, "decimal escape too large");
339 return r;
340}

References LexState::current, escerror(), lisdigit, and next.

Referenced by read_string().

◆ readhexaesc()

static int readhexaesc ( LexState * ls)
static

Definition at line 315 of file lua-5.2.4/src/llex.c.

315 {
316 int c[3], i; /* keep input for error message */
317 int r = 0; /* result accumulator */
318 c[0] = 'x'; /* for error message */
319 for (i = 1; i < 3; i++) { /* read two hexadecimal digits */
320 c[i] = next(ls);
321 if (!lisxdigit(c[i]))
322 escerror(ls, c, i + 1, "hexadecimal digit expected");
323 r = (r << 4) + luaO_hexavalue(c[i]);
324 }
325 return r;
326}
int luaO_hexavalue(int c)

References escerror(), lisxdigit, luaO_hexavalue(), and next.

Referenced by read_string().

◆ save()

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

Definition at line 52 of file lua-5.2.4/src/llex.c.

52 {
53 Mbuffer *b = ls->buff;
54 if (luaZ_bufflen(b) + 1 > luaZ_sizebuffer(b)) {
55 size_t newsize;
56 if (luaZ_sizebuffer(b) >= MAX_SIZET/2)
57 lexerror(ls, "lexical element too long", 0);
58 newsize = luaZ_sizebuffer(b) * 2;
59 luaZ_resizebuffer(ls->L, b, newsize);
60 }
61 b->buffer[luaZ_bufflen(b)++] = cast(char, c);
62}
#define MAX_SIZET
#define luaZ_sizebuffer(buff)

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

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

◆ skip_sep()

static int skip_sep ( LexState * ls)
static

Definition at line 257 of file lua-5.2.4/src/llex.c.

257 {
258 int count = 0;
259 int s = ls->current;
260 lua_assert(s == '[' || s == ']');
261 save_and_next(ls);
262 while (ls->current == '=') {
263 save_and_next(ls);
264 count++;
265 }
266 return (ls->current == s) ? count : (-count) - 1;
267}

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

Referenced by llex(), and read_long_string().

◆ trydecpoint()

static void trydecpoint ( LexState * ls,
SemInfo * seminfo )
static

Definition at line 215 of file lua-5.2.4/src/llex.c.

215 {
216 char old = ls->decpoint;
218 buffreplace(ls, old, ls->decpoint); /* try new decimal separator */
219 if (!buff2d(ls->buff, &seminfo->r)) {
220 /* format error with correct decimal point: no more options */
221 buffreplace(ls, ls->decpoint, '.'); /* undo change (for error message) */
222 lexerror(ls, "malformed number", TK_NUMBER);
223 }
224}
#define getlocaledecpoint()

References LexState::buff, buff2d, buffreplace(), LexState::decpoint, getlocaledecpoint, lexerror(), SemInfo::r, and TK_NUMBER.

Referenced by read_numeral().

◆ txtToken()

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

Definition at line 91 of file lua-5.2.4/src/llex.c.

91 {
92 switch (token) {
93 case TK_NAME:
94 case TK_STRING:
95 case TK_NUMBER:
96 save(ls, '\0');
97 return luaO_pushfstring(ls->L, LUA_QS, luaZ_buffer(ls->buff));
98 default:
99 return luaX_token2str(ls, token);
100 }
101}
const char * luaX_token2str(LexState *ls, int token)

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

Referenced by lexerror().

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>", "<name>", "<string>"
}

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

36 {
37 "and", "break", "do", "else", "elseif",
38 "end", "false", "for", "function", "goto", "if",
39 "in", "local", "nil", "not", "or", "repeat",
40 "return", "then", "true", "until", "while",
41 "..", "...", "==", ">=", "<=", "~=", "::", "<eof>",
42 "<number>", "<name>", "<string>"
43};

Referenced by luaX_init(), and luaX_token2str().