MCPcopy Create free account
hub / github.com/PlutoLang/Pluto / enumexp

Function enumexp

src/lparser.cpp:3374–3479  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3372
3373
3374static void enumexp (LexState *ls, expdesc *v, TString *varname) {
3375 switch (ls->t.token) {
3376 case ':': {
3377 luaX_next(ls);
3378#ifdef PLUTO_PARSER_SUGGESTIONS
3379 if (ls->shouldSuggest()) {
3380 SuggestionsState ss(ls);
3381 ss.push("efunc", "values");
3382 ss.push("efunc", "names");
3383 ss.push("efunc", "kvmap");
3384 ss.push("efunc", "vkmap");
3385 }
3386#endif
3387 check(ls, TK_NAME);
3388 if (strcmp(getstr(ls->t.seminfo.ts), "values") == 0) {
3389 luaX_next(ls);
3390 checknext(ls, '('); checknext(ls, ')');
3391 const EnumDesc* ed = &ls->enums.at((size_t)v->u.ival);
3392 size_t i = 0;
3393 newtable(ls, v, [ed, &i](expdesc *e) {
3394 if (i == ed->enumerators.size())
3395 return false;
3396 init_exp(e, VKINT, 0);
3397 e->u.ival = ed->enumerators.at(i++).value;
3398 return true;
3399 });
3400 }
3401 else if (strcmp(getstr(ls->t.seminfo.ts), "names") == 0) {
3402 luaX_next(ls);
3403 checknext(ls, '('); checknext(ls, ')');
3404 const EnumDesc* ed = &ls->enums.at((size_t)v->u.ival);
3405 size_t i = 0;
3406 newtable(ls, v, [ed, &i](expdesc *e) {
3407 if (i == ed->enumerators.size())
3408 return false;
3409 init_exp(e, VKSTR, 0);
3410 e->u.strval = ed->enumerators.at(i++).name;
3411 return true;
3412 });
3413 }
3414 else if (strcmp(getstr(ls->t.seminfo.ts), "kvmap") == 0) {
3415 luaX_next(ls);
3416 checknext(ls, '('); checknext(ls, ')');
3417 const EnumDesc* ed = &ls->enums.at((size_t)v->u.ival);
3418 size_t i = 0;
3419 newtable(ls, v, [ed, &i](expdesc *key, expdesc *val) {
3420 if (i == ed->enumerators.size())
3421 return false;
3422 init_exp(key, VKSTR, 0);
3423 key->u.strval = ed->enumerators.at(i).name;
3424 init_exp(val, VKINT, 0);
3425 val->u.ival = ed->enumerators.at(i).value;
3426 i++;
3427 return true;
3428 });
3429 }
3430 else if (strcmp(getstr(ls->t.seminfo.ts), "vkmap") == 0) {
3431 luaX_next(ls);

Callers 1

primaryexpFunction · 0.85

Calls 11

luaX_nextFunction · 0.85
checkFunction · 0.85
checknextFunction · 0.85
newtableFunction · 0.85
init_expFunction · 0.85
throwerrFunction · 0.85
luaX_getposFunction · 0.85
luaX_token2strFunction · 0.85
shouldSuggestMethod · 0.80
pushMethod · 0.80
sizeMethod · 0.80

Tested by

no test coverage detected