From 0dc445138bea11f6f5e4062efd7e34a3cd8fb42c Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Thu, 17 Dec 2009 21:14:36 -0500 Subject: [PATCH] removed the 'default' keyword in favor of an 'else' --- TODO | 2 -- examples/code.cs | 4 ++-- lib/coffee_script/grammar.y | 4 ++-- lib/coffee_script/lexer.rb | 2 +- lib/coffee_script/nodes.rb | 4 ++-- 5 files changed, 7 insertions(+), 9 deletions(-) diff --git a/TODO b/TODO index 3eedb434..318a495d 100644 --- a/TODO +++ b/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? diff --git a/examples/code.cs b/examples/code.cs index 29737c45..b458dc3d 100644 --- a/examples/code.cs +++ b/examples/code.cs @@ -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(); . diff --git a/lib/coffee_script/grammar.y b/lib/coffee_script/grammar.y index 3e45aba3..539a494c 100644 --- a/lib/coffee_script/grammar.y +++ b/lib/coffee_script/grammar.y @@ -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: diff --git a/lib/coffee_script/lexer.rb b/lib/coffee_script/lexer.rb index 41bec240..9d611420 100644 --- a/lib/coffee_script/lexer.rb +++ b/lib/coffee_script/lexer.rb @@ -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*)/ diff --git a/lib/coffee_script/nodes.rb b/lib/coffee_script/nodes.rb index d2eb2eaa..9103b3b8 100644 --- a/lib/coffee_script/nodes.rb +++ b/lib/coffee_script/nodes.rb @@ -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