Lines Matching full:ls
24 #define next(ls) (ls->current = zgetc(ls->z)) argument
28 #define currIsNewline(ls) (ls->current == '\n' || ls->current == '\r') argument
42 #define save_and_next(ls) (save(ls, ls->current), next(ls)) argument
45 static l_noret lexerror (LexState *ls, const char *msg, int token);
48 static void save (LexState *ls, int c) { in save() argument
49 Mbuffer *b = ls->buff; in save()
53 lexerror(ls, "lexical element too long", 0); in save()
55 luaZ_resizebuffer(ls->L, b, newsize); in save()
71 const char *luaX_token2str (LexState *ls, int token) { in luaX_token2str() argument
74 return (lisprint(token)) ? luaO_pushfstring(ls->L, LUA_QL("%c"), token) : in luaX_token2str()
75 luaO_pushfstring(ls->L, "char(%d)", token); in luaX_token2str()
80 return luaO_pushfstring(ls->L, LUA_QS, s); in luaX_token2str()
87 static const char *txtToken (LexState *ls, int token) { in txtToken() argument
92 save(ls, '\0'); in txtToken()
93 return luaO_pushfstring(ls->L, LUA_QS, luaZ_buffer(ls->buff)); in txtToken()
95 return luaX_token2str(ls, token); in txtToken()
100 static l_noret lexerror (LexState *ls, const char *msg, int token) { in lexerror() argument
102 luaO_chunkid(buff, getstr(ls->source), LUA_IDSIZE); in lexerror()
103 msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg); in lexerror()
105 luaO_pushfstring(ls->L, "%s near %s", msg, txtToken(ls, token)); in lexerror()
106 luaD_throw(ls->L, LUA_ERRSYNTAX); in lexerror()
110 l_noret luaX_syntaxerror (LexState *ls, const char *msg) { in luaX_syntaxerror() argument
111 lexerror(ls, msg, ls->t.token); in luaX_syntaxerror()
120 TString *luaX_newstring (LexState *ls, const char *str, size_t l) { in luaX_newstring() argument
121 lua_State *L = ls->L; in luaX_newstring()
125 o = luaH_set(L, ls->fs->h, L->top - 1); in luaX_newstring()
144 static void inclinenumber (LexState *ls) { in inclinenumber() argument
145 int old = ls->current; in inclinenumber()
146 lua_assert(currIsNewline(ls)); in inclinenumber()
147 next(ls); /* skip `\n' or `\r' */ in inclinenumber()
148 if (currIsNewline(ls) && ls->current != old) in inclinenumber()
149 next(ls); /* skip `\n\r' or `\r\n' */ in inclinenumber()
150 if (++ls->linenumber >= MAX_INT) in inclinenumber()
151 lexerror(ls, "chunk has too many lines", 0); in inclinenumber()
155 void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source, in luaX_setinput() argument
157 ls->decpoint = '.'; in luaX_setinput()
158 ls->L = L; in luaX_setinput()
159 ls->current = firstchar; in luaX_setinput()
160 ls->lookahead.token = TK_EOS; /* no look-ahead token */ in luaX_setinput()
161 ls->z = z; in luaX_setinput()
162 ls->fs = NULL; in luaX_setinput()
163 ls->linenumber = 1; in luaX_setinput()
164 ls->lastline = 1; in luaX_setinput()
165 ls->source = source; in luaX_setinput()
166 ls->envn = luaS_new(L, LUA_ENV); /* create env name */ in luaX_setinput()
167 luaS_fix(ls->envn); /* never collect this name */ in luaX_setinput()
168 luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */ in luaX_setinput()
181 static int check_next (LexState *ls, const char *set) { in check_next() argument
182 if (ls->current == '\0' || !strchr(set, ls->current)) in check_next()
184 save_and_next(ls); in check_next()
192 static void buffreplace (LexState *ls, char from, char to) { in buffreplace() argument
193 size_t n = luaZ_bufflen(ls->buff); in buffreplace()
194 char *p = luaZ_buffer(ls->buff); in buffreplace()
211 static void trydecpoint (LexState *ls, SemInfo *seminfo) { in trydecpoint() argument
212 char old = ls->decpoint; in trydecpoint()
213 ls->decpoint = getlocaledecpoint(); in trydecpoint()
214 buffreplace(ls, old, ls->decpoint); /* try new decimal separator */ in trydecpoint()
215 if (!buff2d(ls->buff, &seminfo->r)) { in trydecpoint()
217 buffreplace(ls, ls->decpoint, '.'); /* undo change (for error message) */ in trydecpoint()
218 lexerror(ls, "malformed number", TK_NUMBER); in trydecpoint()
228 static void 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_next(ls, "Xx")) /* hexadecimal? */ in read_numeral()
236 if (check_next(ls, expo)) /* exponent part? */ in read_numeral()
237 (void) check_next(ls, "+-"); /* optional exponent sign */ in read_numeral()
238 if (lisxdigit(ls->current) || ls->current == '.') in read_numeral()
239 save_and_next(ls); in read_numeral()
242 save(ls, '\0'); in read_numeral()
243 buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */ in read_numeral()
244 if (!buff2d(ls->buff, &seminfo->r)) /* format error? */ in read_numeral()
245 trydecpoint(ls, seminfo); /* try to update decimal point separator */ in read_numeral()
253 static int skip_sep (LexState *ls) { in skip_sep() argument
255 int s = ls->current; in skip_sep()
257 save_and_next(ls); in skip_sep()
258 while (ls->current == '=') { in skip_sep()
259 save_and_next(ls); in skip_sep()
262 return (ls->current == s) ? count : (-count) - 1; in skip_sep()
266 static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) { in read_long_string() argument
267 save_and_next(ls); /* skip 2nd `[' */ in read_long_string()
268 if (currIsNewline(ls)) /* string starts with a newline? */ in read_long_string()
269 inclinenumber(ls); /* skip it */ in read_long_string()
271 switch (ls->current) { in read_long_string()
273 lexerror(ls, (seminfo) ? "unfinished long string" : in read_long_string()
277 if (skip_sep(ls) == sep) { in read_long_string()
278 save_and_next(ls); /* skip 2nd `]' */ in read_long_string()
284 save(ls, '\n'); in read_long_string()
285 inclinenumber(ls); in read_long_string()
286 if (!seminfo) luaZ_resetbuffer(ls->buff); /* avoid wasting space */ in read_long_string()
290 if (seminfo) save_and_next(ls); in read_long_string()
291 else next(ls); in read_long_string()
296 seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + sep), in read_long_string()
297 luaZ_bufflen(ls->buff) - 2*(2 + sep)); in read_long_string()
301 static void escerror (LexState *ls, int *c, int n, const char *msg) { in escerror() argument
303 luaZ_resetbuffer(ls->buff); /* prepare error message */ in escerror()
304 save(ls, '\\'); in escerror()
306 save(ls, c[i]); in escerror()
307 lexerror(ls, msg, TK_STRING); in escerror()
311 static int readhexaesc (LexState *ls) { in readhexaesc() argument
316 c[i] = next(ls); in readhexaesc()
318 escerror(ls, c, i + 1, "hexadecimal digit expected"); in readhexaesc()
325 static int readdecesc (LexState *ls) { in readdecesc() argument
328 for (i = 0; i < 3 && lisdigit(ls->current); i++) { /* read up to 3 digits */ in readdecesc()
329 c[i] = ls->current; in readdecesc()
331 next(ls); in readdecesc()
334 escerror(ls, c, i, "decimal escape too large"); in readdecesc()
339 static void read_string (LexState *ls, int del, SemInfo *seminfo) { in read_string() argument
340 save_and_next(ls); /* keep delimiter (for error messages) */ in read_string()
341 while (ls->current != del) { in read_string()
342 switch (ls->current) { in read_string()
344 lexerror(ls, "unfinished string", TK_EOS); in read_string()
348 lexerror(ls, "unfinished string", TK_STRING); in read_string()
352 next(ls); /* do not save the `\' */ in read_string()
353 switch (ls->current) { in read_string()
361 case 'x': c = readhexaesc(ls); goto read_save; in read_string()
363 inclinenumber(ls); c = '\n'; goto only_save; in read_string()
365 c = ls->current; goto read_save; in read_string()
368 next(ls); /* skip the 'z' */ in read_string()
369 while (lisspace(ls->current)) { in read_string()
370 if (currIsNewline(ls)) inclinenumber(ls); in read_string()
371 else next(ls); in read_string()
376 if (!lisdigit(ls->current)) in read_string()
377 escerror(ls, &ls->current, 1, "invalid escape sequence"); in read_string()
379 c = readdecesc(ls); in read_string()
383 read_save: next(ls); /* read next character */ in read_string()
384 only_save: save(ls, c); /* save 'c' */ in read_string()
388 save_and_next(ls); in read_string()
391 save_and_next(ls); /* skip delimiter */ in read_string()
392 seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1, in read_string()
393 luaZ_bufflen(ls->buff) - 2); in read_string()
397 static int llex (LexState *ls, SemInfo *seminfo) { in llex() argument
398 luaZ_resetbuffer(ls->buff); in llex()
400 switch (ls->current) { in llex()
402 inclinenumber(ls); in llex()
406 next(ls); in llex()
410 next(ls); in llex()
411 if (ls->current != '-') return '-'; in llex()
413 next(ls); in llex()
414 if (ls->current == '[') { /* long comment? */ in llex()
415 int sep = skip_sep(ls); in llex()
416 luaZ_resetbuffer(ls->buff); /* `skip_sep' may dirty the buffer */ in llex()
418 read_long_string(ls, NULL, sep); /* skip long comment */ in llex()
419 luaZ_resetbuffer(ls->buff); /* previous call may dirty the buff. */ in llex()
424 while (!currIsNewline(ls) && ls->current != EOZ) in llex()
425 next(ls); /* skip until end of line (or end of file) */ in llex()
429 int sep = skip_sep(ls); in llex()
431 read_long_string(ls, seminfo, sep); in llex()
436 lexerror(ls, "invalid long string delimiter", TK_STRING); in llex()
441 next(ls); in llex()
442 if (ls->current != '=') return '='; in llex()
443 else { next(ls); return TK_EQ; } in llex()
446 next(ls); in llex()
447 if (ls->current != '=') return '<'; in llex()
448 else { next(ls); return TK_LE; } in llex()
451 next(ls); in llex()
452 if (ls->current != '=') return '>'; in llex()
453 else { next(ls); return TK_GE; } in llex()
456 next(ls); in llex()
457 if (ls->current != '=') return '~'; in llex()
458 else { next(ls); return TK_NE; } in llex()
461 next(ls); in llex()
462 if (ls->current != ':') return ':'; in llex()
463 else { next(ls); return TK_DBCOLON; } in llex()
466 read_string(ls, ls->current, seminfo); in llex()
470 save_and_next(ls); in llex()
471 if (check_next(ls, ".")) { in llex()
472 if (check_next(ls, ".")) in llex()
476 else if (!lisdigit(ls->current)) return '.'; in llex()
482 read_numeral(ls, seminfo); in llex()
489 if (lislalpha(ls->current)) { /* identifier or reserved word? */ in llex()
492 save_and_next(ls); in llex()
493 } while (lislalnum(ls->current)); in llex()
494 ts = luaX_newstring(ls, luaZ_buffer(ls->buff), in llex()
495 luaZ_bufflen(ls->buff)); in llex()
504 int c = ls->current; in llex()
505 next(ls); in llex()
514 void luaX_next (LexState *ls) { in luaX_next() argument
515 ls->lastline = ls->linenumber; in luaX_next()
516 if (ls->lookahead.token != TK_EOS) { /* is there a look-ahead token? */ in luaX_next()
517 ls->t = ls->lookahead; /* use this one */ in luaX_next()
518 ls->lookahead.token = TK_EOS; /* and discharge it */ in luaX_next()
521 ls->t.token = llex(ls, &ls->t.seminfo); /* read next token */ in luaX_next()
525 int luaX_lookahead (LexState *ls) { in luaX_lookahead() argument
526 lua_assert(ls->lookahead.token == TK_EOS); in luaX_lookahead()
527 ls->lookahead.token = llex(ls, &ls->lookahead.seminfo); in luaX_lookahead()
528 return ls->lookahead.token; in luaX_lookahead()