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