enabling condition-less switches.

This commit is contained in:
Jeremy Ashkenas 2010-05-10 22:57:51 -04:00
parent 4d0acc9b02
commit cd6ee373ff
4 changed files with 84 additions and 65 deletions

View File

@ -573,6 +573,10 @@
return $4.switches_over($2);
}), o("SWITCH Expression INDENT Whens ELSE Block OUTDENT", function() {
return $4.switches_over($2).add_else($6, true);
}), o("SWITCH INDENT Whens OUTDENT", function() {
return $3;
}), o("SWITCH INDENT Whens ELSE Block OUTDENT", function() {
return $3.add_else($5, true);
})
],
// The inner list of whens is left recursive. At code-generation time, the

File diff suppressed because one or more lines are too long

View File

@ -469,6 +469,8 @@ grammar: {
Switch: [
o "SWITCH Expression INDENT Whens OUTDENT", -> $4.switches_over $2
o "SWITCH Expression INDENT Whens ELSE Block OUTDENT", -> $4.switches_over($2).add_else $6, true
o "SWITCH INDENT Whens OUTDENT", -> $3
o "SWITCH INDENT Whens ELSE Block OUTDENT", -> $3.add_else $5, true
]
# The inner list of whens is left recursive. At code-generation time, the

View File

@ -62,3 +62,12 @@ switch "word"
result: true unless false
ok result
# Should be able to handle switches sans-condition.
result: switch
when yes and no then 1
when yes or no then 2
else 3
ok result is 2