ref: 8c21bb0411c9180520f65a113a9237c4235c6d2a
parent: 228cbca9bef303fa5123346d7e3bd32d74e37eef
author: Tor Andersson <tor@ccxvii.net>
date: Fri Jan 10 06:29:53 EST 2014
Parse array literals with elisions.
--- a/js-parse.c
+++ b/js-parse.c
@@ -86,23 +86,22 @@
return NULL;
}
+static js_Ast *arrayelement(js_State *J)
+{
+ if (J->lookahead == ',')
+ return EXP0(NULL); /* TODO: should be 'undefined' */
+ return assignment(J, 0);
+}
+
static js_Ast *arrayliteral(js_State *J)
{
js_Ast *head, *tail;
-
- while (J->lookahead == ',')
- next(J);
-
if (J->lookahead == ']')
return NULL;
-
- head = tail = LIST(assignment(J, 0));
+ head = tail = LIST(arrayelement(J));
while (accept(J, ',')) {
- while (J->lookahead == ',')
- next(J);
- if (J->lookahead == ']')
- break;
- tail = tail->b = LIST(assignment(J, 0));
+ if (J->lookahead != ']')
+ tail = tail->b = LIST(arrayelement(J));
}
return head;
}