Support default case in the non-last position

This commit is contained in:
Jason Turner 2015-10-15 15:02:49 -06:00
parent 64dd349e32
commit 84e2d449b9
3 changed files with 21 additions and 1 deletions

View File

@ -950,7 +950,7 @@ namespace chaiscript
} }
else if (this->children[currentCase]->identifier == AST_Node_Type::Default) { else if (this->children[currentCase]->identifier == AST_Node_Type::Default) {
this->children[currentCase]->eval(t_ss); this->children[currentCase]->eval(t_ss);
breaking = true; hasMatched = true;
} }
} }
catch (detail::Break_Loop &) { catch (detail::Break_Loop &) {

View File

@ -1807,6 +1807,8 @@ namespace chaiscript
build_match<eval::Case_AST_Node>(prev_stack_top); build_match<eval::Case_AST_Node>(prev_stack_top);
} else if (Keyword("default")) { } else if (Keyword("default")) {
retval = true;
while (Eol()) {} while (Eol()) {}
if (!Block()) { if (!Block()) {

View File

@ -0,0 +1,18 @@
var total = 0;
switch(2) {
case (1) {
total += 1;
}
default {
total += 16;
}
case (3) {
total += 4;
}
case (4) {
total += 8;
}
}
assert_equal(total, 28)