Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 14 commits
  • 42 files changed
  • 0 commit comments
  • 2 contributors
Showing with 1,396 additions and 1,321 deletions.
  1. +12 −3 Rakefile
  2. +0 −3 bin/cs
  3. +2 −2 coffee-script.gemspec
  4. +1 −1 documentation/cs/aliases.cs
  5. +62 −25 documentation/index.html.erb
  6. +10 −10 documentation/js/array_comprehensions.js
  7. +6 −6 documentation/js/overview.js
  8. +1 −1 examples/code.cs
  9. +2 −2 examples/poignant.cs
  10. +1 −1 examples/underscore.cs
  11. +85 −48 index.html
  12. +0 −91 lib-js/coffee-script.js
  13. +0 −23 lib-js/coffee-script/loader.js
  14. +1 −1 lib/coffee-script.rb
  15. +1 −1 lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage
  16. +27 −2 lib/coffee_script/command_line.rb
  17. +9 −7 lib/coffee_script/grammar.y
  18. +1 −1 lib/coffee_script/lexer.rb
  19. +59 −0 lib/coffee_script/narwhal/coffee-script.cs
  20. +65 −0 lib/coffee_script/narwhal/js/coffee-script.js
  21. +3 −0 lib/coffee_script/narwhal/js/launcher.js
  22. +20 −0 lib/coffee_script/narwhal/js/loader.js
  23. +1 −0 lib/coffee_script/narwhal/launcher.cs
  24. +19 −0 lib/coffee_script/narwhal/loader.cs
  25. +11 −4 lib/coffee_script/nodes.rb
  26. +971 −937 lib/coffee_script/parser.rb
  27. +1 −1 lib/coffee_script/scope.rb
  28. +3 −3 package.json
  29. +1 −1 test/fixtures/each.cs
  30. +7 −7 test/fixtures/each.js
  31. +1 −1 test/fixtures/each.tokens
  32. +7 −7 test/fixtures/each_no_wrap.js
  33. +1 −1 test/fixtures/execution/array_comprehension.cs
  34. +0 −21 test/fixtures/execution/array_comprehension.js
  35. +0 −9 test/fixtures/execution/assign_to_try_catch.js
  36. +0 −27 test/fixtures/execution/calling_super.js
  37. +0 −6 test/fixtures/execution/fancy_if_statement.js
  38. +0 −10 test/fixtures/execution/keyword_operators.js
  39. +2 −2 test/fixtures/execution/test_everything.cs
  40. +0 −29 test/fixtures/execution/test_everything.js
  41. +0 −16 test/fixtures/execution/test_switch.js
  42. +3 −11 test/unit/test_execution.rb
View
@@ -10,9 +10,18 @@ task :test do
Dir['test/*/**/test_*.rb'].each {|test| require test }
end
-desc "Recompile the Racc parser (pass -v and -g for verbose debugging)"
-task :build, :extra_args do |t, args|
- sh "racc #{args[:extra_args]} -o lib/coffee_script/parser.rb lib/coffee_script/grammar.y"
+namespace :build do
+
+ desc "Recompile the Racc parser (pass -v and -g for verbose debugging)"
+ task :parser, :extra_args do |t, args|
+ sh "racc #{args[:extra_args]} -o lib/coffee_script/parser.rb lib/coffee_script/grammar.y"
+ end
+
+ desc "Compile the Narwhal interface for --interactive and --run"
+ task :narwhal do
+ sh "bin/coffee-script lib/coffee_script/narwhal/*.cs -o lib/coffee_script/narwhal/js"
+ end
+
end
desc "Build the documentation page"
View
@@ -1,3 +0,0 @@
-#!/usr/bin/env narwhal
-
-require("coffee-script").run(system.args);
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|
s.name = 'coffee-script'
- s.version = '0.1.2' # Keep version in sync with coffee-script.rb
- s.date = '2009-12-24'
+ s.version = '0.1.3' # Keep version in sync with coffee-script.rb
+ s.date = '2009-12-25'
s.homepage = "http://jashkenas.github.com/coffee-script/"
s.summary = "The CoffeeScript Compiler"
@@ -1,6 +1,6 @@
launch() if ignition is on
-volume: 10 if band aint spinal_tap
+volume: 10 if band isnt spinal_tap
let_the_wild_rumpus_begin() unless answer is no
@@ -37,8 +37,6 @@
equivalent in JavaScript, it's just another way of saying it.
</p>
- <!-- <%# code_for('intro') %>-->
-
<p>
<b>Disclaimer:</b>
CoffeeScript is just for fun and seriously alpha. I'm sure that there are still
@@ -83,7 +81,7 @@
<%= code_for('overview', 'cubed_list') %>
<h2 id="installation">Installation and Usage</h2>
-
+
<p>
The CoffeeScript compiler is written in pure Ruby, and is available
as a Ruby Gem.
@@ -95,14 +93,31 @@ gem install coffee-script</pre>
<p>
Installing the gem provides the <tt>coffee-script</tt> command, which can
be used to compile CoffeeScript <tt>.cs</tt> files into JavaScript, as
- well as debug them. By default, <tt>coffee-script</tt> writes out the
- JavaScript as <tt>.js</tt> files in the same directory, but output
+ well as debug them. In conjunction with
+ <a href="http://narwhaljs.org/">Narwhal</a>, the <tt>coffee-script</tt>
+ command also provides direct evaluation and an interactive REPL.
+ When compiling to JavaScript, <tt>coffee-script</tt> writes the output
+ as <tt>.js</tt> files in the same directory by default, but output
can be customized with the following options:
</p>
<table>
<tr>
- <td width="25%"><code>-o, --output [DIR]</code></td>
+ <td width="25%"><code>-i, --interactive</code></td>
+ <td>
+ Launch an interactive CoffeeScript session.
+ Requires <a href="http://narwhaljs.org/">Narwhal</a>.
+ </td>
+ </tr>
+ <tr>
+ <td><code>-r, --run</code></td>
+ <td>
+ Compile and execute the CoffeeScripts without saving the intermediate
+ JavaScript. Requires <a href="http://narwhaljs.org/">Narwhal</a>.
+ </td>
+ </tr>
+ <tr>
+ <td><code>-o, --output [DIR]</code></td>
<td>
Write out all compiled JavaScript files into the specified directory.
</td>
@@ -125,7 +140,7 @@ gem install coffee-script</pre>
<td><code>-l, --lint</code></td>
<td>
If the <tt>jsl</tt> (JavaScript Lint) command is installed, use it
- to check the compilation of a CoffeeScript file. (Handy in
+ to check the compilation of a CoffeeScript file. (Handy in
conjunction with <tt>--watch</tt>)
</td>
</tr>
@@ -152,6 +167,14 @@ gem install coffee-script</pre>
</td>
</tr>
<tr>
+ <td><code>-n, --no-wrap</code></td>
+ <td>
+ Compile the JavaScript without the top-level function safety wrapper
+ or var declarations, for situations where you want to add every
+ variable to global scope.
+ </td>
+ </tr>
+ <tr>
<td><code>--install-bundle</code></td>
<td>
Install the TextMate bundle for CoffeeScript syntax highlighting.
@@ -186,15 +209,15 @@ coffee-script --print app/scripts/*.cs > concatenation.js</pre>
the line will do just as well. All other whitespace is
not significant. Instead of using curly braces <tt>{ }</tt>
to delimit a block of code, use a period <tt>.</tt> to mark the end of a
- block, for
- <a href="#functions">functions</a>,
- <a href="#conditionals">if-statements</a>,
+ block, for
+ <a href="#functions">functions</a>,
+ <a href="#conditionals">if-statements</a>,
<a href="#switch">switch</a>, and <a href="#try">try/catch</a>.
</p>
<p id="functions">
<b class="header">Functions and Invocation</b>
- Functions are defined by a list of parameters, an arrow, and the
+ Functions are defined by a list of parameters, an arrow, and the
function body. The empty function looks like this: <tt>=>.</tt>
</p>
<%= code_for('functions', 'cube(5)') %>
@@ -270,15 +293,15 @@ coffee-script --print app/scripts/*.cs > concatenation.js</pre>
The same mechanism is used to push down assignment through <b>switch</b>
statements, and <b>if-elses</b> (although the ternary operator is preferred).
</p>
-
+
<p id="aliases">
<b class="header">Aliases</b>
Because the <tt>==</tt> operator frequently causes undesirable coercion,
is intransitive, and has a different meaning than in other languages,
CoffeeScript compiles <tt>==</tt> into <tt>===</tt>, and <tt>!=</tt> into
<tt>!==</tt>.
In addition, <tt>is</tt> compiles into <tt>===</tt>,
- and <tt>aint</tt> into <tt>!==</tt>.
+ and <tt>isnt</tt> into <tt>!==</tt>.
</p>
<p>
You can use <tt>not</tt> as an alias for <tt>!</tt>.
@@ -289,7 +312,7 @@ coffee-script --print app/scripts/*.cs > concatenation.js</pre>
</p>
<p>
Instead of a newline or semicolon, <tt>then</tt> can be used to separate
- conditions from expressions, in <b>while</b>,
+ conditions from expressions, in <b>while</b>,
<b>if</b>/<b>else</b>, and <b>switch</b>/<b>when</b> statements.
</p>
<p>
@@ -382,14 +405,14 @@ coffee-script --print app/scripts/*.cs > concatenation.js</pre>
Multiline strings are allowed in CoffeeScript.
</p>
<%= code_for('strings', 'moby_dick') %>
-
+
<h2 id="contributing">Contributing</h2>
-
+
<p>
Here's a wish list of things that would be wonderful to have in
CoffeeScript:
</p>
-
+
<ul>
<li>
A JavaScript version of the compiler, perhaps using Alessandro Warth's
@@ -404,39 +427,53 @@ coffee-script --print app/scripts/*.cs > concatenation.js</pre>
should be able to compile properly.
</li>
<li>
- A tutorial that introduces CoffeeScript from the ground up for folks
+ A tutorial that introduces CoffeeScript from the ground up for folks
without knowledge of JavaScript.
</li>
<li>
Integration with Processing.js's JavaScript API (this would depend on
having a JavaScript version of the compiler).
</li>
<li>
- A lot of the code generation in <tt>nodes.rb</tt> gets into messy
+ A lot of the code generation in <tt>nodes.rb</tt> gets into messy
string manipulation. Techniques for cleaning this up across the board
would be appreciated.
</li>
</ul>
-
+
<h2 id="change_log">Change Log</h2>
<p>
+ <b class="header" style="margin-top: 20px;">0.1.3</b>
+ The <tt>coffee-script</tt> command now includes <tt>--interactive</tt>,
+ which launches an interactive CoffeeScript session, and <tt>--run</tt>,
+ which directly compiles and executes a script. Both options depend on a
+ working installation of Narwhal.
+ The <tt>aint</tt> keyword has been replaced by <tt>isnt</tt>, which goes
+ together a little smoother with <tt>is</tt>.
+ Quoted strings are now allowed as identifiers within object literals: eg.
+ <tt>{"5+5": 10}</tt>.
+ All assignment operators now use a colon: <tt>+:</tt>, <tt>-:</tt>,
+ <tt>*:</tt>, etc.
+ </p>
+
+ <p>
<b class="header" style="margin-top: 20px;">0.1.2</b>
- Fixed a bug with calling <tt>super()</tt> through more than one level of
+ Fixed a bug with calling <tt>super()</tt> through more than one level of
inheritance, with the re-addition of the <tt>extends</tt> keyword.
- Added experimental <a href="http://narwhaljs.org/">Narwhal</a>
- support (as a Tusk package), contributed by
+ Added experimental <a href="http://narwhaljs.org/">Narwhal</a>
+ support (as a Tusk package), contributed by
<a href="http://tlrobinson.net/">Tom Robinson</a>, including
<b>bin/cs</b> as a CoffeeScript REPL and interpreter.
New <tt>--no-wrap</tt> option to suppress the safety function
wrapper.
</p>
-
+
<p>
<b class="header" style="margin-top: 20px;">0.1.1</b>
Added <tt>instanceof</tt> and <tt>typeof</tt> as operators.
</p>
-
+
<p>
<b class="header" style="margin-top: 20px;">0.1.0</b>
Initial CoffeeScript release.
@@ -2,18 +2,18 @@
// Eat lunch.
var lunch;
- var a = ['toast', 'cheese', 'wine'];
- var d = [];
- for (var b=0, c=a.length; b<c; b++) {
- var food = a[b];
- d[b] = food.eat();
+ var __a = ['toast', 'cheese', 'wine'];
+ var __d = [];
+ for (var __b=0, __c=__a.length; __b<__c; __b++) {
+ var food = __a[__b];
+ __d[__b] = food.eat();
}
- lunch = d;
+ lunch = __d;
// Zebra-stripe a table.
- var e = table;
- for (var f=0, g=e.length; f<g; f++) {
- var row = e[f];
- var i = f;
+ var __e = table;
+ for (var __f=0, __g=__e.length; __f<__g; __f++) {
+ var row = __e[__f];
+ var i = __f;
i % 2 === 0 ? highlight(row) : null;
}
})();
@@ -23,11 +23,11 @@
};
// Array comprehensions:
var cubed_list;
- var a = list;
- var d = [];
- for (var b=0, c=a.length; b<c; b++) {
- var num = a[b];
- d[b] = math.cube(num);
+ var __a = list;
+ var __d = [];
+ for (var __b=0, __c=__a.length; __b<__c; __b++) {
+ var num = __a[__b];
+ __d[__b] = math.cube(num);
}
- cubed_list = d;
+ cubed_list = __d;
})();
View
@@ -5,7 +5,7 @@
odd: x => x % 2 is 0.
-even: x => x % 2 aint 0.
+even: x => x % 2 isnt 0.
run_loop: =>
fire_events( e => e.stopPropagation(). )
@@ -81,9 +81,9 @@
hit: damage =>
p_up: Math.rand( this.charisma )
if p_up % 9 is 7
- this.life += p_up / 4
+ this.life +: p_up / 4
puts( "[" + this.name + " magick powers up " + p_up + "!]" ).
- this.life -= damage
+ this.life -: damage
if this.life <= 0 then puts( "[" + this.name + " has died.]" )..
# This method takes one turn in a fight.
@@ -49,7 +49,7 @@
return iterator.call(context, item, i, obj) for item, i in obj. if _.isArray(obj) or _.isArguments(obj)
iterator.call(context, obj[key], key, obj) for key in _.keys(obj).
catch e
- throw e if e aint breaker.
+ throw e if e isnt breaker.
obj.
# Return the results of applying the iterator to each element. Use JavaScript
Oops, something went wrong.

No commit comments for this range