diff options
Diffstat (limited to 'lparser.c')
-rw-r--r-- | lparser.c | 23 |
1 files changed, 13 insertions, 10 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 1.144 2001/06/05 19:27:32 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.145 2001/06/07 14:44:51 roberto Exp roberto $ |
3 | ** LL(1) Parser and code generator for Lua | 3 | ** LL(1) Parser and code generator for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -492,16 +492,20 @@ static void recfield (LexState *ls, expdesc *t) { | |||
492 | } | 492 | } |
493 | 493 | ||
494 | 494 | ||
495 | static int anotherfield (LexState *ls) { | ||
496 | if (ls->t.token != l_c(',')) return 0; | ||
497 | next(ls); /* skip the comma */ | ||
498 | return (ls->t.token != l_c(';') && ls->t.token != l_c('}')); | ||
499 | } | ||
500 | |||
501 | |||
495 | static int recfields (LexState *ls, expdesc *t) { | 502 | static int recfields (LexState *ls, expdesc *t) { |
496 | /* recfields -> recfield { `,' recfield } [`,'] */ | 503 | /* recfields -> recfield { `,' recfield } [`,'] */ |
497 | int n = 1; /* at least one element */ | 504 | int n = 0; |
498 | recfield(ls, t); | 505 | do { /* at least one element */ |
499 | while (ls->t.token == l_c(',')) { | ||
500 | next(ls); | ||
501 | if (ls->t.token == l_c(';') || ls->t.token == l_c('}')) break; | ||
502 | recfield(ls, t); | 506 | recfield(ls, t); |
503 | n++; | 507 | n++; |
504 | } | 508 | } while (anotherfield(ls)); |
505 | return n; | 509 | return n; |
506 | } | 510 | } |
507 | 511 | ||
@@ -514,13 +518,12 @@ static int listfields (LexState *ls, expdesc *t) { | |||
514 | int reg; | 518 | int reg; |
515 | reg = fs->freereg; | 519 | reg = fs->freereg; |
516 | expr(ls, &v); | 520 | expr(ls, &v); |
517 | while (ls->t.token == l_c(',') && | 521 | while (anotherfield(ls)) { |
518 | (next(ls), (ls->t.token != l_c(';') && ls->t.token != l_c('}')))) { | ||
519 | luaK_exp2nextreg(fs, &v); | 522 | luaK_exp2nextreg(fs, &v); |
520 | luaX_checklimit(ls, n, MAXARG_Bc, | 523 | luaX_checklimit(ls, n, MAXARG_Bc, |
521 | l_s("`item groups' in a list initializer")); | 524 | l_s("`item groups' in a list initializer")); |
522 | if (n%LFIELDS_PER_FLUSH == 0) { | 525 | if (n%LFIELDS_PER_FLUSH == 0) { |
523 | luaK_codeABc(fs, OP_SETLIST, t->u.i.info, n-1); | 526 | luaK_codeABc(fs, OP_SETLIST, t->u.i.info, n-1); /* flush */ |
524 | fs->freereg = reg; /* free registers */ | 527 | fs->freereg = reg; /* free registers */ |
525 | } | 528 | } |
526 | expr(ls, &v); | 529 | expr(ls, &v); |