mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
removed the 'default' keyword in favor of an 'else'
This commit is contained in:
parent
3ffbf541df
commit
0dc445138b
5 changed files with 7 additions and 9 deletions
2
TODO
2
TODO
|
@ -4,8 +4,6 @@ TODO:
|
|||
|
||||
* Code Cleanup.
|
||||
|
||||
* Add JS-style exponential number literals.
|
||||
|
||||
* Is it possible to close blocks (functions, ifs, trys) without an explicit
|
||||
block delimiter or significant whitespace?
|
||||
|
||||
|
|
|
@ -111,7 +111,7 @@ supper: food.capitalize() for food in ['toast', 'cheese', 'wine'].
|
|||
|
||||
drink(bottle) for bottle, i in ['soda', 'wine', 'lemonade'] if even(i).
|
||||
|
||||
# Switch statements.
|
||||
# Switch statements ("else" serves as a default).
|
||||
switch day
|
||||
case "Tuesday" then eat_breakfast()
|
||||
case "Sunday" then go_to_church()
|
||||
|
@ -120,7 +120,7 @@ case "Wednesday"
|
|||
eat_breakfast()
|
||||
go_to_work()
|
||||
eat_dinner()
|
||||
default go_to_work().
|
||||
else go_to_work().
|
||||
|
||||
# Semicolons can optionally be used instead of newlines.
|
||||
wednesday: => eat_breakfast(); go_to_work(); eat_dinner(); .
|
||||
|
|
|
@ -9,7 +9,7 @@ token CODE PARAM NEW RETURN
|
|||
token TRY CATCH FINALLY THROW
|
||||
token BREAK CONTINUE
|
||||
token FOR IN WHILE
|
||||
token SWITCH CASE DEFAULT
|
||||
token SWITCH CASE
|
||||
token SUPER
|
||||
token NEWLINE
|
||||
token JS
|
||||
|
@ -279,7 +279,7 @@ rule
|
|||
SWITCH Expression Then
|
||||
Cases "." { result = val[3].rewrite_condition(val[1]) }
|
||||
| SWITCH Expression Then
|
||||
Cases DEFAULT Expressions "." { result = val[3].rewrite_condition(val[1]).add_default(val[5]) }
|
||||
Cases ELSE Expressions "." { result = val[3].rewrite_condition(val[1]).add_else(val[5]) }
|
||||
;
|
||||
|
||||
Cases:
|
||||
|
|
|
@ -7,7 +7,7 @@ class Lexer
|
|||
"try", "catch", "finally", "throw",
|
||||
"break", "continue",
|
||||
"for", "in", "while",
|
||||
"switch", "case", "default",
|
||||
"switch", "case",
|
||||
"super"]
|
||||
|
||||
IDENTIFIER = /\A([a-zA-Z$_]\w*)/
|
||||
|
|
|
@ -433,8 +433,8 @@ class IfNode < Node
|
|||
end
|
||||
|
||||
# Rewrite a chain of IfNodes to add a default case as the final else.
|
||||
def add_default(expressions)
|
||||
chain? ? @else_body.add_default(expressions) : @else_body = expressions
|
||||
def add_else(expressions)
|
||||
chain? ? @else_body.add_else(expressions) : @else_body = expressions
|
||||
self
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue