removed the 'default' keyword in favor of an 'else'

This commit is contained in:
Jeremy Ashkenas
2009-12-17 21:14:36 -05:00
parent e1e6bb72c6
commit f5d31b78e6
6 changed files with 573 additions and 566 deletions

2
TODO
View File

@@ -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?

View File

@@ -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(); .

View File

@@ -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:

View File

@@ -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*)/

View File

@@ -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

File diff suppressed because it is too large Load Diff