From 10d64945d5d2676cb03ab7062a157771a2197523 Mon Sep 17 00:00:00 2001 From: Nicolas Cannasse Date: Mon, 15 Sep 2014 11:55:57 +0200 Subject: [PATCH] fixed ESwitch parsing : allow several expressions in case/default block --- hscript/Parser.hx | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/hscript/Parser.hx b/hscript/Parser.hx index 4eade93..c1c74f6 100644 --- a/hscript/Parser.hx +++ b/hscript/Parser.hx @@ -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: