Lines Matching refs:ls

32 #define next(ls) (ls->current = zgetc(ls->z))  argument
36 #define currIsNewline(ls) (ls->current == '\n' || ls->current == '\r') argument
50 #define save_and_next(ls) (save(ls, ls->current), next(ls)) argument
53 static l_noret lexerror (LexState *ls, const char *msg, int token);
56 static void save (LexState *ls, int c) { in save() argument
57 Mbuffer *b = ls->buff; in save()
61 lexerror(ls, "lexical element too long", 0); in save()
63 luaZ_resizebuffer(ls->L, b, newsize); in save()
79 const char *luaX_token2str (LexState *ls, int token) { in luaX_token2str() argument
82 return (lisprint(token)) ? luaO_pushfstring(ls->L, LUA_QL("%c"), token) : in luaX_token2str()
83 luaO_pushfstring(ls->L, "char(%d)", token); in luaX_token2str()
88 return luaO_pushfstring(ls->L, LUA_QS, s); in luaX_token2str()
95 static const char *txtToken (LexState *ls, int token) { in txtToken() argument
100 save(ls, '\0'); in txtToken()
101 return luaO_pushfstring(ls->L, LUA_QS, luaZ_buffer(ls->buff)); in txtToken()
103 return luaX_token2str(ls, token); in txtToken()
108 static l_noret lexerror (LexState *ls, const char *msg, int token) { in lexerror() argument
110 luaO_chunkid(buff, getstr(ls->source), LUA_IDSIZE); in lexerror()
111 msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg); in lexerror()
113 luaO_pushfstring(ls->L, "%s near %s", msg, txtToken(ls, token)); in lexerror()
114 luaD_throw(ls->L, LUA_ERRSYNTAX); in lexerror()
118 l_noret luaX_syntaxerror (LexState *ls, const char *msg) { in luaX_syntaxerror() argument
119 lexerror(ls, msg, ls->t.token); in luaX_syntaxerror()
128 TString *luaX_newstring (LexState *ls, const char *str, size_t l) { in luaX_newstring() argument
129 lua_State *L = ls->L; in luaX_newstring()
133 o = luaH_set(L, ls->fs->h, L->top - 1); in luaX_newstring()
152 static void inclinenumber (LexState *ls) { in inclinenumber() argument
153 int old = ls->current; in inclinenumber()
154 lua_assert(currIsNewline(ls)); in inclinenumber()
155 next(ls); /* skip `\n' or `\r' */ in inclinenumber()
156 if (currIsNewline(ls) && ls->current != old) in inclinenumber()
157 next(ls); /* skip `\n\r' or `\r\n' */ in inclinenumber()
158 if (++ls->linenumber >= MAX_INT) in inclinenumber()
159 luaX_syntaxerror(ls, "chunk has too many lines"); in inclinenumber()
163 void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source, in luaX_setinput() argument
165 ls->decpoint = '.'; in luaX_setinput()
166 ls->L = L; in luaX_setinput()
167 ls->current = firstchar; in luaX_setinput()
168 ls->lookahead.token = TK_EOS; /* no look-ahead token */ in luaX_setinput()
169 ls->z = z; in luaX_setinput()
170 ls->fs = NULL; in luaX_setinput()
171 ls->linenumber = 1; in luaX_setinput()
172 ls->lastline = 1; in luaX_setinput()
173 ls->source = source; in luaX_setinput()
174 ls->envn = luaS_new(L, LUA_ENV); /* create env name */ in luaX_setinput()
175 luaS_fix(ls->envn); /* never collect this name */ in luaX_setinput()
176 luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */ in luaX_setinput()
189 static int check_next (LexState *ls, const char *set) { in check_next() argument
190 if (ls->current == '\0' || !strchr(set, ls->current)) in check_next()
192 save_and_next(ls); in check_next()
200 static void buffreplace (LexState *ls, char from, char to) { in buffreplace() argument
201 size_t n = luaZ_bufflen(ls->buff); in buffreplace()
202 char *p = luaZ_buffer(ls->buff); in buffreplace()
219 static void trydecpoint (LexState *ls, SemInfo *seminfo) { in trydecpoint() argument
220 char old = ls->decpoint; in trydecpoint()
221 ls->decpoint = getlocaledecpoint(); in trydecpoint()
222 buffreplace(ls, old, ls->decpoint); /* try new decimal separator */ in trydecpoint()
223 if (!buff2d(ls->buff, &seminfo->r)) { in trydecpoint()
225 buffreplace(ls, ls->decpoint, '.'); /* undo change (for error message) */ in trydecpoint()
226 lexerror(ls, "malformed number", TK_NUMBER); in trydecpoint()
236 static void read_numeral (LexState *ls, SemInfo *seminfo) { in read_numeral() argument
238 int first = ls->current; in read_numeral()
239 lua_assert(lisdigit(ls->current)); in read_numeral()
240 save_and_next(ls); in read_numeral()
241 if (first == '0' && check_next(ls, "Xx")) /* hexadecimal? */ in read_numeral()
244 if (check_next(ls, expo)) /* exponent part? */ in read_numeral()
245 check_next(ls, "+-"); /* optional exponent sign */ in read_numeral()
246 if (lisxdigit(ls->current) || ls->current == '.') in read_numeral()
247 save_and_next(ls); in read_numeral()
250 save(ls, '\0'); in read_numeral()
251 buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */ in read_numeral()
252 if (!buff2d(ls->buff, &seminfo->r)) /* format error? */ in read_numeral()
253 trydecpoint(ls, seminfo); /* try to update decimal point separator */ in read_numeral()
261 static int skip_sep (LexState *ls) { in skip_sep() argument
263 int s = ls->current; in skip_sep()
265 save_and_next(ls); in skip_sep()
266 while (ls->current == '=') { in skip_sep()
267 save_and_next(ls); in skip_sep()
270 return (ls->current == s) ? count : (-count) - 1; in skip_sep()
274 static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) { in read_long_string() argument
275 save_and_next(ls); /* skip 2nd `[' */ in read_long_string()
276 if (currIsNewline(ls)) /* string starts with a newline? */ in read_long_string()
277 inclinenumber(ls); /* skip it */ in read_long_string()
279 switch (ls->current) { in read_long_string()
281 lexerror(ls, (seminfo) ? "unfinished long string" : in read_long_string()
285 if (skip_sep(ls) == sep) { in read_long_string()
286 save_and_next(ls); /* skip 2nd `]' */ in read_long_string()
292 save(ls, '\n'); in read_long_string()
293 inclinenumber(ls); in read_long_string()
294 if (!seminfo) luaZ_resetbuffer(ls->buff); /* avoid wasting space */ in read_long_string()
298 if (seminfo) save_and_next(ls); in read_long_string()
299 else next(ls); in read_long_string()
304 seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + sep), in read_long_string()
305 luaZ_bufflen(ls->buff) - 2*(2 + sep)); in read_long_string()
309 static void escerror (LexState *ls, int *c, int n, const char *msg) { in escerror() argument
311 luaZ_resetbuffer(ls->buff); /* prepare error message */ in escerror()
312 save(ls, '\\'); in escerror()
314 save(ls, c[i]); in escerror()
315 lexerror(ls, msg, TK_STRING); in escerror()
319 static int readhexaesc (LexState *ls) { in readhexaesc() argument
324 c[i] = next(ls); in readhexaesc()
326 escerror(ls, c, i + 1, "hexadecimal digit expected"); in readhexaesc()
333 static int readdecesc (LexState *ls) { in readdecesc() argument
336 for (i = 0; i < 3 && lisdigit(ls->current); i++) { /* read up to 3 digits */ in readdecesc()
337 c[i] = ls->current; in readdecesc()
339 next(ls); in readdecesc()
342 escerror(ls, c, i, "decimal escape too large"); in readdecesc()
347 static void read_string (LexState *ls, int del, SemInfo *seminfo) { in read_string() argument
348 save_and_next(ls); /* keep delimiter (for error messages) */ in read_string()
349 while (ls->current != del) { in read_string()
350 switch (ls->current) { in read_string()
352 lexerror(ls, "unfinished string", TK_EOS); in read_string()
356 lexerror(ls, "unfinished string", TK_STRING); in read_string()
360 next(ls); /* do not save the `\' */ in read_string()
361 switch (ls->current) { in read_string()
369 case 'x': c = readhexaesc(ls); goto read_save; in read_string()
371 inclinenumber(ls); c = '\n'; goto only_save; in read_string()
373 c = ls->current; goto read_save; in read_string()
376 next(ls); /* skip the 'z' */ in read_string()
377 while (lisspace(ls->current)) { in read_string()
378 if (currIsNewline(ls)) inclinenumber(ls); in read_string()
379 else next(ls); in read_string()
384 if (!lisdigit(ls->current)) in read_string()
385 escerror(ls, &ls->current, 1, "invalid escape sequence"); in read_string()
387 c = readdecesc(ls); in read_string()
391 read_save: next(ls); /* read next character */ in read_string()
392 only_save: save(ls, c); /* save 'c' */ in read_string()
396 save_and_next(ls); in read_string()
399 save_and_next(ls); /* skip delimiter */ in read_string()
400 seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1, in read_string()
401 luaZ_bufflen(ls->buff) - 2); in read_string()
405 static int llex (LexState *ls, SemInfo *seminfo) { in llex() argument
406 luaZ_resetbuffer(ls->buff); in llex()
408 switch (ls->current) { in llex()
410 inclinenumber(ls); in llex()
414 next(ls); in llex()
418 next(ls); in llex()
419 if (ls->current != '-') return '-'; in llex()
421 next(ls); in llex()
422 if (ls->current == '[') { /* long comment? */ in llex()
423 int sep = skip_sep(ls); in llex()
424 luaZ_resetbuffer(ls->buff); /* `skip_sep' may dirty the buffer */ in llex()
426 read_long_string(ls, NULL, sep); /* skip long comment */ in llex()
427 luaZ_resetbuffer(ls->buff); /* previous call may dirty the buff. */ in llex()
432 while (!currIsNewline(ls) && ls->current != EOZ) in llex()
433 next(ls); /* skip until end of line (or end of file) */ in llex()
437 int sep = skip_sep(ls); in llex()
439 read_long_string(ls, seminfo, sep); in llex()
443 else lexerror(ls, "invalid long string delimiter", TK_STRING); in llex()
446 next(ls); in llex()
447 if (ls->current != '=') return '='; in llex()
448 else { next(ls); return TK_EQ; } in llex()
451 next(ls); in llex()
452 if (ls->current != '=') return '<'; in llex()
453 else { next(ls); return TK_LE; } in llex()
456 next(ls); in llex()
457 if (ls->current != '=') return '>'; in llex()
458 else { next(ls); return TK_GE; } in llex()
461 next(ls); in llex()
462 if (ls->current != '=') return '~'; in llex()
463 else { next(ls); return TK_NE; } in llex()
466 next(ls); in llex()
467 if (ls->current != ':') return ':'; in llex()
468 else { next(ls); return TK_DBCOLON; } in llex()
471 read_string(ls, ls->current, seminfo); in llex()
475 save_and_next(ls); in llex()
476 if (check_next(ls, ".")) { in llex()
477 if (check_next(ls, ".")) in llex()
481 else if (!lisdigit(ls->current)) return '.'; in llex()
486 read_numeral(ls, seminfo); in llex()
493 if (lislalpha(ls->current)) { /* identifier or reserved word? */ in llex()
496 save_and_next(ls); in llex()
497 } while (lislalnum(ls->current)); in llex()
498 ts = luaX_newstring(ls, luaZ_buffer(ls->buff), in llex()
499 luaZ_bufflen(ls->buff)); in llex()
508 int c = ls->current; in llex()
509 next(ls); in llex()
518 void luaX_next (LexState *ls) { in luaX_next() argument
519 ls->lastline = ls->linenumber; in luaX_next()
520 if (ls->lookahead.token != TK_EOS) { /* is there a look-ahead token? */ in luaX_next()
521 ls->t = ls->lookahead; /* use this one */ in luaX_next()
522 ls->lookahead.token = TK_EOS; /* and discharge it */ in luaX_next()
525 ls->t.token = llex(ls, &ls->t.seminfo); /* read next token */ in luaX_next()
529 int luaX_lookahead (LexState *ls) { in luaX_lookahead() argument
530 lua_assert(ls->lookahead.token == TK_EOS); in luaX_lookahead()
531 ls->lookahead.token = llex(ls, &ls->lookahead.seminfo); in luaX_lookahead()
532 return ls->lookahead.token; in luaX_lookahead()