summaryrefslogtreecommitdiff
path: root/parse
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-01-25 12:58:33 -0800
committerOri Bernstein <ori@eigenstate.org>2015-01-25 12:58:33 -0800
commit3426a0868cf03119797fbf84e2685cdd8905c7d9 (patch)
tree33c7847f7245907ea64a423ab9037d56afa6fc0a /parse
parent40e25ffab9e67040ad007679293ddcb0006889b6 (diff)
downloadmc-3426a0868cf03119797fbf84e2685cdd8905c7d9.tar.gz
Allow trailing commas in seq literals.
struct foo = [.x=1,.y=2,.z=3,] now works.
Diffstat (limited to 'parse')
-rw-r--r--parse/gram.y23
1 files changed, 13 insertions, 10 deletions
diff --git a/parse/gram.y b/parse/gram.y
index bc55053..9d7111f 100644
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -756,14 +756,18 @@ params : declcore {
| /* empty */ {$$.nl = NULL; $$.nn = 0;}
;
-seqlit : Tosqbrac arrayelts Tcsqbrac
+seqlit : Tosqbrac arrayelts optcomma Tcsqbrac
{$$ = mkexprl($1->loc, Oarr, $2.nl, $2.nn);}
- | Tosqbrac structelts Tcsqbrac
+ | Tosqbrac structelts optcomma Tcsqbrac
{$$ = mkexprl($1->loc, Ostruct, $2.nl, $2.nn);}
- | Tosqbrac Tcsqbrac /* [] is the empty array. */
+ | Tosqbrac optendlns optcomma Tcsqbrac /* [] is the empty array. */
{$$ = mkexprl($1->loc, Oarr, NULL, 0);}
;
+optcomma: Tcomma optendlns
+ | /* empty */
+ ;
+
arrayelts
: optendlns arrayelt {
$$.nl = NULL;
@@ -772,24 +776,23 @@ arrayelts
}
| arrayelts Tcomma optendlns arrayelt
{lappend(&$$.nl, &$$.nn, mkidxinit($4->loc, mkint($4->loc, $$.nn), $4));}
- | arrayelts Tcomma optendlns
;
arrayelt: expr optendlns {$$ = $1;}
;
structelts
- : structelt {
+ : optendlns structelt {
$$.nl = NULL;
$$.nn = 0;
- lappend(&$$.nl, &$$.nn, $1);
+ lappend(&$$.nl, &$$.nn, $2);
}
- | structelts Tcomma structelt
- {lappend(&$$.nl, &$$.nn, $3);}
+ | structelts Tcomma optendlns structelt
+ {lappend(&$$.nl, &$$.nn, $4);}
;
-structelt: optendlns Tdot Tident Tasn expr optendlns
- {$$ = mkidxinit($2->loc, mkname($3->loc, $3->id), $5);}
+structelt: Tdot Tident Tasn expr optendlns
+ {$$ = mkidxinit($2->loc, mkname($2->loc, $2->id), $4);}
;
optendlns : /* none */