Permalink
Browse files

Allow case statements contains eval-expressions, fixes #768

Fix
  • Loading branch information...
nkt committed May 8, 2015
1 parent 2e1d6ef commit c34fb8fbde5779c07ae1034ee81e5d17d864bc0f
Showing with 55 additions and 2 deletions.
  1. +31 −0 ext/test/flow.zep.c
  2. +7 −0 ext/test/flow.zep.h
  3. +2 −2 parser/parser.lemon
  4. +12 −0 test/flow.zep
  5. +3 −0 unit-tests/Extension/FlowTest.php

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -2270,11 +2270,11 @@ xx_case_clauses(R) ::= xx_case_clause(K) . {
R = xx_ret_list(NULL, K);
}
xx_case_clause(R) ::= CASE xx_literal_expr(E) COLON . {
xx_case_clause(R) ::= CASE xx_eval_expr(E) COLON . {
R = xx_ret_case_clause(E, NULL, status->scanner_state);
}
xx_case_clause(R) ::= CASE xx_literal_expr(E) COLON xx_statement_list(L) . {
xx_case_clause(R) ::= CASE xx_eval_expr(E) COLON xx_statement_list(L) . {
R = xx_ret_case_clause(E, L, status->scanner_state);
}
@@ -925,6 +925,18 @@ class Flow
}
}
public function testSwitch12(var1, var2)
{
switch true {
case var1 > var2 && var2 > 5:
return 1;
case var1 < var2 && var1 < 5:
return 2;
default:
return 0;
}
}
public function testUnrechable1()
{
var a = 0, b = 0.0, c = false, d = "", e = '\0';
@@ -116,5 +116,8 @@ public function testSwitch()
$this->assertEquals($t->testSwitch9(), 2);
$this->assertEquals($t->testSwitch10(), 2);
$this->assertEquals($t->testSwitch11(), 1);
$this->assertEquals($t->testSwitch12(10, 6), 1);
$this->assertEquals($t->testSwitch12(6, 10), 0);
$this->assertEquals($t->testSwitch12(2, 3), 2);
}
}

0 comments on commit c34fb8f

Please sign in to comment.