| 275 | |
| 276 | static int llex (LexState *ls, SemInfo *seminfo, int *column); |
| 277 | void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source, |
| 278 | int firstchar) { |
| 279 | ls->t.token = 0; |
| 280 | ls->L = L; |
| 281 | ls->current = firstchar; |
| 282 | ls->z = z; |
| 283 | ls->fs = NULL; |
| 284 | ls->source = source; |
| 285 | ls->envn = luaS_newliteral(L, LUA_ENV); /* get env string */ |
| 286 | #if defined(LUA_COMPAT_GLOBAL) |
| 287 | /* compatibility mode: "global" is not a reserved word */ |
| 288 | ls->glbn = luaS_newliteral(L, "global"); /* get "global" string */ |
| 289 | ls->glbn->extra = 0; /* mark it as not reserved */ |
| 290 | #endif |
| 291 | luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */ |
| 292 | |
| 293 | ls->warnconfs.emplace_back(WarningConfig(G(L))); |
| 294 | |
| 295 | while (true) { /* perform lexer pass */ |
| 296 | Token t; |
| 297 | t.column = (int)ls->getLineBuff().size(); |
| 298 | t.token = llex(ls, &t.seminfo, &t.column); |
| 299 | t.line = (int)ls->lines.size(); |
| 300 | ls->tokens.emplace_back(std::move(t)); |
| 301 | if (t.token == TK_EOS) break; |
| 302 | } |
| 303 | |
| 304 | /* preprocessor */ |
| 305 | for (auto i = ls->tokens.begin(); i != ls->tokens.end(); ) { |
| 306 | if (i->token == '$' && (i + 1)->token == TK_NAME) { |
| 307 | const char *directive = getstr((i + 1)->seminfo.ts); |
| 308 | if (strcmp(directive, "alias") == 0) { |
| 309 | const auto directive_begin = i; |
| 310 | i += 2; /* skip '$alias' */ |
| 311 | if (l_unlikely(i->token != TK_NAME)) { |
| 312 | ls->tidx = std::distance(ls->tokens.begin(), i); |
| 313 | luaX_syntaxerror(ls, "expected name after $alias"); |
| 314 | } |
| 315 | Macro& macro = ls->macros.emplace(i->seminfo.ts, Macro{}).first->second; |
| 316 | ++i; /* skip name */ |
| 317 | if (i->token == '(') { |
| 318 | macro.functionlike = true; |
| 319 | do { |
| 320 | ++i; /* skip '(' or ',' */ |
| 321 | if (l_unlikely(i->token != TK_NAME)) { |
| 322 | ls->tidx = std::distance(ls->tokens.begin(), i); |
| 323 | luaX_syntaxerror(ls, "expected parameter name for function-like alias"); |
| 324 | } |
| 325 | macro.params.emplace_back(i->seminfo.ts); |
| 326 | ++i; /* skip name */ |
| 327 | } while (i->token == ','); |
| 328 | if (l_unlikely(i->token != ')')) { |
| 329 | ls->tidx = std::distance(ls->tokens.begin(), i); |
| 330 | luaX_syntaxerror(ls, "expected ')' after parameter list for function-like alias"); |
| 331 | } |
| 332 | ++i; /* skip ')' */ |
| 333 | } |
| 334 | if (l_unlikely(i->token != '=')) { |
no test coverage detected