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()
87 return luaO_pushfstring(ls->L, "'<\\%d>'", token); in luaX_token2str()
92 return luaO_pushfstring(ls->L, "'%s'", s); in luaX_token2str()
99 static const char *txtToken (LexState *ls, int token) { in txtToken() argument
103 save(ls, '\0'); in txtToken()
104 return luaO_pushfstring(ls->L, "'%s'", luaZ_buffer(ls->buff)); in txtToken()
106 return luaX_token2str(ls, token); in txtToken()
111 static l_noret lexerror (LexState *ls, const char *msg, int token) { in lexerror() argument
112 msg = luaG_addinfo(ls->L, msg, ls->source, ls->linenumber); in lexerror()
114 luaO_pushfstring(ls->L, "%s near %s", msg, txtToken(ls, token)); in lexerror()
115 luaD_throw(ls->L, LUA_ERRSYNTAX); in lexerror()
119 l_noret luaX_syntaxerror (LexState *ls, const char *msg) { in luaX_syntaxerror() argument
120 lexerror(ls, msg, ls->t.token); in luaX_syntaxerror()
134 TString *luaX_newstring (LexState *ls, const char *str, size_t l) { in luaX_newstring() argument
135 lua_State *L = ls->L; in luaX_newstring()
137 const TValue *o = luaH_getstr(ls->h, ts); in luaX_newstring()
143 luaH_finishset(L, ls->h, stv, o, stv); /* t[string] = string */ in luaX_newstring()
156 static void inclinenumber (LexState *ls) { in inclinenumber() argument
157 int old = ls->current; in inclinenumber()
158 lua_assert(currIsNewline(ls)); in inclinenumber()
159 next(ls); /* skip '\n' or '\r' */ in inclinenumber()
160 if (currIsNewline(ls) && ls->current != old) in inclinenumber()
161 next(ls); /* skip '\n\r' or '\r\n' */ in inclinenumber()
162 if (++ls->linenumber >= MAX_INT) in inclinenumber()
163 lexerror(ls, "chunk has too many lines", 0); in inclinenumber()
167 void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source, in luaX_setinput() argument
169 ls->t.token = 0; in luaX_setinput()
170 ls->L = L; in luaX_setinput()
171 ls->current = firstchar; in luaX_setinput()
172 ls->lookahead.token = TK_EOS; /* no look-ahead token */ in luaX_setinput()
173 ls->z = z; in luaX_setinput()
174 ls->fs = NULL; in luaX_setinput()
175 ls->linenumber = 1; in luaX_setinput()
176 ls->lastline = 1; in luaX_setinput()
177 ls->source = source; in luaX_setinput()
178 ls->envn = luaS_newliteral(L, LUA_ENV); /* get env name */ in luaX_setinput()
179 luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */ in luaX_setinput()
191 static int check_next1 (LexState *ls, int c) { in check_next1() argument
192 if (ls->current == c) { in check_next1()
193 next(ls); in check_next1()
204 static int check_next2 (LexState *ls, const char *set) { in check_next2() argument
206 if (ls->current == set[0] || ls->current == set[1]) { in check_next2()
207 save_and_next(ls); in check_next2()
227 static int read_numeral (LexState *ls, SemInfo *seminfo) { in read_numeral() argument
230 int first = ls->current; in read_numeral()
231 lua_assert(lisdigit(ls->current)); in read_numeral()
232 save_and_next(ls); in read_numeral()
233 if (first == '0' && check_next2(ls, "xX")) /* hexadecimal? */ in read_numeral()
236 if (check_next2(ls, expo)) /* exponent mark? */ in read_numeral()
237 check_next2(ls, "-+"); /* optional exponent sign */ in read_numeral()
238 else if (lisxdigit(ls->current) || ls->current == '.') /* '%x|%.' */ in read_numeral()
239 save_and_next(ls); in read_numeral()
242 if (lislalpha(ls->current)) /* is numeral touching a letter? */ in read_numeral()
243 save_and_next(ls); /* force an error */ in read_numeral()
244 save(ls, '\0'); in read_numeral()
245 if (luaO_str2num(luaZ_buffer(ls->buff), &obj) == 0) /* format error? */ in read_numeral()
246 lexerror(ls, "malformed number", TK_FLT); in read_numeral()
265 static size_t skip_sep (LexState *ls) { in skip_sep() argument
267 int s = ls->current; in skip_sep()
269 save_and_next(ls); in skip_sep()
270 while (ls->current == '=') { in skip_sep()
271 save_and_next(ls); in skip_sep()
274 return (ls->current == s) ? count + 2 in skip_sep()
280 static void read_long_string (LexState *ls, SemInfo *seminfo, size_t sep) { in read_long_string() argument
281 int line = ls->linenumber; /* initial line (for error message) */ in read_long_string()
282 save_and_next(ls); /* skip 2nd '[' */ in read_long_string()
283 if (currIsNewline(ls)) /* string starts with a newline? */ in read_long_string()
284 inclinenumber(ls); /* skip it */ in read_long_string()
286 switch (ls->current) { in read_long_string()
289 const char *msg = luaO_pushfstring(ls->L, in read_long_string()
291 lexerror(ls, msg, TK_EOS); in read_long_string()
295 if (skip_sep(ls) == sep) { in read_long_string()
296 save_and_next(ls); /* skip 2nd ']' */ in read_long_string()
302 save(ls, '\n'); in read_long_string()
303 inclinenumber(ls); in read_long_string()
304 if (!seminfo) luaZ_resetbuffer(ls->buff); /* avoid wasting space */ in read_long_string()
308 if (seminfo) save_and_next(ls); in read_long_string()
309 else next(ls); in read_long_string()
314 seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + sep, in read_long_string()
315 luaZ_bufflen(ls->buff) - 2 * sep); in read_long_string()
319 static void esccheck (LexState *ls, int c, const char *msg) { in esccheck() argument
321 if (ls->current != EOZ) in esccheck()
322 save_and_next(ls); /* add current to buffer for error message */ in esccheck()
323 lexerror(ls, msg, TK_STRING); in esccheck()
328 static int gethexa (LexState *ls) { in gethexa() argument
329 save_and_next(ls); in gethexa()
330 esccheck (ls, lisxdigit(ls->current), "hexadecimal digit expected"); in gethexa()
331 return luaO_hexavalue(ls->current); in gethexa()
335 static int readhexaesc (LexState *ls) { in readhexaesc() argument
336 int r = gethexa(ls); in readhexaesc()
337 r = (r << 4) + gethexa(ls); in readhexaesc()
338 luaZ_buffremove(ls->buff, 2); /* remove saved chars from buffer */ in readhexaesc()
343 static unsigned long readutf8esc (LexState *ls) { in readutf8esc() argument
346 save_and_next(ls); /* skip 'u' */ in readutf8esc()
347 esccheck(ls, ls->current == '{', "missing '{'"); in readutf8esc()
348 r = gethexa(ls); /* must have at least one digit */ in readutf8esc()
349 while (cast_void(save_and_next(ls)), lisxdigit(ls->current)) { in readutf8esc()
351 esccheck(ls, r <= (0x7FFFFFFFu >> 4), "UTF-8 value too large"); in readutf8esc()
352 r = (r << 4) + luaO_hexavalue(ls->current); in readutf8esc()
354 esccheck(ls, ls->current == '}', "missing '}'"); in readutf8esc()
355 next(ls); /* skip '}' */ in readutf8esc()
356 luaZ_buffremove(ls->buff, i); /* remove saved chars from buffer */ in readutf8esc()
361 static void utf8esc (LexState *ls) { in utf8esc() argument
363 int n = luaO_utf8esc(buff, readutf8esc(ls)); in utf8esc()
365 save(ls, buff[UTF8BUFFSZ - n]); in utf8esc()
369 static int readdecesc (LexState *ls) { in readdecesc() argument
372 for (i = 0; i < 3 && lisdigit(ls->current); i++) { /* read up to 3 digits */ in readdecesc()
373 r = 10*r + ls->current - '0'; in readdecesc()
374 save_and_next(ls); in readdecesc()
376 esccheck(ls, r <= UCHAR_MAX, "decimal escape too large"); in readdecesc()
377 luaZ_buffremove(ls->buff, i); /* remove read digits from buffer */ in readdecesc()
382 static void read_string (LexState *ls, int del, SemInfo *seminfo) { in read_string() argument
383 save_and_next(ls); /* keep delimiter (for error messages) */ in read_string()
384 while (ls->current != del) { in read_string()
385 switch (ls->current) { in read_string()
387 lexerror(ls, "unfinished string", TK_EOS); in read_string()
391 lexerror(ls, "unfinished string", TK_STRING); in read_string()
395 save_and_next(ls); /* keep '\\' for error messages */ in read_string()
396 switch (ls->current) { in read_string()
404 case 'x': c = readhexaesc(ls); goto read_save; in read_string()
405 case 'u': utf8esc(ls); goto no_save; in read_string()
407 inclinenumber(ls); c = '\n'; goto only_save; in read_string()
409 c = ls->current; goto read_save; in read_string()
412 luaZ_buffremove(ls->buff, 1); /* remove '\\' */ in read_string()
413 next(ls); /* skip the 'z' */ in read_string()
414 while (lisspace(ls->current)) { in read_string()
415 if (currIsNewline(ls)) inclinenumber(ls); in read_string()
416 else next(ls); in read_string()
421 esccheck(ls, lisdigit(ls->current), "invalid escape sequence"); in read_string()
422 c = readdecesc(ls); /* digital escape '\ddd' */ in read_string()
427 next(ls); in read_string()
430 luaZ_buffremove(ls->buff, 1); /* remove '\\' */ in read_string()
431 save(ls, c); in read_string()
436 save_and_next(ls); in read_string()
439 save_and_next(ls); /* skip delimiter */ in read_string()
440 seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1, in read_string()
441 luaZ_bufflen(ls->buff) - 2); in read_string()
445 static int llex (LexState *ls, SemInfo *seminfo) { in llex() argument
446 luaZ_resetbuffer(ls->buff); in llex()
448 switch (ls->current) { in llex()
450 inclinenumber(ls); in llex()
454 next(ls); in llex()
458 next(ls); in llex()
459 if (ls->current != '-') return '-'; in llex()
461 next(ls); in llex()
462 if (ls->current == '[') { /* long comment? */ in llex()
463 size_t sep = skip_sep(ls); in llex()
464 luaZ_resetbuffer(ls->buff); /* 'skip_sep' may dirty the buffer */ in llex()
466 read_long_string(ls, NULL, sep); /* skip long comment */ in llex()
467 luaZ_resetbuffer(ls->buff); /* previous call may dirty the buff. */ in llex()
472 while (!currIsNewline(ls) && ls->current != EOZ) in llex()
473 next(ls); /* skip until end of line (or end of file) */ in llex()
477 size_t sep = skip_sep(ls); in llex()
479 read_long_string(ls, seminfo, sep); in llex()
483 lexerror(ls, "invalid long string delimiter", TK_STRING); in llex()
487 next(ls); in llex()
488 if (check_next1(ls, '=')) return TK_EQ; /* '==' */ in llex()
492 next(ls); in llex()
493 if (check_next1(ls, '=')) return TK_LE; /* '<=' */ in llex()
494 else if (check_next1(ls, '<')) return TK_SHL; /* '<<' */ in llex()
498 next(ls); in llex()
499 if (check_next1(ls, '=')) return TK_GE; /* '>=' */ in llex()
500 else if (check_next1(ls, '>')) return TK_SHR; /* '>>' */ in llex()
504 next(ls); in llex()
505 if (check_next1(ls, '/')) return TK_IDIV; /* '//' */ in llex()
509 next(ls); in llex()
510 if (check_next1(ls, '=')) return TK_NE; /* '~=' */ in llex()
514 next(ls); in llex()
515 if (check_next1(ls, ':')) return TK_DBCOLON; /* '::' */ in llex()
519 read_string(ls, ls->current, seminfo); in llex()
523 save_and_next(ls); in llex()
524 if (check_next1(ls, '.')) { in llex()
525 if (check_next1(ls, '.')) in llex()
529 else if (!lisdigit(ls->current)) return '.'; in llex()
530 else return read_numeral(ls, seminfo); in llex()
534 return read_numeral(ls, seminfo); in llex()
540 if (lislalpha(ls->current)) { /* identifier or reserved word? */ in llex()
543 save_and_next(ls); in llex()
544 } while (lislalnum(ls->current)); in llex()
545 ts = luaX_newstring(ls, luaZ_buffer(ls->buff), in llex()
546 luaZ_bufflen(ls->buff)); in llex()
555 int c = ls->current; in llex()
556 next(ls); in llex()
565 void luaX_next (LexState *ls) { in luaX_next() argument
566 ls->lastline = ls->linenumber; in luaX_next()
567 if (ls->lookahead.token != TK_EOS) { /* is there a look-ahead token? */ in luaX_next()
568 ls->t = ls->lookahead; /* use this one */ in luaX_next()
569 ls->lookahead.token = TK_EOS; /* and discharge it */ in luaX_next()
572 ls->t.token = llex(ls, &ls->t.seminfo); /* read next token */ in luaX_next()
576 int luaX_lookahead (LexState *ls) { in luaX_lookahead() argument
577 lua_assert(ls->lookahead.token == TK_EOS); in luaX_lookahead()
578 ls->lookahead.token = llex(ls, &ls->lookahead.seminfo); in luaX_lookahead()
579 return ls->lookahead.token; in luaX_lookahead()