Skip to content

Commit

Permalink
Details in lparser.c
Browse files Browse the repository at this point in the history
Added comments so that all braces pair correctly. (The parser has
several instances of unmatched braces as characters ('{' or '}'), which
hinders matching regular braces in the code.)
  • Loading branch information
roberto-ieru committed Jan 10, 2025
1 parent 429761d commit 4b107a8
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions lparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -797,10 +797,11 @@ static void close_func (LexState *ls) {
}



/*============================================================*/
/* GRAMMAR RULES */
/*============================================================*/
/*
** {======================================================================
** GRAMMAR RULES
** =======================================================================
*/


/*
Expand Down Expand Up @@ -974,15 +975,15 @@ static void constructor (LexState *ls, expdesc *t) {
init_exp(t, VNONRELOC, fs->freereg); /* table will be at stack top */
luaK_reserveregs(fs, 1);
init_exp(&cc.v, VVOID, 0); /* no value (yet) */
checknext(ls, '{');
checknext(ls, '{' /*}*/);
cc.maxtostore = maxtostore(fs);
do {
lua_assert(cc.v.k == VVOID || cc.tostore > 0);
if (ls->t.token == '}') break;
if (ls->t.token == /*{*/ '}') break;
closelistfield(fs, &cc);
field(ls, &cc);
} while (testnext(ls, ',') || testnext(ls, ';'));
check_match(ls, '}', '{', line);
check_match(ls, /*{*/ '}', '{' /*}*/, line);
lastlistfield(fs, &cc);
luaK_settablesize(fs, pc, t->u.info, cc.na, cc.nh);
}
Expand Down Expand Up @@ -1080,7 +1081,7 @@ static void funcargs (LexState *ls, expdesc *f) {
check_match(ls, ')', '(', line);
break;
}
case '{': { /* funcargs -> constructor */
case '{' /*}*/: { /* funcargs -> constructor */
constructor(ls, &args);
break;
}
Expand Down Expand Up @@ -1167,7 +1168,7 @@ static void suffixedexp (LexState *ls, expdesc *v) {
funcargs(ls, v);
break;
}
case '(': case TK_STRING: case '{': { /* funcargs */
case '(': case TK_STRING: case '{' /*}*/: { /* funcargs */
luaK_exp2nextreg(fs, v);
funcargs(ls, v);
break;
Expand Down Expand Up @@ -1215,7 +1216,7 @@ static void simpleexp (LexState *ls, expdesc *v) {
init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 0, 1));
break;
}
case '{': { /* constructor */
case '{' /*}*/: { /* constructor */
constructor(ls, v);
return;
}
Expand Down Expand Up @@ -1922,6 +1923,8 @@ static void statement (LexState *ls) {

/* }====================================================================== */

/* }====================================================================== */


/*
** compiles the main function, which is a regular vararg function with an
Expand Down

0 comments on commit 4b107a8

Please sign in to comment.