if/else if/else
if/else if/else | Normal Form |
---|---|
rule xxx when { $a : A() if ( v == 1 ) { B() do[t2] } C() } then { ..t1.. } then[t2] { ..t2.. } | rule xxx1 when { $a : A() C() } then { ..t1.. }
rule xxx2 when { $a : A() eval( $a.v == 1) B() } then { ..t2.. } |
if with break | Normal Form |
---|---|
rule xxx when { $a : A() if ( v == 1 ) break { B() do[t2] } C() } then { ..t1.. } then[t2] { ..t2.. } | rule xxx1 when { $a : A() eval( !$a.v == 1) // notice then negation C() } then { ..t1.. }
rule xxx2 when { $a : A() eval( $a.v == 1) B() } then { ..t2.. } |
if/else if/else | Normal Form |
---|---|
rule xxx when { $a : A() if ( v == 1 ) { B() do[t2] } else if ( v == 2 ) { C() do[t3] } else { D() do[t4] } E() } then { ..t1.. } then[t2] { ..t2.. } then[t3] { ..t3.. } then[t4] { ..t3.. } | rule xxx1 when { $a : A() E() } then { ..t1.. }
rule xxx2 when { $a : A() eval( $a.v == 1) B() } then { ..t2.. }
rule xxx3 when { $a : A() eval( ! $a.v == 1 ) eval( $a.v == 2) C() } then { ..t3.. }
rule xxx3 when { $a : A() eval( ! $a.v == 1) eval( ! $a.v == 2) D() } then { ..t4.. } |
if/else if/else | Normal Form |
---|---|
rule xxx when { $a : A() if ( v == 1 ) break { B() do[t2] } else if ( v == 2 ) break { C() do[t3] } else { D() do[t4] // no break here, otherwise it could never reach E() } E() } then { ..t1.. } then[t2] { ..t2.. } then[t3] { ..t3.. } then[t4] { ..t3.. } | rule xxx1 when { $a : A() eval( ! $a.v == 1) eval( ! $a.v == 2) E() } then { ..t1.. }
rule xxx2 when { $a : A() eval( $a.v == 1) B() } then { ..t2.. }
rule xxx3 when { $a : A() eval( ! $a.v == 1) eval( $a.v == 2) C() } then { ..t3.. }
rule xxx3 when { $a : A() eval( ! $a.v == 1) eval( ! $a.v == 2) D() } then { ..t4.. } |
if/else if/else | Normal Form |
---|---|
rule xxx when { $a : A() if ( v == 1 ) { B() do[t2] } else if ( v == 2 ) break { C() do[t3] } else { D() do[t4] } E() } then { ..t1.. } then[t2] { ..t2.. } then[t3] { ..t3.. } then[t4] { ..t3.. } | rule xxx1 when { $a : A() eval( ! (!$a.v == 1 && $a.v == 2 ) ) E() } then { ..t1.. }
rule xxx2 when { $a : A() eval( $a.v == 1) B() } then { ..t2.. }
rule xxx3 when { $a : A() eval( ! $a.v == 1) eval( $a.v == 2) C() } then { ..t3.. }
rule xxx3 when { $a : A() eval( ! $a.v == 1) eval( ! $a.v == 2) D() } then { ..t4.. } |
switch
'switch' is suggar provided for 'if/else if/else'. Like 'if/else if/else' the 'switch' first parenthesis can take any valid expression and its 'this' is contextualised to the pattern immediately preceeding it. Any valid expression can be used inside each of the 'case' parenthesis. Only the first matching case has it's block evaluated. If no 'cases' match, the 'default' is evaluated. unlike java/c the 'switch' has no follow through, and it's behaviour is per 'if/else if/else', where 'break' is simply whether the matching continues after the switch element.
switch | if/else if/else |
---|---|
rule xxx when { $z : Z() $a : A() switch( v ) break { case 1 { B() do[t2] } case 2 { C() do[t3] } case $z.v { ... } case 1 + 1 + 1 { ... } default { D() } } E() } then { ..t1.. } then[t2] { ..t2.. } then[t3] { ..t3.. } then[t4] { ..t3.. } | rule xxx when { $z : Z() $a : A() if ( v == 1 ) break { B() do[t2] } else if ( v == 2 ) break { C() do[t3] } else if ( v == $z.v ) break { ... } else if ( v == 1 + 1 + 1 ) break { ... } else { D() } E() } then { ..t1.. } then[t2] { ..t2.. } then[t3] { ..t3.. } then[t4] { ..t3.. } |
rule xxx when { $z : Z() $a : A() switch( v ) { case 1 { B() do[t2] } case 2 { C() do[t3] } case $z.v { ... } case 1 + 1 + 1 { ... } default { D() } } E() } then { ..t1.. } then[t2] { ..t2.. } then[t3] { ..t3.. } then[t4] { ..t3.. } | rule xxx when { $z : Z() $a : A() if ( v == 1 ) { B() do[t2] } if ( v == 2 ) { C() do[t3] } if ( v == $z.v ) { ... } if ( v == 1 + 1 + 1 ) { ... } if( !( v==1 ) && !(v==2) &&...) { D() } E() } then { ..t1.. } then[t2] { ..t2.. } then[t3] { ..t3.. } then[t4] { ..t3.. } |
Comments