mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-19 03:44:23 -05:00
enabling condition-less switches.
This commit is contained in:
@@ -573,6 +573,10 @@
|
|||||||
return $4.switches_over($2);
|
return $4.switches_over($2);
|
||||||
}), o("SWITCH Expression INDENT Whens ELSE Block OUTDENT", function() {
|
}), o("SWITCH Expression INDENT Whens ELSE Block OUTDENT", function() {
|
||||||
return $4.switches_over($2).add_else($6, true);
|
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
|
// 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: [
|
Switch: [
|
||||||
o "SWITCH Expression INDENT Whens OUTDENT", -> $4.switches_over $2
|
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 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
|
# The inner list of whens is left recursive. At code-generation time, the
|
||||||
|
|||||||
@@ -62,3 +62,12 @@ switch "word"
|
|||||||
result: true unless false
|
result: true unless false
|
||||||
|
|
||||||
ok result
|
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
|
||||||
Reference in New Issue
Block a user