…he node branch without breaking narwhal compatibility
…e narwhal instead. All tests are executing successfully against both Node.js and Narwhal/Rhino backends
| @@ -17,10 +17,14 @@ namespace :build do | ||
| sh "racc #{args[:racc_args]} -o lib/coffee_script/parser.rb lib/coffee_script/grammar.y" | ||
| end | ||
|
|
||
| desc "Compile the Narwhal interface for --interactive and --run" | ||
| desc "Compile the Narwhal interface" | ||
| task :narwhal do | ||
| sh "bin/coffee lib/coffee_script/narwhal/*.coffee -o lib/coffee_script/narwhal/lib/coffee-script" | ||
| sh "mv lib/coffee_script/narwhal/lib/coffee-script/coffee-script.js lib/coffee_script/narwhal/lib/coffee-script.js" | ||
| sh "bin/coffee src/narwhal/*.coffee -o lib/coffee_script/narwhal" | ||
| end | ||
|
|
||
| desc "Continually compile the CoffeeScript/Node.js components with --watch" | ||
| task :node do | ||
| sh "bin/coffee -w src/*.coffee -o lib/coffee_script/" | ||
| end | ||
|
|
||
| desc "Compile and install the Ultraviolet syntax highlighter" | ||
| @@ -1,7 +1,7 @@ | ||
| Gem::Specification.new do |s| | ||
| s.name = 'coffee-script' | ||
| s.version = '0.3.0' # Keep version in sync with coffee-script.rb | ||
| s.date = '2010-1-26' | ||
| s.version = '0.3.2' # Keep version in sync with coffee-script.rb | ||
| s.date = '2010-2-8' | ||
|
|
||
| s.homepage = "http://jashkenas.github.com/coffee-script/" | ||
| s.summary = "The CoffeeScript Compiler" | ||
| @@ -5,3 +5,5 @@ volume: 10 if band isnt spinal_tap | ||
| let_the_wild_rumpus_begin() unless answer is no | ||
|
|
||
| if car.speed < speed_limit then accelerate() | ||
|
|
||
| print "My name is " + @name | ||
| @@ -1,6 +1,6 @@ | ||
| Account: (customer, cart) -> | ||
| this.customer: customer | ||
| this.cart: cart | ||
| @customer: customer | ||
| @cart: cart | ||
|
|
||
| $('.shopping_cart').bind 'click', (event) => | ||
| this.customer.purchase this.cart | ||
| @customer.purchase @cart |
| @@ -1,14 +1,14 @@ | ||
| Animal: -> | ||
| Animal::move: (meters) -> | ||
| alert this.name + " moved " + meters + "m." | ||
| alert @name + " moved " + meters + "m." | ||
|
|
||
| Snake: (name) -> this.name: name | ||
| Snake: (name) -> @name: name | ||
| Snake extends Animal | ||
| Snake::move: -> | ||
| alert "Slithering..." | ||
| super 5 | ||
|
|
||
| Horse: (name) -> this.name: name | ||
| Horse: (name) -> @name: name | ||
| Horse extends Animal | ||
| Horse::move: -> | ||
| alert "Galloping..." | ||
| @@ -51,7 +51,7 @@ | ||
|
|
||
| <p> | ||
| <b>Latest Version:</b> | ||
| <a href="http://gemcutter.org/gems/coffee-script">0.3.0</a> | ||
| <a href="http://gemcutter.org/gems/coffee-script">0.3.2</a> | ||
| </p> | ||
|
|
||
| <h2>Table of Contents</h2> | ||
| @@ -118,7 +118,7 @@ gem install coffee-script</pre> | ||
| Installing the gem provides the <tt>coffee</tt> command, which can | ||
| be used to compile CoffeeScript <tt>.coffee</tt> files into JavaScript, as | ||
| well as debug them. In conjunction with | ||
| <a href="http://narwhaljs.org/">Narwhal</a>, the <tt>coffee</tt> | ||
| <a href="http://nodejs.org/">Node.js</a> (or <a href="http://narwhaljs.org/">Narwhal</a>), the <tt>coffee</tt> | ||
| command also provides direct evaluation and an interactive REPL. | ||
| When compiling to JavaScript, <tt>coffee</tt> writes the output | ||
| as <tt>.js</tt> files in the same directory by default, but output | ||
| @@ -130,14 +130,16 @@ gem install coffee-script</pre> | ||
| <td width="25%"><code>-i, --interactive</code></td> | ||
| <td> | ||
| Launch an interactive CoffeeScript session. | ||
| Requires <a href="http://narwhaljs.org/">Narwhal</a>. | ||
| Requires <a href="http://nodejs.org/">Node.js</a>, | ||
| or <a href="http://narwhaljs.org/">Narwhal</a>, with <tt>--narwhal</tt>. | ||
| </td> | ||
| </tr> | ||
| <tr> | ||
| <td><code>-r, --run</code></td> | ||
| <td> | ||
| Compile and execute scripts without saving the intermediate | ||
| JavaScript. Requires <a href="http://narwhaljs.org/">Narwhal</a>. | ||
| JavaScript. Requires <a href="http://nodejs.org/">Node.js</a>, | ||
| or <a href="http://narwhaljs.org/">Narwhal</a>, with <tt>--narwhal</tt>. | ||
| </td> | ||
| </tr> | ||
| <tr> | ||
| @@ -194,7 +196,7 @@ gem install coffee-script</pre> | ||
| <td><code>-n, --no-wrap</code></td> | ||
| <td> | ||
| Compile the JavaScript without the top-level function safety wrapper. | ||
| (Used for CoffeeScript as a Narwhal module.) | ||
| (Used for CoffeeScript as a Node.js module.) | ||
| </td> | ||
| </tr> | ||
| <tr> | ||
| @@ -367,6 +369,9 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre> | ||
| <p> | ||
| For single-line statements, <tt>unless</tt> can be used as the inverse of <tt>if</tt>. | ||
| </p> | ||
| <p> | ||
| As a shortcut for <tt>this.property</tt>, you can use <tt>@property</tt>. | ||
| </p> | ||
| <%= code_for('aliases') %> | ||
|
|
||
| <p id="splats"> | ||
| @@ -624,21 +629,22 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre> | ||
| <ul> | ||
| <li> | ||
| <a href="http://github.com/jashkenas/coffee-script/">Source Code</a><br /> | ||
| After checking out the source, make sure to run <tt>rake build:parser</tt> | ||
| to generate an up-to-date version of the Racc parser. | ||
| Use <tt>bin/coffee</tt> to test your changes, | ||
| <tt>rake test</tt> to run the test suite, | ||
| <tt>rake build:parser</tt> to regenerate the Racc parser if you're | ||
| working on the grammar, | ||
| and <tt>rake gem:install</tt> to | ||
| create and install a custom version of the gem. | ||
| </li> | ||
| <li> | ||
| <a href="http://github.com/jashkenas/coffee-script/issues">Bugs, Feature Requests, and General Discussion</a> | ||
| <a href="http://github.com/jashkenas/coffee-script/issues">CoffeeScript Issues</a><br /> | ||
| Bugs reports, feature requests, and general discussion all belong here. | ||
| </li> | ||
| <li> | ||
| <a href="http://github.com/creationix/coffeepot">CoffeePot</a><br /> | ||
| An implementation of CoffeeScript, written in CoffeeScript, by | ||
| <a href="http://github.com/creationix">Tim Caswell</a>. Compiles just | ||
| a limited subset at this point. | ||
| <a href="http://github.com/mattly/rack-coffee">rack-coffee</a><br /> | ||
| Rack middleware for serving CoffeeScripts as JavaScript directly to | ||
| the browser, without having to compile them first. From | ||
| <a href="http://github.com/mattly">Matt Lyon</a>. | ||
| </li> | ||
| <li> | ||
| <a href="http://github.com/jnicklas/bistro_car">BistroCar</a><br /> | ||
| @@ -653,9 +659,22 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre> | ||
| <a href="http://github.com/inem">Ivan Nemytchenko</a>, that embeds | ||
| snippets of CoffeeScript within your HAML templates. | ||
| </li> | ||
| <li> | ||
| <a href="http://github.com/creationix/coffeepot">CoffeePot</a><br /> | ||
| An implementation of CoffeeScript, written in CoffeeScript, by | ||
| <a href="http://github.com/creationix">Tim Caswell</a>. Compiles just | ||
| a limited subset at this point. | ||
| </li> | ||
| </ul> | ||
|
|
||
| <h2 id="change_log">Change Log</h2> | ||
|
|
||
| <p> | ||
| <b class="header" style="margin-top: 20px;">0.3.2</b> | ||
| <tt>@property</tt> is now a shorthand for <tt>this.property</tt>.<br /> | ||
| Switched the default JavaScript engine from Narwhal to Node.js. Pass | ||
| the <tt>--narwhal</tt> flag if you'd like to continue using it. | ||
| </p> | ||
|
|
||
| <p> | ||
| <b class="header" style="margin-top: 20px;">0.3.0</b> | ||
| @@ -10,4 +10,5 @@ | ||
| let_the_wild_rumpus_begin(); | ||
| } | ||
| car.speed < speed_limit ? accelerate() : null; | ||
| print("My name is " + this.name); | ||
| })(); | ||
| @@ -1,6 +1,6 @@ | ||
| (function(){ | ||
| var solipsism, speed; | ||
| if ((typeof mind !== "undefined" && mind !== null) && !(typeof world !== "undefined" && world !== null)) { | ||
| if ((typeof mind !== "undefined" && mind !== null) && (typeof !world !== "undefined" && !world !== null)) { | ||
| solipsism = true; | ||
| } | ||
| speed = (typeof speed !== "undefined" && speed !== null) ? speed : 140; | ||
| @@ -11,6 +11,6 @@ index: (list, target) -> | ||
| if val < target then low: mid + 1 else high: mid | ||
| return -1 | ||
|
|
||
| print(2 is index([10, 20, 30, 40, 50], 30)) | ||
| print(4 is index([-97, 35, 67, 88, 1200], 1200)) | ||
| print(0 is index([0, 45, 70], 0)) | ||
| puts 2 is index([10, 20, 30, 40, 50], 30) | ||
| puts 4 is index([-97, 35, 67, 88, 1200], 1200) | ||
| puts 0 is index([0, 45, 70], 0) | ||
| @@ -8,6 +8,6 @@ runtime: (N) -> | ||
| t: n - 1 + sum / n | ||
| t | ||
|
|
||
| print(runtime(3) is 2.6666666666666665) | ||
| print(runtime(5) is 7.4) | ||
| print(runtime(8) is 16.92142857142857) | ||
| puts runtime(3) is 2.6666666666666665 | ||
| puts runtime(5) is 7.4 | ||
| puts runtime(8) is 16.92142857142857 | ||
| @@ -26,9 +26,9 @@ match_star: (c, regexp, text) -> | ||
| return false unless text and (text[0] is c or c is '.') | ||
| text: text.slice(1) | ||
|
|
||
| print(match("ex", "some text")) | ||
| print(match("s..t", "spit")) | ||
| print(match("^..t", "buttercup")) | ||
| print(match("i..$", "cherries")) | ||
| print(match("o*m", "vrooooommm!")) | ||
| print(match("^hel*o$", "hellllllo")) | ||
| puts match("ex", "some text") | ||
| puts match("s..t", "spit") | ||
| puts match("^..t", "buttercup") | ||
| puts match("i..$", "cherries") | ||
| puts match("o*m", "vrooooommm!") | ||
| puts match("^hel*o$", "hellllllo") | ||
| @@ -0,0 +1,57 @@ | ||
| # After wycats' http://yehudakatz.com/2010/02/07/the-building-blocks-of-ruby/ | ||
|
|
||
| # Sinatra. | ||
| get '/hello', -> | ||
| 'Hello World' | ||
|
|
||
|
|
||
| # Append. | ||
| append: (location, data) -> | ||
| path: new Pathname location | ||
| throw "Location does not exist" unless path.exists() | ||
|
|
||
| File.open path, 'a', (file) -> | ||
| file.puts YAML.dump data | ||
|
|
||
| data | ||
|
|
||
|
|
||
| # Rubinius' File.open implementation. | ||
| File.open: (path, mode, block) -> | ||
| io: new File path, mode | ||
|
|
||
| return io unless block | ||
|
|
||
| try | ||
| block io | ||
| finally | ||
| try | ||
| io.close() unless io.closed() | ||
| catch error | ||
| # nothing, just swallow them. | ||
|
|
||
|
|
||
| # Write. | ||
| write: (location, data) -> | ||
| path = new Pathname location | ||
| raise "Location does not exist" unless path.exists() | ||
|
|
||
| File.open path, 'w', (file) -> | ||
| return false if Digest.MD5.hexdigest(file.read()) is data.hash() | ||
| file.puts YAML.dump data | ||
| true | ||
|
|
||
|
|
||
| # Rails' respond_to. | ||
| index: -> | ||
| people: Person.find 'all' | ||
|
|
||
| respond_to (format) -> | ||
| format.html() | ||
| format.xml -> render { xml: people.xml() } | ||
|
|
||
|
|
||
| # Synchronization. | ||
| synchronize: (block) -> | ||
| lock() | ||
| try block() finally unlock() |
| @@ -19,7 +19,7 @@ binary_search: (items, value) -> | ||
|
|
||
|
|
||
| # Test the function. | ||
| print(2 is binary_search([10, 20, 30, 40, 50], 30)) | ||
| print(4 is binary_search([-97, 35, 67, 88, 1200], 1200)) | ||
| print(0 is binary_search([0, 45, 70], 0)) | ||
| print(-1 is binary_search([0, 45, 70], 10)) | ||
| puts(2 is binary_search([10, 20, 30, 40, 50], 30)) | ||
| puts(4 is binary_search([-97, 35, 67, 88, 1200], 1200)) | ||
| puts(0 is binary_search([0, 45, 70], 0)) | ||
| puts(-1 is binary_search([0, 45, 70], 10)) | ||
| @@ -7,5 +7,5 @@ bubble_sort: (list) -> | ||
|
|
||
|
|
||
| # Test the function. | ||
| print(bubble_sort([3, 2, 1]).join(' ') is '1 2 3') | ||
| print(bubble_sort([9, 2, 7, 0, 1]).join(' ') is '0 1 2 7 9') | ||
| puts(bubble_sort([3, 2, 1]).join(' ') is '1 2 3') | ||
| puts(bubble_sort([9, 2, 7, 0, 1]).join(' ') is '0 1 2 7 9') | ||
| @@ -91,16 +91,16 @@ LinkedList::toString: -> this.toArray().toString() | ||
| list: new LinkedList() | ||
|
|
||
| list.add("Hi") | ||
| print(list.size() is 1) | ||
| print(list.item(0) is "Hi") | ||
| print(list.item(1) is null) | ||
| puts(list.size() is 1) | ||
| puts(list.item(0) is "Hi") | ||
| puts(list.item(1) is null) | ||
|
|
||
| list: new LinkedList() | ||
| list.add("zero").add("one").add("two") | ||
| print(list.size() is 3) | ||
| print(list.item(2) is "two") | ||
| print(list.remove(1) is "one") | ||
| print(list.item(0) is "zero") | ||
| print(list.item(1) is "two") | ||
| print(list.size() is 2) | ||
| print(list.item(-10) is null) | ||
| puts(list.size() is 3) | ||
| puts(list.item(2) is "two") | ||
| puts(list.remove(1) is "one") | ||
| puts(list.item(0) is "zero") | ||
| puts(list.item(1) is "two") | ||
| puts(list.size() is 2) | ||
| puts(list.item(-10) is null) | ||
| @@ -31,6 +31,6 @@ is_valid_identifier: (identifier) -> | ||
|
|
||
|
|
||
| # Tests. | ||
| print(is_valid_identifier("49927398716") is true) | ||
| print(is_valid_identifier("4408041234567893") is true) | ||
| print(is_valid_identifier("4408041234567890") is false) | ||
| puts(is_valid_identifier("49927398716") is true) | ||
| puts(is_valid_identifier("4408041234567893") is true) | ||
| puts(is_valid_identifier("4408041234567890") is false) | ||
| @@ -15,5 +15,5 @@ merge_sort: (list) -> | ||
|
|
||
|
|
||
| # Test the function. | ||
| print(merge_sort([3, 2, 1]).join(' ') is '1 2 3') | ||
| print(merge_sort([9, 2, 7, 0, 1]).join(' ') is '0 1 2 7 9') | ||
| puts(merge_sort([3, 2, 1]).join(' ') is '1 2 3') | ||
| puts(merge_sort([9, 2, 7, 0, 1]).join(' ') is '0 1 2 7 9') | ||
| @@ -9,7 +9,7 @@ selection_sort: (list) -> | ||
| min: i | ||
|
|
||
| # Check the rest of the array to see if anything is smaller. | ||
| (min: j if list[j] < list[min]) for j in [i+1...len] | ||
| (min: j if list[j] < list[min]) for j in [(i+1)...len] | ||
|
|
||
| # Swap if a smaller item has been found. | ||
| [list[i], list[min]]: [list[min], list[i]] if i isnt min | ||
| @@ -19,5 +19,5 @@ selection_sort: (list) -> | ||
|
|
||
|
|
||
| # Test the function. | ||
| print(selection_sort([3, 2, 1]).join(' ') is '1 2 3') | ||
| print(selection_sort([9, 2, 7, 0, 1]).join(' ') is '0 1 2 7 9') | ||
| puts(selection_sort([3, 2, 1]).join(' ') is '1 2 3') | ||
| puts(selection_sort([9, 2, 7, 0, 1]).join(' ') is '0 1 2 7 9') | ||
| @@ -72,6 +72,12 @@ | ||
| <key>name</key> | ||
| <string>constant.numeric.coffee</string> | ||
| </dict> | ||
| <dict> | ||
| <key>match</key> | ||
| <string>(@)[a-zA-Z_$]\w*</string> | ||
| <key>name</key> | ||
| <string>variable.other.readwrite.instance.coffee</string> | ||
| </dict> | ||
| <dict> | ||
| <key>name</key> | ||
| <string>string.quoted.heredoc.coffee</string> | ||
Showing you all comments on commits in this comparison.
|
So weepy finally convinced you this is a good idea then? :P |
|
I still don't like the syntax, but it seems much-beloved by most. |
|
people: use this for good, not evil. |
|
creeping rubyism |
|
@var doesn't work well when you assign to it:
produces:
Still a good start! |
|
Thanks for the bug report, Stan. This is now fixed on both node and master. The ValueNode didn't realize that a ThisNode counts the same as having properties -- I've straightened it out. |