Lines Matching refs:ls

26 #define next(ls) (ls->current = zgetc(ls->z))  argument
30 #define currIsNewline(ls) (ls->current == '\n' || ls->current == '\r') argument
44 #define save_and_next(ls) (save(ls, ls->current), next(ls)) argument
47 static l_noret lexerror (LexState *ls, const char *msg, int token);
50 static void save (LexState *ls, int c) { in save() argument
51 Mbuffer *b = ls->buff; in save()
55 lexerror(ls, "lexical element too long", 0); in save()
57 luaZ_resizebuffer(ls->L, b, newsize); in save()
73 const char *luaX_token2str (LexState *ls, int token) { in luaX_token2str() argument
76 return (lisprint(token)) ? luaO_pushfstring(ls->L, LUA_QL("%c"), token) : in luaX_token2str()
77 luaO_pushfstring(ls->L, "char(%d)", token); in luaX_token2str()
82 return luaO_pushfstring(ls->L, LUA_QS, s); in luaX_token2str()
89 static const char *txtToken (LexState *ls, int token) { in txtToken() argument
94 save(ls, '\0'); in txtToken()
95 return luaO_pushfstring(ls->L, LUA_QS, luaZ_buffer(ls->buff)); in txtToken()
97 return luaX_token2str(ls, token); in txtToken()
102 static l_noret lexerror (LexState *ls, const char *msg, int token) { in lexerror() argument
104 luaO_chunkid(buff, getstr(ls->source), LUA_IDSIZE); in lexerror()
105 msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg); in lexerror()
107 luaO_pushfstring(ls->L, "%s near %s", msg, txtToken(ls, token)); in lexerror()
108 luaD_throw(ls->L, LUA_ERRSYNTAX); in lexerror()
112 l_noret luaX_syntaxerror (LexState *ls, const char *msg) { in luaX_syntaxerror() argument
113 lexerror(ls, msg, ls->t.token); in luaX_syntaxerror()
122 TString *luaX_newstring (LexState *ls, const char *str, size_t l) { in luaX_newstring() argument
123 lua_State *L = ls->L; in luaX_newstring()
127 o = luaH_set(L, ls->fs->h, L->top - 1); in luaX_newstring()
146 static void inclinenumber (LexState *ls) { in inclinenumber() argument
147 int old = ls->current; in inclinenumber()
148 lua_assert(currIsNewline(ls)); in inclinenumber()
149 next(ls); /* skip `\n' or `\r' */ in inclinenumber()
150 if (currIsNewline(ls) && ls->current != old) in inclinenumber()
151 next(ls); /* skip `\n\r' or `\r\n' */ in inclinenumber()
152 if (++ls->linenumber >= MAX_INT) in inclinenumber()
153 lexerror(ls, "chunk has too many lines", 0); in inclinenumber()
157 void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source, in luaX_setinput() argument
159 ls->decpoint = '.'; in luaX_setinput()
160 ls->L = L; in luaX_setinput()
161 ls->current = firstchar; in luaX_setinput()
162 ls->lookahead.token = TK_EOS; /* no look-ahead token */ in luaX_setinput()
163 ls->z = z; in luaX_setinput()
164 ls->fs = NULL; in luaX_setinput()
165 ls->linenumber = 1; in luaX_setinput()
166 ls->lastline = 1; in luaX_setinput()
167 ls->source = source; in luaX_setinput()
168 ls->envn = luaS_new(L, LUA_ENV); /* create env name */ in luaX_setinput()
169 luaS_fix(ls->envn); /* never collect this name */ in luaX_setinput()
170 luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */ in luaX_setinput()
183 static int check_next (LexState *ls, const char *set) { in check_next() argument
184 if (ls->current == '\0' || !strchr(set, ls->current)) in check_next()
186 save_and_next(ls); in check_next()
194 static void buffreplace (LexState *ls, char from, char to) { in buffreplace() argument
195 size_t n = luaZ_bufflen(ls->buff); in buffreplace()
196 char *p = luaZ_buffer(ls->buff); in buffreplace()
213 static void trydecpoint (LexState *ls, SemInfo *seminfo) { in trydecpoint() argument
214 char old = ls->decpoint; in trydecpoint()
215 ls->decpoint = getlocaledecpoint(); in trydecpoint()
216 buffreplace(ls, old, ls->decpoint); /* try new decimal separator */ in trydecpoint()
217 if (!buff2d(ls->buff, &seminfo->r)) { in trydecpoint()
219 buffreplace(ls, ls->decpoint, '.'); /* undo change (for error message) */ in trydecpoint()
220 lexerror(ls, "malformed number", TK_NUMBER); in trydecpoint()
230 static void read_numeral (LexState *ls, SemInfo *seminfo) { in read_numeral() argument
232 int first = ls->current; in read_numeral()
233 lua_assert(lisdigit(ls->current)); in read_numeral()
234 save_and_next(ls); in read_numeral()
235 if (first == '0' && check_next(ls, "Xx")) /* hexadecimal? */ in read_numeral()
238 if (check_next(ls, expo)) /* exponent part? */ in read_numeral()
239 check_next(ls, "+-"); /* optional exponent sign */ in read_numeral()
240 if (lisxdigit(ls->current) || ls->current == '.') in read_numeral()
241 save_and_next(ls); in read_numeral()
244 save(ls, '\0'); in read_numeral()
245 buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */ in read_numeral()
246 if (!buff2d(ls->buff, &seminfo->r)) /* format error? */ in read_numeral()
247 trydecpoint(ls, seminfo); /* try to update decimal point separator */ in read_numeral()
255 static int skip_sep (LexState *ls) { in skip_sep() argument
257 int s = ls->current; in skip_sep()
259 save_and_next(ls); in skip_sep()
260 while (ls->current == '=') { in skip_sep()
261 save_and_next(ls); in skip_sep()
264 return (ls->current == s) ? count : (-count) - 1; in skip_sep()
268 static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) { in read_long_string() argument
269 save_and_next(ls); /* skip 2nd `[' */ in read_long_string()
270 if (currIsNewline(ls)) /* string starts with a newline? */ in read_long_string()
271 inclinenumber(ls); /* skip it */ in read_long_string()
273 switch (ls->current) { in read_long_string()
275 lexerror(ls, (seminfo) ? "unfinished long string" : 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 escerror (LexState *ls, int *c, int n, const char *msg) { in escerror() argument
305 luaZ_resetbuffer(ls->buff); /* prepare error message */ in escerror()
306 save(ls, '\\'); in escerror()
308 save(ls, c[i]); in escerror()
309 lexerror(ls, msg, TK_STRING); in escerror()
313 static int readhexaesc (LexState *ls) { in readhexaesc() argument
318 c[i] = next(ls); in readhexaesc()
320 escerror(ls, c, i + 1, "hexadecimal digit expected"); in readhexaesc()
327 static int readdecesc (LexState *ls) { in readdecesc() argument
330 for (i = 0; i < 3 && lisdigit(ls->current); i++) { /* read up to 3 digits */ in readdecesc()
331 c[i] = ls->current; in readdecesc()
333 next(ls); in readdecesc()
336 escerror(ls, c, i, "decimal escape too large"); in readdecesc()
341 static void read_string (LexState *ls, int del, SemInfo *seminfo) { in read_string() argument
342 save_and_next(ls); /* keep delimiter (for error messages) */ in read_string()
343 while (ls->current != del) { in read_string()
344 switch (ls->current) { in read_string()
346 lexerror(ls, "unfinished string", TK_EOS); in read_string()
350 lexerror(ls, "unfinished string", TK_STRING); in read_string()
354 next(ls); /* do not save the `\' */ in read_string()
355 switch (ls->current) { in read_string()
363 case 'x': c = readhexaesc(ls); goto read_save; in read_string()
365 inclinenumber(ls); c = '\n'; goto only_save; in read_string()
367 c = ls->current; goto read_save; in read_string()
370 next(ls); /* skip the 'z' */ in read_string()
371 while (lisspace(ls->current)) { in read_string()
372 if (currIsNewline(ls)) inclinenumber(ls); in read_string()
373 else next(ls); in read_string()
378 if (!lisdigit(ls->current)) in read_string()
379 escerror(ls, &ls->current, 1, "invalid escape sequence"); in read_string()
381 c = readdecesc(ls); in read_string()
385 read_save: next(ls); /* read next character */ in read_string()
386 only_save: save(ls, c); /* save 'c' */ in read_string()
390 save_and_next(ls); in read_string()
393 save_and_next(ls); /* skip delimiter */ in read_string()
394 seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1, in read_string()
395 luaZ_bufflen(ls->buff) - 2); in read_string()
399 static int llex (LexState *ls, SemInfo *seminfo) { in llex() argument
400 luaZ_resetbuffer(ls->buff); in llex()
402 switch (ls->current) { in llex()
404 inclinenumber(ls); in llex()
408 next(ls); in llex()
412 next(ls); in llex()
413 if (ls->current != '-') return '-'; in llex()
415 next(ls); in llex()
416 if (ls->current == '[') { /* long comment? */ in llex()
417 int sep = skip_sep(ls); in llex()
418 luaZ_resetbuffer(ls->buff); /* `skip_sep' may dirty the buffer */ in llex()
420 read_long_string(ls, NULL, sep); /* skip long comment */ in llex()
421 luaZ_resetbuffer(ls->buff); /* previous call may dirty the buff. */ in llex()
426 while (!currIsNewline(ls) && ls->current != EOZ) in llex()
427 next(ls); /* skip until end of line (or end of file) */ in llex()
431 int sep = skip_sep(ls); in llex()
433 read_long_string(ls, seminfo, sep); in llex()
437 else lexerror(ls, "invalid long string delimiter", TK_STRING); in llex()
440 next(ls); in llex()
441 if (ls->current != '=') return '='; in llex()
442 else { next(ls); return TK_EQ; } in llex()
445 next(ls); in llex()
446 if (ls->current != '=') return '<'; in llex()
447 else { next(ls); return TK_LE; } in llex()
450 next(ls); in llex()
451 if (ls->current != '=') return '>'; in llex()
452 else { next(ls); return TK_GE; } in llex()
455 next(ls); in llex()
456 if (ls->current != '=') return '~'; in llex()
457 else { next(ls); return TK_NE; } in llex()
460 next(ls); in llex()
461 if (ls->current != ':') return ':'; in llex()
462 else { next(ls); return TK_DBCOLON; } in llex()
465 read_string(ls, ls->current, seminfo); in llex()
469 save_and_next(ls); in llex()
470 if (check_next(ls, ".")) { in llex()
471 if (check_next(ls, ".")) in llex()
475 else if (!lisdigit(ls->current)) return '.'; in llex()
481 read_numeral(ls, seminfo); in llex()
488 if (lislalpha(ls->current)) { /* identifier or reserved word? */ in llex()
491 save_and_next(ls); in llex()
492 } while (lislalnum(ls->current)); in llex()
493 ts = luaX_newstring(ls, luaZ_buffer(ls->buff), in llex()
494 luaZ_bufflen(ls->buff)); in llex()
503 int c = ls->current; in llex()
504 next(ls); in llex()
513 void luaX_next (LexState *ls) { in luaX_next() argument
514 ls->lastline = ls->linenumber; in luaX_next()
515 if (ls->lookahead.token != TK_EOS) { /* is there a look-ahead token? */ in luaX_next()
516 ls->t = ls->lookahead; /* use this one */ in luaX_next()
517 ls->lookahead.token = TK_EOS; /* and discharge it */ in luaX_next()
520 ls->t.token = llex(ls, &ls->t.seminfo); /* read next token */ in luaX_next()
524 int luaX_lookahead (LexState *ls) { in luaX_lookahead() argument
525 lua_assert(ls->lookahead.token == TK_EOS); in luaX_lookahead()
526 ls->lookahead.token = llex(ls, &ls->lookahead.seminfo); in luaX_lookahead()
527 return ls->lookahead.token; in luaX_lookahead()