Lines Matching full:ls
32 #define next(ls) (ls->current = zgetc(ls->z)) argument
36 #define currIsNewline(ls) (ls->current == '\n' || ls->current == '\r') argument
51 #define save_and_next(ls) (save(ls, ls->current), next(ls)) argument
54 static l_noret lexerror (LexState *ls, const char *msg, int token);
57 static void save (LexState *ls, int c) { in save() argument
58 Mbuffer *b = ls->buff; in save()
62 lexerror(ls, "lexical element too long", 0); in save()
64 luaZ_resizebuffer(ls->L, b, newsize); in save()
82 const char *luaX_token2str (LexState *ls, int token) { in luaX_token2str() argument
85 return luaO_pushfstring(ls->L, "'%c'", token); in luaX_token2str()
90 return luaO_pushfstring(ls->L, "'%s'", s); in luaX_token2str()
97 static const char *txtToken (LexState *ls, int token) { in txtToken() argument
101 save(ls, '\0'); in txtToken()
102 return luaO_pushfstring(ls->L, "'%s'", luaZ_buffer(ls->buff)); in txtToken()
104 return luaX_token2str(ls, token); in txtToken()
109 static l_noret lexerror (LexState *ls, const char *msg, int token) { in lexerror() argument
110 msg = luaG_addinfo(ls->L, msg, ls->source, ls->linenumber); in lexerror()
112 luaO_pushfstring(ls->L, "%s near %s", msg, txtToken(ls, token)); in lexerror()
113 luaD_throw(ls->L, LUA_ERRSYNTAX); in lexerror()
117 l_noret luaX_syntaxerror (LexState *ls, const char *msg) { in luaX_syntaxerror() argument
118 lexerror(ls, msg, ls->t.token); in luaX_syntaxerror()
127 TString *luaX_newstring (LexState *ls, const char *str, size_t l) { in luaX_newstring() argument
128 lua_State *L = ls->L; in luaX_newstring()
132 o = luaH_set(L, ls->h, L->top - 1); in luaX_newstring()
151 static void inclinenumber (LexState *ls) { in inclinenumber() argument
152 int old = ls->current; in inclinenumber()
153 lua_assert(currIsNewline(ls)); in inclinenumber()
154 next(ls); /* skip '\n' or '\r' */ in inclinenumber()
155 if (currIsNewline(ls) && ls->current != old) in inclinenumber()
156 next(ls); /* skip '\n\r' or '\r\n' */ in inclinenumber()
157 if (++ls->linenumber >= MAX_INT) in inclinenumber()
158 lexerror(ls, "chunk has too many lines", 0); in inclinenumber()
162 void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source, in luaX_setinput() argument
164 ls->t.token = 0; in luaX_setinput()
165 ls->L = L; in luaX_setinput()
166 ls->current = firstchar; in luaX_setinput()
167 ls->lookahead.token = TK_EOS; /* no look-ahead token */ in luaX_setinput()
168 ls->z = z; in luaX_setinput()
169 ls->fs = NULL; in luaX_setinput()
170 ls->linenumber = 1; in luaX_setinput()
171 ls->lastline = 1; in luaX_setinput()
172 ls->source = source; in luaX_setinput()
173 ls->envn = luaS_newliteral(L, LUA_ENV); /* get env name */ in luaX_setinput()
174 luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */ in luaX_setinput()
186 static int check_next1 (LexState *ls, int c) { in check_next1() argument
187 if (ls->current == c) { in check_next1()
188 next(ls); in check_next1()
199 static int check_next2 (LexState *ls, const char *set) { in check_next2() argument
201 if (ls->current == set[0] || ls->current == set[1]) { in check_next2()
202 save_and_next(ls); in check_next2()
214 static int read_numeral (LexState *ls, SemInfo *seminfo) { in read_numeral() argument
217 int first = ls->current; in read_numeral()
218 lua_assert(lisdigit(ls->current)); in read_numeral()
219 save_and_next(ls); in read_numeral()
220 if (first == '0' && check_next2(ls, "xX")) /* hexadecimal? */ in read_numeral()
223 if (check_next2(ls, expo)) /* exponent part? */ in read_numeral()
224 check_next2(ls, "-+"); /* optional exponent sign */ in read_numeral()
225 if (lisxdigit(ls->current)) in read_numeral()
226 save_and_next(ls); in read_numeral()
227 else if (ls->current == '.') in read_numeral()
228 save_and_next(ls); in read_numeral()
231 save(ls, '\0'); in read_numeral()
232 if (luaO_str2num(luaZ_buffer(ls->buff), &obj) == 0) /* format error? */ in read_numeral()
233 lexerror(ls, "malformed number", TK_FLT); in read_numeral()
251 static int skip_sep (LexState *ls) { in skip_sep() argument
253 int s = ls->current; in skip_sep()
255 save_and_next(ls); in skip_sep()
256 while (ls->current == '=') { in skip_sep()
257 save_and_next(ls); in skip_sep()
260 return (ls->current == s) ? count : (-count) - 1; in skip_sep()
264 static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) { in read_long_string() argument
265 int line = ls->linenumber; /* initial line (for error message) */ in read_long_string()
266 save_and_next(ls); /* skip 2nd '[' */ in read_long_string()
267 if (currIsNewline(ls)) /* string starts with a newline? */ in read_long_string()
268 inclinenumber(ls); /* skip it */ in read_long_string()
270 switch (ls->current) { in read_long_string()
273 const char *msg = luaO_pushfstring(ls->L, in read_long_string()
275 lexerror(ls, msg, TK_EOS); in read_long_string()
279 if (skip_sep(ls) == sep) { in read_long_string()
280 save_and_next(ls); /* skip 2nd ']' */ in read_long_string()
286 save(ls, '\n'); in read_long_string()
287 inclinenumber(ls); in read_long_string()
288 if (!seminfo) luaZ_resetbuffer(ls->buff); /* avoid wasting space */ in read_long_string()
292 if (seminfo) save_and_next(ls); in read_long_string()
293 else next(ls); in read_long_string()
298 seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + sep), in read_long_string()
299 luaZ_bufflen(ls->buff) - 2*(2 + sep)); in read_long_string()
303 static void esccheck (LexState *ls, int c, const char *msg) { in esccheck() argument
305 if (ls->current != EOZ) in esccheck()
306 save_and_next(ls); /* add current to buffer for error message */ in esccheck()
307 lexerror(ls, msg, TK_STRING); in esccheck()
312 static int gethexa (LexState *ls) { in gethexa() argument
313 save_and_next(ls); in gethexa()
314 esccheck (ls, lisxdigit(ls->current), "hexadecimal digit expected"); in gethexa()
315 return luaO_hexavalue(ls->current); in gethexa()
319 static int readhexaesc (LexState *ls) { in readhexaesc() argument
320 int r = gethexa(ls); in readhexaesc()
321 r = (r << 4) + gethexa(ls); in readhexaesc()
322 luaZ_buffremove(ls->buff, 2); /* remove saved chars from buffer */ in readhexaesc()
327 static unsigned long readutf8esc (LexState *ls) { in readutf8esc() argument
330 save_and_next(ls); /* skip 'u' */ in readutf8esc()
331 esccheck(ls, ls->current == '{', "missing '{'"); in readutf8esc()
332 r = gethexa(ls); /* must have at least one digit */ in readutf8esc()
333 while ((save_and_next(ls), lisxdigit(ls->current))) { in readutf8esc()
335 r = (r << 4) + luaO_hexavalue(ls->current); in readutf8esc()
336 esccheck(ls, r <= 0x10FFFF, "UTF-8 value too large"); in readutf8esc()
338 esccheck(ls, ls->current == '}', "missing '}'"); in readutf8esc()
339 next(ls); /* skip '}' */ in readutf8esc()
340 luaZ_buffremove(ls->buff, i); /* remove saved chars from buffer */ in readutf8esc()
345 static void utf8esc (LexState *ls) { in utf8esc() argument
347 int n = luaO_utf8esc(buff, readutf8esc(ls)); in utf8esc()
349 save(ls, buff[UTF8BUFFSZ - n]); in utf8esc()
353 static int readdecesc (LexState *ls) { in readdecesc() argument
356 for (i = 0; i < 3 && lisdigit(ls->current); i++) { /* read up to 3 digits */ in readdecesc()
357 r = 10*r + ls->current - '0'; in readdecesc()
358 save_and_next(ls); in readdecesc()
360 esccheck(ls, r <= UCHAR_MAX, "decimal escape too large"); in readdecesc()
361 luaZ_buffremove(ls->buff, i); /* remove read digits from buffer */ in readdecesc()
366 static void read_string (LexState *ls, int del, SemInfo *seminfo) { in read_string() argument
367 save_and_next(ls); /* keep delimiter (for error messages) */ in read_string()
368 while (ls->current != del) { in read_string()
369 switch (ls->current) { in read_string()
371 lexerror(ls, "unfinished string", TK_EOS); in read_string()
375 lexerror(ls, "unfinished string", TK_STRING); in read_string()
379 save_and_next(ls); /* keep '\\' for error messages */ in read_string()
380 switch (ls->current) { in read_string()
388 case 'x': c = readhexaesc(ls); goto read_save; in read_string()
389 case 'u': utf8esc(ls); goto no_save; in read_string()
391 inclinenumber(ls); c = '\n'; goto only_save; in read_string()
393 c = ls->current; goto read_save; in read_string()
396 luaZ_buffremove(ls->buff, 1); /* remove '\\' */ in read_string()
397 next(ls); /* skip the 'z' */ in read_string()
398 while (lisspace(ls->current)) { in read_string()
399 if (currIsNewline(ls)) inclinenumber(ls); in read_string()
400 else next(ls); in read_string()
405 esccheck(ls, lisdigit(ls->current), "invalid escape sequence"); in read_string()
406 c = readdecesc(ls); /* digital escape '\ddd' */ in read_string()
411 next(ls); in read_string()
414 luaZ_buffremove(ls->buff, 1); /* remove '\\' */ in read_string()
415 save(ls, c); in read_string()
420 save_and_next(ls); in read_string()
423 save_and_next(ls); /* skip delimiter */ in read_string()
424 seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1, in read_string()
425 luaZ_bufflen(ls->buff) - 2); in read_string()
429 static int llex (LexState *ls, SemInfo *seminfo) { in llex() argument
430 luaZ_resetbuffer(ls->buff); in llex()
432 switch (ls->current) { in llex()
434 inclinenumber(ls); in llex()
438 next(ls); in llex()
442 next(ls); in llex()
443 if (ls->current != '-') return '-'; in llex()
445 next(ls); in llex()
446 if (ls->current == '[') { /* long comment? */ in llex()
447 int sep = skip_sep(ls); in llex()
448 luaZ_resetbuffer(ls->buff); /* 'skip_sep' may dirty the buffer */ in llex()
450 read_long_string(ls, NULL, sep); /* skip long comment */ in llex()
451 luaZ_resetbuffer(ls->buff); /* previous call may dirty the buff. */ in llex()
456 while (!currIsNewline(ls) && ls->current != EOZ) in llex()
457 next(ls); /* skip until end of line (or end of file) */ in llex()
461 int sep = skip_sep(ls); in llex()
463 read_long_string(ls, seminfo, sep); in llex()
467 lexerror(ls, "invalid long string delimiter", TK_STRING); in llex()
471 next(ls); in llex()
472 if (check_next1(ls, '=')) return TK_EQ; in llex()
476 next(ls); in llex()
477 if (check_next1(ls, '=')) return TK_LE; in llex()
478 else if (check_next1(ls, '<')) return TK_SHL; in llex()
482 next(ls); in llex()
483 if (check_next1(ls, '=')) return TK_GE; in llex()
484 else if (check_next1(ls, '>')) return TK_SHR; in llex()
488 next(ls); in llex()
489 if (check_next1(ls, '/')) return TK_IDIV; in llex()
493 next(ls); in llex()
494 if (check_next1(ls, '=')) return TK_NE; in llex()
498 next(ls); in llex()
499 if (check_next1(ls, ':')) return TK_DBCOLON; in llex()
503 read_string(ls, ls->current, seminfo); in llex()
507 save_and_next(ls); in llex()
508 if (check_next1(ls, '.')) { in llex()
509 if (check_next1(ls, '.')) in llex()
513 else if (!lisdigit(ls->current)) return '.'; in llex()
514 else return read_numeral(ls, seminfo); in llex()
518 return read_numeral(ls, seminfo); in llex()
524 if (lislalpha(ls->current)) { /* identifier or reserved word? */ in llex()
527 save_and_next(ls); in llex()
528 } while (lislalnum(ls->current)); in llex()
529 ts = luaX_newstring(ls, luaZ_buffer(ls->buff), in llex()
530 luaZ_bufflen(ls->buff)); in llex()
539 int c = ls->current; in llex()
540 next(ls); in llex()
549 void luaX_next (LexState *ls) { in luaX_next() argument
550 ls->lastline = ls->linenumber; in luaX_next()
551 if (ls->lookahead.token != TK_EOS) { /* is there a look-ahead token? */ in luaX_next()
552 ls->t = ls->lookahead; /* use this one */ in luaX_next()
553 ls->lookahead.token = TK_EOS; /* and discharge it */ in luaX_next()
556 ls->t.token = llex(ls, &ls->t.seminfo); /* read next token */ in luaX_next()
560 int luaX_lookahead (LexState *ls) { in luaX_lookahead() argument
561 lua_assert(ls->lookahead.token == TK_EOS); in luaX_lookahead()
562 ls->lookahead.token = llex(ls, &ls->lookahead.seminfo); in luaX_lookahead()
563 return ls->lookahead.token; in luaX_lookahead()