ref: bd0724eccecfb0ea9651cf8d5b5f8d6bfaca6e4c
parent: 3b0bbade8ba3efecdeea39c2804f65016b3b4831
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Jan 25 07:58:33 EST 2015
Allow trailing commas in seq literals. struct foo = [.x=1,.y=2,.z=3,] now works.
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -756,14 +756,18 @@
| /* 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,7 +776,6 @@
}
| arrayelts Tcomma optendlns arrayelt
{lappend(&$$.nl, &$$.nn, mkidxinit($4->loc, mkint($4->loc, $$.nn), $4));}
- | arrayelts Tcomma optendlns
;
arrayelt: expr optendlns {$$ = $1;}
@@ -779,17 +782,17 @@
;
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 */