mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
enabling condition-less switches.
This commit is contained in:
parent
4d0acc9b02
commit
cd6ee373ff
4 changed files with 84 additions and 65 deletions
|
@ -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
|
||||
|
|
134
lib/parser.js
134
lib/parser.js
File diff suppressed because one or more lines are too long
|
@ -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
|
||||
|
|
|
@ -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
|
Loading…
Add table
Reference in a new issue