fixed ESwitch parsing : allow several expressions in case/default block

This commit is contained in:
Nicolas Cannasse
2014-09-15 11:56:08 +02:00
parent 5b7abff256
commit 10d64945d5
+34 -2
View File
@@ -587,11 +587,43 @@ class Parser {
unexpected(tk);
}
}
c.expr = parseFullExpr();
var exprs = [];
while( true ) {
tk = token();
push(tk);
switch( tk ) {
case TId("case"), TId("default"), TBrClose:
break;
default:
exprs.push(parseFullExpr());
}
}
c.expr = if( exprs.length == 1)
exprs[0];
else if( exprs.length == 0 )
mk(EBlock([]), tokenMin, tokenMin);
else
mk(EBlock(exprs), pmin(exprs[0]), pmax(exprs[exprs.length - 1]));
case TId("default"):
if( def != null ) unexpected(tk);
ensure(TSemicolon);
def = parseExpr();
var exprs = [];
while( true ) {
tk = token();
push(tk);
switch( tk ) {
case TId("case"), TId("default"), TBrClose:
break;
default:
exprs.push(parseFullExpr());
}
}
def = if( exprs.length == 1)
exprs[0];
else if( exprs.length == 0 )
mk(EBlock([]), tokenMin, tokenMin);
else
mk(EBlock(exprs), pmin(exprs[0]), pmax(exprs[exprs.length - 1]));
case TBrClose:
break;
default: