Lines Matching full:ls
25 #define next(ls) (ls->current = zgetc(ls->z)) argument
29 #define currIsNewline(ls) (ls->current == '\n' || ls->current == '\r') argument
43 #define save_and_next(ls) (save(ls, ls->current), next(ls)) argument
46 static l_noret lexerror (LexState *ls, const char *msg, int token);
49 static void save (LexState *ls, int c) { in save() argument
50 Mbuffer *b = ls->buff; in save()
54 lexerror(ls, "lexical element too long", 0); in save()
56 luaZ_resizebuffer(ls->L, b, newsize); in save()
72 const char *luaX_token2str (LexState *ls, int token) { in luaX_token2str() argument
75 return (lisprint(token)) ? luaO_pushfstring(ls->L, LUA_QL("%c"), token) : in luaX_token2str()
76 luaO_pushfstring(ls->L, "char(%d)", token); in luaX_token2str()
81 return luaO_pushfstring(ls->L, LUA_QS, s); in luaX_token2str()
88 static const char *txtToken (LexState *ls, int token) { in txtToken() argument
93 save(ls, '\0'); in txtToken()
94 return luaO_pushfstring(ls->L, LUA_QS, luaZ_buffer(ls->buff)); in txtToken()
96 return luaX_token2str(ls, token); in txtToken()
101 static l_noret lexerror (LexState *ls, const char *msg, int token) { in lexerror() argument
103 luaO_chunkid(buff, getstr(ls->source), LUA_IDSIZE); in lexerror()
104 msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg); in lexerror()
106 luaO_pushfstring(ls->L, "%s near %s", msg, txtToken(ls, token)); in lexerror()
107 luaD_throw(ls->L, LUA_ERRSYNTAX); in lexerror()
111 l_noret luaX_syntaxerror (LexState *ls, const char *msg) { in luaX_syntaxerror() argument
112 lexerror(ls, msg, ls->t.token); in luaX_syntaxerror()
121 TString *luaX_newstring (LexState *ls, const char *str, size_t l) { in luaX_newstring() argument
122 lua_State *L = ls->L; in luaX_newstring()
126 o = luaH_set(L, ls->fs->h, L->top - 1); in luaX_newstring()
145 static void inclinenumber (LexState *ls) { in inclinenumber() argument
146 int old = ls->current; in inclinenumber()
147 lua_assert(currIsNewline(ls)); in inclinenumber()
148 next(ls); /* skip `\n' or `\r' */ in inclinenumber()
149 if (currIsNewline(ls) && ls->current != old) in inclinenumber()
150 next(ls); /* skip `\n\r' or `\r\n' */ in inclinenumber()
151 if (++ls->linenumber >= MAX_INT) in inclinenumber()
152 lexerror(ls, "chunk has too many lines", 0); in inclinenumber()
156 void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source, in luaX_setinput() argument
158 ls->decpoint = '.'; in luaX_setinput()
159 ls->L = L; in luaX_setinput()
160 ls->current = firstchar; in luaX_setinput()
161 ls->lookahead.token = TK_EOS; /* no look-ahead token */ in luaX_setinput()
162 ls->z = z; in luaX_setinput()
163 ls->fs = NULL; in luaX_setinput()
164 ls->linenumber = 1; in luaX_setinput()
165 ls->lastline = 1; in luaX_setinput()
166 ls->source = source; in luaX_setinput()
167 ls->envn = luaS_new(L, LUA_ENV); /* create env name */ in luaX_setinput()
168 luaS_fix(ls->envn); /* never collect this name */ in luaX_setinput()
169 luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */ in luaX_setinput()
182 static int check_next (LexState *ls, const char *set) { in check_next() argument
183 if (ls->current == '\0' || !strchr(set, ls->current)) in check_next()
185 save_and_next(ls); in check_next()
193 static void buffreplace (LexState *ls, char from, char to) { in buffreplace() argument
194 size_t n = luaZ_bufflen(ls->buff); in buffreplace()
195 char *p = luaZ_buffer(ls->buff); in buffreplace()
212 static void trydecpoint (LexState *ls, SemInfo *seminfo) { in trydecpoint() argument
213 char old = ls->decpoint; in trydecpoint()
214 ls->decpoint = getlocaledecpoint(); in trydecpoint()
215 buffreplace(ls, old, ls->decpoint); /* try new decimal separator */ in trydecpoint()
216 if (!buff2d(ls->buff, &seminfo->r)) { in trydecpoint()
218 buffreplace(ls, ls->decpoint, '.'); /* undo change (for error message) */ in trydecpoint()
219 lexerror(ls, "malformed number", TK_NUMBER); in trydecpoint()
229 static void read_numeral (LexState *ls, SemInfo *seminfo) { in read_numeral() argument
231 int first = ls->current; in read_numeral()
232 lua_assert(lisdigit(ls->current)); in read_numeral()
233 save_and_next(ls); in read_numeral()
234 if (first == '0' && check_next(ls, "Xx")) /* hexadecimal? */ in read_numeral()
237 if (check_next(ls, expo)) /* exponent part? */ in read_numeral()
238 (void) check_next(ls, "+-"); /* optional exponent sign */ in read_numeral()
239 if (lisxdigit(ls->current) || ls->current == '.') in read_numeral()
240 save_and_next(ls); in read_numeral()
243 save(ls, '\0'); in read_numeral()
244 buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */ in read_numeral()
245 if (!buff2d(ls->buff, &seminfo->r)) /* format error? */ in read_numeral()
246 trydecpoint(ls, seminfo); /* try to update decimal point separator */ in read_numeral()
254 static int skip_sep (LexState *ls) { in skip_sep() argument
256 int s = ls->current; in skip_sep()
258 save_and_next(ls); in skip_sep()
259 while (ls->current == '=') { in skip_sep()
260 save_and_next(ls); in skip_sep()
263 return (ls->current == s) ? count : (-count) - 1; in skip_sep()
267 static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) { in read_long_string() argument
268 save_and_next(ls); /* skip 2nd `[' */ in read_long_string()
269 if (currIsNewline(ls)) /* string starts with a newline? */ in read_long_string()
270 inclinenumber(ls); /* skip it */ in read_long_string()
272 switch (ls->current) { in read_long_string()
274 lexerror(ls, (seminfo) ? "unfinished long string" : in read_long_string()
278 if (skip_sep(ls) == sep) { in read_long_string()
279 save_and_next(ls); /* skip 2nd `]' */ in read_long_string()
285 save(ls, '\n'); in read_long_string()
286 inclinenumber(ls); in read_long_string()
287 if (!seminfo) luaZ_resetbuffer(ls->buff); /* avoid wasting space */ in read_long_string()
291 if (seminfo) save_and_next(ls); in read_long_string()
292 else next(ls); in read_long_string()
297 seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + sep), in read_long_string()
298 luaZ_bufflen(ls->buff) - 2*(2 + sep)); in read_long_string()
302 static void escerror (LexState *ls, int *c, int n, const char *msg) { in escerror() argument
304 luaZ_resetbuffer(ls->buff); /* prepare error message */ in escerror()
305 save(ls, '\\'); in escerror()
307 save(ls, c[i]); in escerror()
308 lexerror(ls, msg, TK_STRING); in escerror()
312 static int readhexaesc (LexState *ls) { in readhexaesc() argument
317 c[i] = next(ls); in readhexaesc()
319 escerror(ls, c, i + 1, "hexadecimal digit expected"); in readhexaesc()
326 static int readdecesc (LexState *ls) { in readdecesc() argument
329 for (i = 0; i < 3 && lisdigit(ls->current); i++) { /* read up to 3 digits */ in readdecesc()
330 c[i] = ls->current; in readdecesc()
332 next(ls); in readdecesc()
335 escerror(ls, c, i, "decimal escape too large"); in readdecesc()
340 static void read_string (LexState *ls, int del, SemInfo *seminfo) { in read_string() argument
341 save_and_next(ls); /* keep delimiter (for error messages) */ in read_string()
342 while (ls->current != del) { in read_string()
343 switch (ls->current) { in read_string()
345 lexerror(ls, "unfinished string", TK_EOS); in read_string()
349 lexerror(ls, "unfinished string", TK_STRING); in read_string()
353 next(ls); /* do not save the `\' */ in read_string()
354 switch (ls->current) { in read_string()
362 case 'x': c = readhexaesc(ls); goto read_save; in read_string()
364 inclinenumber(ls); c = '\n'; goto only_save; in read_string()
366 c = ls->current; goto read_save; in read_string()
369 next(ls); /* skip the 'z' */ in read_string()
370 while (lisspace(ls->current)) { in read_string()
371 if (currIsNewline(ls)) inclinenumber(ls); in read_string()
372 else next(ls); in read_string()
377 if (!lisdigit(ls->current)) in read_string()
378 escerror(ls, &ls->current, 1, "invalid escape sequence"); in read_string()
380 c = readdecesc(ls); in read_string()
384 read_save: next(ls); /* read next character */ in read_string()
385 only_save: save(ls, c); /* save 'c' */ in read_string()
389 save_and_next(ls); in read_string()
392 save_and_next(ls); /* skip delimiter */ in read_string()
393 seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1, in read_string()
394 luaZ_bufflen(ls->buff) - 2); in read_string()
398 static int llex (LexState *ls, SemInfo *seminfo) { in llex() argument
399 luaZ_resetbuffer(ls->buff); in llex()
401 switch (ls->current) { in llex()
403 inclinenumber(ls); in llex()
407 next(ls); in llex()
411 next(ls); in llex()
412 if (ls->current != '-') return '-'; in llex()
414 next(ls); in llex()
415 if (ls->current == '[') { /* long comment? */ in llex()
416 int sep = skip_sep(ls); in llex()
417 luaZ_resetbuffer(ls->buff); /* `skip_sep' may dirty the buffer */ in llex()
419 read_long_string(ls, NULL, sep); /* skip long comment */ in llex()
420 luaZ_resetbuffer(ls->buff); /* previous call may dirty the buff. */ in llex()
425 while (!currIsNewline(ls) && ls->current != EOZ) in llex()
426 next(ls); /* skip until end of line (or end of file) */ in llex()
430 int sep = skip_sep(ls); in llex()
432 read_long_string(ls, seminfo, sep); in llex()
437 lexerror(ls, "invalid long string delimiter", TK_STRING); in llex()
442 next(ls); in llex()
443 if (ls->current != '=') return '='; in llex()
444 else { next(ls); return TK_EQ; } in llex()
447 next(ls); in llex()
448 if (ls->current != '=') return '<'; in llex()
449 else { next(ls); return TK_LE; } in llex()
452 next(ls); in llex()
453 if (ls->current != '=') return '>'; in llex()
454 else { next(ls); return TK_GE; } in llex()
457 next(ls); in llex()
458 if (ls->current != '=') return '~'; in llex()
459 else { next(ls); return TK_NE; } in llex()
462 next(ls); in llex()
463 if (ls->current != ':') return ':'; in llex()
464 else { next(ls); return TK_DBCOLON; } in llex()
467 read_string(ls, ls->current, seminfo); in llex()
471 save_and_next(ls); in llex()
472 if (check_next(ls, ".")) { in llex()
473 if (check_next(ls, ".")) in llex()
477 else if (!lisdigit(ls->current)) return '.'; in llex()
483 read_numeral(ls, seminfo); in llex()
490 if (lislalpha(ls->current)) { /* identifier or reserved word? */ in llex()
493 save_and_next(ls); in llex()
494 } while (lislalnum(ls->current)); in llex()
495 ts = luaX_newstring(ls, luaZ_buffer(ls->buff), in llex()
496 luaZ_bufflen(ls->buff)); in llex()
505 int c = ls->current; in llex()
506 next(ls); in llex()
515 void luaX_next (LexState *ls) { in luaX_next() argument
516 ls->lastline = ls->linenumber; in luaX_next()
517 if (ls->lookahead.token != TK_EOS) { /* is there a look-ahead token? */ in luaX_next()
518 ls->t = ls->lookahead; /* use this one */ in luaX_next()
519 ls->lookahead.token = TK_EOS; /* and discharge it */ in luaX_next()
522 ls->t.token = llex(ls, &ls->t.seminfo); /* read next token */ in luaX_next()
526 int luaX_lookahead (LexState *ls) { in luaX_lookahead() argument
527 lua_assert(ls->lookahead.token == TK_EOS); in luaX_lookahead()
528 ls->lookahead.token = llex(ls, &ls->lookahead.seminfo); in luaX_lookahead()
529 return ls->lookahead.token; in luaX_lookahead()