From 0a58eeef2b1234a9159096d637c66c30fa339f7e Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Thu, 24 Dec 2009 01:22:41 -0500 Subject: [PATCH] waypoint --- documentation/cs/strings.cs | 3 ++- documentation/cs/super.cs | 4 ++++ documentation/index.html.erb | 17 +++++++++------- documentation/js/strings.js | 10 ++++----- index.html | 34 ++++++++++++++++++++----------- lib/coffee_script/command_line.rb | 2 +- lib/coffee_script/lexer.rb | 2 +- 7 files changed, 45 insertions(+), 27 deletions(-) diff --git a/documentation/cs/strings.cs b/documentation/cs/strings.cs index 335d702b..0f41e4fa 100644 --- a/documentation/cs/strings.cs +++ b/documentation/cs/strings.cs @@ -3,4 +3,5 @@ never mind how long precisely -- having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the -world..." \ No newline at end of file +world..." + diff --git a/documentation/cs/super.cs b/documentation/cs/super.cs index 2c97fb99..baee074a 100644 --- a/documentation/cs/super.cs +++ b/documentation/cs/super.cs @@ -19,3 +19,7 @@ tom: new Horse("Tommy the Palomino") sam.move() tom.move() + + + + diff --git a/documentation/index.html.erb b/documentation/index.html.erb index 8916d842..3df8a296 100644 --- a/documentation/index.html.erb +++ b/documentation/index.html.erb @@ -41,7 +41,7 @@

Disclaimer: - CoffeeScript is just for fun and seriously alpha. I'm sure that there are still + CoffeeScript is just for fun and seriously alpha. I'm sure that there are still plenty of holes in the walls and leaks in the syntax. There is no guarantee, explicit or implied, of its suitability for any purpose. That said, it compiles into clean JavaScript (the good parts) that can use existing @@ -173,12 +173,15 @@ coffee-script --print app/scripts/*.cs > concatenation.js the line will do just as well. All other whitespace is not significant. Instead of using curly braces { } to delimit a block of code, use a period . to mark the end of a - function, if-statement, switch, or try/catch. + block for + functions, + if-statements, + switch, and try/catch.

Functions and Invocation - Let's start with the best part, shall we? Functions are defined + Let's start with the best part of CoffeeScript, shall we? Functions are defined by a list of parameters, an arrow, and the function body. The empty function looks like this: =>.

@@ -293,7 +296,7 @@ coffee-script --print app/scripts/*.cs > concatenation.js JS.Class, etc. The libraries provide syntactic sugar, but the built-in inheritance would be completely usable if it weren't for one small exception: - it's very awkward to call super, the prototype object's + it's very awkward to call super, the prototype object's implementation of the current function. CoffeeScript converts super() calls into calls against the immediate ancestor's method of the same name. @@ -331,8 +334,8 @@ coffee-script --print app/scripts/*.cs > concatenation.js

Switch/Case/Else Switch statements in JavaScript are rather broken. You can only - do string comparisons, and need to remember to break at the end of - every case statement to avoid accidentally falling through to + do string comparisons, and need to remember to break at the end of + every case statement to avoid accidentally falling through to the default case. CoffeeScript compiles switch statements into JavaScript if-else chains, allowing you to compare any object (via ===), preventing fall-through, and resulting @@ -352,7 +355,7 @@ coffee-script --print app/scripts/*.cs > concatenation.js Multiline Strings Multiline strings are allowed in CoffeeScript.

- <%= code_for('strings') %> + <%= code_for('strings', 'moby_dick') %> diff --git a/documentation/js/strings.js b/documentation/js/strings.js index 37876208..b3407d7f 100644 --- a/documentation/js/strings.js +++ b/documentation/js/strings.js @@ -1,8 +1,8 @@ (function(){ - var moby_dick = "Call me Ishmael. Some years ago --\ -never mind how long precisely -- having little\ -or no money in my purse, and nothing particular\ -to interest me on shore, I thought I would sail\ -about a little and see the watery part of the\ + var moby_dick = "Call me Ishmael. Some years ago -- \ +never mind how long precisely -- having little \ +or no money in my purse, and nothing particular \ +to interest me on shore, I thought I would sail \ +about a little and see the watery part of the \ world..."; })(); \ No newline at end of file diff --git a/index.html b/index.html index f71b6add..1b6152f5 100644 --- a/index.html +++ b/index.html @@ -27,7 +27,7 @@

Disclaimer: - CoffeeScript is just for fun and seriously alpha. I'm sure that there are still + CoffeeScript is just for fun and seriously alpha. I'm sure that there are still plenty of holes in the walls and leaks in the syntax. There is no guarantee, explicit or implied, of its suitability for any purpose. That said, it compiles into clean JavaScript (the good parts) that can use existing @@ -243,12 +243,15 @@ coffee-script --print app/scripts/*.cs > concatenation.js the line will do just as well. All other whitespace is not significant. Instead of using curly braces { } to delimit a block of code, use a period . to mark the end of a - function, if-statement, switch, or try/catch. + block for + functions, + if-statements, + switch, and try/catch.

Functions and Invocation - Let's start with the best part, shall we? Functions are defined + Let's start with the best part of CoffeeScript, shall we? Functions are defined by a list of parameters, an arrow, and the function body. The empty function looks like this: =>.

@@ -508,7 +511,7 @@ var three_to_six = nums.slice(3, 6 + 1); JS.Class, etc. The libraries provide syntactic sugar, but the built-in inheritance would be completely usable if it weren't for one small exception: - it's very awkward to call super, the prototype object's + it's very awkward to call super, the prototype object's implementation of the current function. CoffeeScript converts super() calls into calls against the immediate ancestor's method of the same name. @@ -642,8 +645,8 @@ let_the_wild_rumpus_begin() unless answer Switch/Case/Else Switch statements in JavaScript are rather broken. You can only - do string comparisons, and need to remember to break at the end of - every case statement to avoid accidentally falling through to + do string comparisons, and need to remember to break at the end of + every case statement to avoid accidentally falling through to the default case. CoffeeScript compiles switch statements into JavaScript if-else chains, allowing you to compare any object (via ===), preventing fall-through, and resulting @@ -707,13 +710,20 @@ let_the_wild_rumpus_begin() unless answer to interest me on shore, I thought I would sail about a little and see the watery part of the world..." -
var moby_dick = "Call me Ishmael. Some years ago --\
-never mind how long precisely -- having little\
-or no money in my purse, and nothing particular\
-to interest me on shore, I thought I would sail\
-about a little and see the watery part of the\
+
+
var moby_dick = "Call me Ishmael. Some years ago -- \
+never mind how long precisely -- having little \
+or no money in my purse, and nothing particular \
+to interest me on shore, I thought I would sail \
+about a little and see the watery part of the \
 world...";
-

+
diff --git a/lib/coffee_script/command_line.rb b/lib/coffee_script/command_line.rb index 1172d7c2..19ed27d0 100644 --- a/lib/coffee_script/command_line.rb +++ b/lib/coffee_script/command_line.rb @@ -93,7 +93,7 @@ Usage: # Eval a little piece of CoffeeScript directly from the command line. def eval_scriptlet - script = @sources.join(' ') + script = STDIN.tty? ? @sources.join(' ') : STDIN.read return tokens(script) if @options[:tokens] js = compile(script) return lint(js) if @options[:lint] diff --git a/lib/coffee_script/lexer.rb b/lib/coffee_script/lexer.rb index a67e3050..d44c486d 100644 --- a/lib/coffee_script/lexer.rb +++ b/lib/coffee_script/lexer.rb @@ -89,7 +89,7 @@ module CoffeeScript return false unless string = @chunk[STRING, 1] escaped = string.gsub(MULTILINER) do |match| @line += 1 - "\\\n" + " \\\n" end token(:STRING, escaped) @i += string.length