Permalink
...
Comparing changes
Open a pull request
- 6 commits
- 19 files changed
- 0 commit comments
- 1 contributor
Unified
Split
Showing
with
356 additions
and 129 deletions.
- +1 −1 LICENSE
- +1 −1 coffee-script.gemspec
- +1 −1 documentation/coffee/expressions_comprehension.coffee
- +2 −1 documentation/coffee/object_comprehensions.coffee
- +9 −3 documentation/index.html.erb
- +18 −18 documentation/underscore.html
- +205 −0 examples/potion.coffee
- +4 −4 examples/underscore.coffee
- +14 −7 index.html
- +1 −1 lib/coffee-script.rb
- +3 −3 lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage
- +3 −3 lib/coffee_script/grammar.y
- +1 −1 lib/coffee_script/lexer.rb
- +3 −7 lib/coffee_script/narwhal/lib/coffee-script.js
- +74 −66 lib/coffee_script/nodes.rb
- +4 −0 lib/coffee_script/value.rb
- +1 −1 package.json
- +2 −2 test/fixtures/execution/test_array_comprehension.coffee
- +9 −9 test/unit/test_parser.rb
View
2
LICENSE
| @@ -1,4 +1,4 @@ | ||
| -Copyright (c) 2009 Jeremy Ashkenas | ||
| +Copyright (c) 2010 Jeremy Ashkenas | ||
| Permission is hereby granted, free of charge, to any person | ||
| obtaining a copy of this software and associated documentation | ||
View
2
coffee-script.gemspec
| @@ -1,6 +1,6 @@ | ||
| Gem::Specification.new do |s| | ||
| s.name = 'coffee-script' | ||
| - s.version = '0.2.2' # Keep version in sync with coffee-script.rb | ||
| + s.version = '0.2.3' # Keep version in sync with coffee-script.rb | ||
| s.date = '2010-1-10' | ||
| s.homepage = "http://jashkenas.github.com/coffee-script/" | ||
View
2
documentation/coffee/expressions_comprehension.coffee
| @@ -1,3 +1,3 @@ | ||
| # The first ten global properties. | ||
| -globals: (name for name ino window)[0...10] | ||
| +globals: (name for name of window)[0...10] |
View
3
documentation/coffee/object_comprehensions.coffee
| @@ -1,3 +1,4 @@ | ||
| years_old: {max: 10, ida: 9, tim: 11} | ||
| -ages: child + " is " + age for child, age ino years_old | ||
| +ages: for child, age of years_old | ||
| + child + " is " + age |
View
12
documentation/index.html.erb
| @@ -51,7 +51,7 @@ | ||
| <p> | ||
| <b>Latest Version:</b> | ||
| - <a href="http://gemcutter.org/gems/coffee-script">0.2.2</a> | ||
| + <a href="http://gemcutter.org/gems/coffee-script">0.2.3</a> | ||
| </p> | ||
| <h2>Table of Contents</h2> | ||
| @@ -415,8 +415,8 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre> | ||
| <%= code_for('range_comprehensions', 'countdown') %> | ||
| <p> | ||
| Comprehensions can also be used to iterate over the keys and values in | ||
| - an object. Use <tt>ino</tt> to signal comprehension over an object instead | ||
| - of an array. | ||
| + an object. Use <tt>of</tt> to signal comprehension over the properties of | ||
| + an object instead of the values in an array. | ||
| </p> | ||
| <%= code_for('object_comprehensions', 'ages.join(", ")') %> | ||
| @@ -588,6 +588,12 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre> | ||
| </ul> | ||
| <h2 id="change_log">Change Log</h2> | ||
| + | ||
| + <p> | ||
| + <b class="header" style="margin-top: 20px;">0.2.3</b> | ||
| + Axed the unsatisfactory <tt>ino</tt> keyword, replacing it with <tt>of</tt> for | ||
| + object comprehensions. They now look like: <tt>for key, value of object</tt>. | ||
| + </p> | ||
| <p> | ||
| <b class="header" style="margin-top: 20px;">0.2.2</b> | ||
View
36
documentation/underscore.html
| @@ -41,7 +41,7 @@ | ||
| <span class="line-numbers"> 22 </span> <span class="Comment"><span class="Comment">#</span> can be used OO-style. This wrapper holds altered versions of all the</span> | ||
| <span class="line-numbers"> 23 </span> <span class="Comment"><span class="Comment">#</span> underscore functions. Wrapped objects may be chained.</span> | ||
| <span class="line-numbers"> 24 </span> <span class="FunctionArgument"> wrapper: obj </span><span class="Storage">=></span> | ||
| -<span class="line-numbers"> 25 </span> <span class="Variable">this</span>.<span class="FunctionName">_wrapped</span><span class="Keyword">:</span> obj | ||
| +<span class="line-numbers"> 25 </span> <span class="FunctionName">this._wrapped</span><span class="Keyword">:</span> obj | ||
| <span class="line-numbers"> 26 </span> <span class="Variable">this</span> | ||
| <span class="line-numbers"> 27 </span> | ||
| <span class="line-numbers"> 28 </span> | ||
| @@ -54,7 +54,7 @@ | ||
| <span class="line-numbers"> 35 </span> | ||
| <span class="line-numbers"> 36 </span> | ||
| <span class="line-numbers"> 37 </span> <span class="Comment"><span class="Comment">#</span> Export the Underscore object for CommonJS.</span> | ||
| -<span class="line-numbers"> 38 </span> <span class="Keyword">if</span> <span class="Keyword">typeof</span>(exports) <span class="Keyword">!</span><span class="Keyword">=</span> <span class="String"><span class="String">'</span>undefined<span class="String">'</span></span> <span class="Keyword">then</span> exports.<span class="FunctionName">_</span><span class="Keyword">:</span> _ | ||
| +<span class="line-numbers"> 38 </span> <span class="Keyword">if</span> <span class="Keyword">typeof</span>(exports) <span class="Keyword">!</span><span class="Keyword">=</span> <span class="String"><span class="String">'</span>undefined<span class="String">'</span></span> <span class="Keyword">then</span> <span class="FunctionName">exports._</span><span class="Keyword">:</span> _ | ||
| <span class="line-numbers"> 39 </span> | ||
| <span class="line-numbers"> 40 </span> | ||
| <span class="line-numbers"> 41 </span> <span class="Comment"><span class="Comment">#</span> Create quick reference variables for speed access to core prototypes.</span> | ||
| @@ -66,7 +66,7 @@ | ||
| <span class="line-numbers"> 47 </span> | ||
| <span class="line-numbers"> 48 </span> | ||
| <span class="line-numbers"> 49 </span> <span class="Comment"><span class="Comment">#</span> Current version.</span> | ||
| -<span class="line-numbers"> 50 </span> _.<span class="FunctionName">VERSION</span><span class="Keyword">:</span> <span class="String"><span class="String">'</span>0.5.5<span class="String">'</span></span> | ||
| +<span class="line-numbers"> 50 </span> <span class="FunctionName">_.VERSION</span><span class="Keyword">:</span> <span class="String"><span class="String">'</span>0.5.5<span class="String">'</span></span> | ||
| <span class="line-numbers"> 51 </span> | ||
| <span class="line-numbers"> 52 </span> | ||
| <span class="line-numbers"> 53 </span> <span class="Comment"><span class="Comment">#</span> ------------------------ Collection Functions: ---------------------------</span> | ||
| @@ -79,7 +79,7 @@ | ||
| <span class="line-numbers"> 60 </span> <span class="Keyword">return</span> obj.forEach(iterator, context) <span class="Keyword">if</span> obj.forEach | ||
| <span class="line-numbers"> 61 </span> <span class="Keyword">if</span> _.isArray(obj) <span class="Keyword">or</span> _.isArguments(obj) | ||
| <span class="line-numbers"> 62 </span> <span class="Keyword">return</span> iterator.call(context, obj[i], i, obj) <span class="Keyword">for</span> i <span class="Keyword">in</span> [<span class="Number">0</span>...obj.length] | ||
| -<span class="line-numbers"> 63 </span> iterator.call(context, val, key, obj) <span class="Keyword">for</span> key, val <span class="Keyword">ino</span> obj | ||
| +<span class="line-numbers"> 63 </span> iterator.call(context, val, key, obj) <span class="Keyword">for</span> key, val <span class="Keyword">of</span> obj | ||
| <span class="line-numbers"> 64 </span> <span class="Keyword">catch</span> e | ||
| <span class="line-numbers"> 65 </span> <span class="Keyword">throw</span> e <span class="Keyword">if</span> e <span class="Keyword">isnt</span> breaker | ||
| <span class="line-numbers"> 66 </span> obj | ||
| @@ -167,7 +167,7 @@ | ||
| <span class="line-numbers"> 148 </span> <span class="Comment"><span class="Comment">#</span> based on '==='.</span> | ||
| <span class="line-numbers"> 149 </span> <span class="FunctionArgument"> _.include: obj, target </span><span class="Storage">=></span> | ||
| <span class="line-numbers"> 150 </span> <span class="Keyword">return</span> _.indexOf(obj, target) <span class="Keyword">isnt</span> <span class="Keyword">-</span><span class="Number">1</span> <span class="Keyword">if</span> _.isArray(obj) | ||
| -<span class="line-numbers"> 151 </span> <span class="Keyword">for</span> key, val <span class="Keyword">ino</span> obj | ||
| +<span class="line-numbers"> 151 </span> <span class="Keyword">for</span> key, val <span class="Keyword">of</span> obj | ||
| <span class="line-numbers"> 152 </span> <span class="Keyword">return</span> <span class="BuiltInConstant">true</span> <span class="Keyword">if</span> val <span class="Keyword">is</span> target | ||
| <span class="line-numbers"> 153 </span> <span class="BuiltInConstant">false</span> | ||
| <span class="line-numbers"> 154 </span> | ||
| @@ -399,7 +399,7 @@ | ||
| <span class="line-numbers"> 380 </span> <span class="Comment"><span class="Comment">#</span> Retrieve the names of an object's properties.</span> | ||
| <span class="line-numbers"> 381 </span> <span class="FunctionArgument"> _.keys: obj </span><span class="Storage">=></span> | ||
| <span class="line-numbers"> 382 </span> <span class="Keyword">return</span> _.range(<span class="Number">0</span>, obj.length) <span class="Keyword">if</span> _.isArray(obj) | ||
| -<span class="line-numbers"> 383 </span> key <span class="Keyword">for</span> key, val <span class="Keyword">ino</span> obj | ||
| +<span class="line-numbers"> 383 </span> key <span class="Keyword">for</span> key, val <span class="Keyword">of</span> obj | ||
| <span class="line-numbers"> 384 </span> | ||
| <span class="line-numbers"> 385 </span> | ||
| <span class="line-numbers"> 386 </span> <span class="Comment"><span class="Comment">#</span> Retrieve the values of an object's properties.</span> | ||
| @@ -414,7 +414,7 @@ | ||
| <span class="line-numbers"> 395 </span> | ||
| <span class="line-numbers"> 396 </span> <span class="Comment"><span class="Comment">#</span> Extend a given object with all of the properties in a source object.</span> | ||
| <span class="line-numbers"> 397 </span> <span class="FunctionArgument"> _.extend: destination, source </span><span class="Storage">=></span> | ||
| -<span class="line-numbers"> 398 </span> <span class="Keyword">for</span> key, val <span class="Keyword">ino</span> source | ||
| +<span class="line-numbers"> 398 </span> <span class="Keyword">for</span> key, val <span class="Keyword">of</span> source | ||
| <span class="line-numbers"> 399 </span> destination[key]<span class="Keyword">:</span> val | ||
| <span class="line-numbers"> 400 </span> destination | ||
| <span class="line-numbers"> 401 </span> | ||
| @@ -522,7 +522,7 @@ | ||
| <span class="line-numbers"> 503 </span> <span class="Comment"><span class="Comment">#</span> Run Underscore.js in noConflict mode, returning the '_' variable to its</span> | ||
| <span class="line-numbers"> 504 </span> <span class="Comment"><span class="Comment">#</span> previous owner. Returns a reference to the Underscore object.</span> | ||
| <span class="line-numbers"> 505 </span> <span class="FunctionArgument"> _.noConflict: </span><span class="Storage">=></span> | ||
| -<span class="line-numbers"> 506 </span> root.<span class="FunctionName">_</span><span class="Keyword">:</span> previousUnderscore | ||
| +<span class="line-numbers"> 506 </span> <span class="FunctionName">root._</span><span class="Keyword">:</span> previousUnderscore | ||
| <span class="line-numbers"> 507 </span> <span class="Variable">this</span> | ||
| <span class="line-numbers"> 508 </span> | ||
| <span class="line-numbers"> 509 </span> | ||
| @@ -561,15 +561,15 @@ | ||
| <span class="line-numbers"> 542 </span> | ||
| <span class="line-numbers"> 543 </span> <span class="Comment"><span class="Comment">#</span> ------------------------------- Aliases ----------------------------------</span> | ||
| <span class="line-numbers"> 544 </span> | ||
| -<span class="line-numbers"> 545 </span> _.<span class="FunctionName">forEach</span><span class="Keyword">:</span> _.each | ||
| -<span class="line-numbers"> 546 </span> _.<span class="FunctionName">foldl</span><span class="Keyword">:</span> _.<span class="FunctionName">inject</span><span class="Keyword">:</span> _.reduce | ||
| -<span class="line-numbers"> 547 </span> _.<span class="FunctionName">foldr</span><span class="Keyword">:</span> _.reduceRight | ||
| -<span class="line-numbers"> 548 </span> _.<span class="FunctionName">filter</span><span class="Keyword">:</span> _.select | ||
| -<span class="line-numbers"> 549 </span> _.<span class="FunctionName">every</span><span class="Keyword">:</span> _.all | ||
| -<span class="line-numbers"> 550 </span> _.<span class="FunctionName">some</span><span class="Keyword">:</span> _.any | ||
| -<span class="line-numbers"> 551 </span> _.<span class="FunctionName">head</span><span class="Keyword">:</span> _.first | ||
| -<span class="line-numbers"> 552 </span> _.<span class="FunctionName">tail</span><span class="Keyword">:</span> _.rest | ||
| -<span class="line-numbers"> 553 </span> _.<span class="FunctionName">methods</span><span class="Keyword">:</span> _.functions | ||
| +<span class="line-numbers"> 545 </span> <span class="FunctionName">_.forEach</span><span class="Keyword">:</span> _.each | ||
| +<span class="line-numbers"> 546 </span> <span class="FunctionName">_.foldl</span><span class="Keyword">:</span> <span class="FunctionName">_.inject</span><span class="Keyword">:</span> _.reduce | ||
| +<span class="line-numbers"> 547 </span> <span class="FunctionName">_.foldr</span><span class="Keyword">:</span> _.reduceRight | ||
| +<span class="line-numbers"> 548 </span> <span class="FunctionName">_.filter</span><span class="Keyword">:</span> _.select | ||
| +<span class="line-numbers"> 549 </span> <span class="FunctionName">_.every</span><span class="Keyword">:</span> _.all | ||
| +<span class="line-numbers"> 550 </span> <span class="FunctionName">_.some</span><span class="Keyword">:</span> _.any | ||
| +<span class="line-numbers"> 551 </span> <span class="FunctionName">_.head</span><span class="Keyword">:</span> _.first | ||
| +<span class="line-numbers"> 552 </span> <span class="FunctionName">_.tail</span><span class="Keyword">:</span> _.rest | ||
| +<span class="line-numbers"> 553 </span> <span class="FunctionName">_.methods</span><span class="Keyword">:</span> _.functions | ||
| <span class="line-numbers"> 554 </span> | ||
| <span class="line-numbers"> 555 </span> | ||
| <span class="line-numbers"> 556 </span> <span class="Comment"><span class="Comment">#</span> /*------------------------ Setup the OOP Wrapper: --------------------------*/</span> | ||
| @@ -605,7 +605,7 @@ | ||
| <span class="line-numbers"> 586 </span> | ||
| <span class="line-numbers"> 587 </span> <span class="Comment"><span class="Comment">#</span> Start chaining a wrapped Underscore object.</span> | ||
| <span class="line-numbers"> 588 </span> <span class="FunctionArgument"> wrapper::chain: </span><span class="Storage">=></span> | ||
| -<span class="line-numbers"> 589 </span> <span class="Variable">this</span>.<span class="FunctionName">_chain</span><span class="Keyword">:</span> <span class="BuiltInConstant">true</span> | ||
| +<span class="line-numbers"> 589 </span> <span class="FunctionName">this._chain</span><span class="Keyword">:</span> <span class="BuiltInConstant">true</span> | ||
| <span class="line-numbers"> 590 </span> <span class="Variable">this</span> | ||
| <span class="line-numbers"> 591 </span> | ||
| <span class="line-numbers"> 592 </span> | ||
View
205
examples/potion.coffee
| @@ -0,0 +1,205 @@ | ||
| +# Examples from _why's Potion, the Readme and "Potion: A Short Pamphlet". | ||
| + | ||
| +# 5 times: "Odelay!" print. | ||
| + | ||
| +print("Odelay!") for i in [1..5] | ||
| + | ||
| + | ||
| +# add = (x, y): x + y. | ||
| +# add(2, 4) string print | ||
| + | ||
| +add: x, y => x + y | ||
| +print(add(2, 4)) | ||
| + | ||
| + | ||
| +# loop: 'quaff' print. | ||
| + | ||
| +while true | ||
| + print('quaff') | ||
| + | ||
| + | ||
| +# ('cheese', 'bread', 'mayo') at (1) print | ||
| + | ||
| +print(['cheese', 'bread', 'mayo'][1]) | ||
| + | ||
| + | ||
| +# (language='Potion', pointless=true) at (key='language') print | ||
| + | ||
| +print({language: 'Potion', pointless: true}['language']) | ||
| + | ||
| + | ||
| +# minus = (x, y): x - y. | ||
| +# minus (y=10, x=6) | ||
| + | ||
| +minus: x, y => x - y | ||
| +minus(6, 10) | ||
| + | ||
| + | ||
| +# foods = ('cheese', 'bread', 'mayo') | ||
| +# foods (2) | ||
| + | ||
| +foods: ['cheese', 'bread', 'mayo'] | ||
| +foods[2] | ||
| + | ||
| + | ||
| +# (dog='canine', cat='feline', fox='vulpine') each (key, val): | ||
| +# (key, ' is a ', val) join print. | ||
| + | ||
| +for key, val of {dog: 'canine', cat: 'feline', fox: 'vulpine'} | ||
| + print(key + ' is a ' + val) | ||
| + | ||
| + | ||
| +# Person = class: /name, /age, /sex. | ||
| +# Person print = (): | ||
| +# ('My name is ', /name, '.') join print. | ||
| + | ||
| +Person: => | ||
| +Person::print: => | ||
| + print('My name is ' + this.name + '.') | ||
| + | ||
| + | ||
| +# p = Person () | ||
| +# p /name string print | ||
| + | ||
| +p: new Person() | ||
| +print(p.name) | ||
| + | ||
| + | ||
| +# Policeman = Person class (rank): /rank = rank. | ||
| +# Policeman print = (): | ||
| +# ('My name is ', /name, ' and I'm a ', /rank, '.') join print. | ||
| +# | ||
| +# Policeman ('Constable') print | ||
| + | ||
| +Policeman: rank => this.rank: rank | ||
| +Policeman extends Person | ||
| +Policeman::print: => | ||
| + print('My name is ' + this.name + " and I'm a " + this.rank + '.') | ||
| + | ||
| +print(new Policeman('Constable')) | ||
| + | ||
| + | ||
| +# app = [window (width=200, height=400) | ||
| +# [para 'Welcome.', button 'OK']] | ||
| +# app first name | ||
| + | ||
| +app = { | ||
| + window: {width: 200, height: 200} | ||
| + para: 'Welcome.' | ||
| + button: 'OK' | ||
| +} | ||
| +app.window | ||
| + | ||
| + | ||
| +# x = 1 | ||
| +# y = 2 | ||
| +# | ||
| +# x = 1, y = 2 | ||
| + | ||
| +x: 1 | ||
| +y: 2 | ||
| + | ||
| +x: 1; y: 2 | ||
| + | ||
| + | ||
| +# table = (language='Potion' | ||
| +# pointless=true) | ||
| + | ||
| +table: { | ||
| + language: 'Potion' | ||
| + pointless: yes | ||
| +} | ||
| + | ||
| + | ||
| +# # this foul business... | ||
| +# String length = (): 10. | ||
| + | ||
| +# this foul business... | ||
| +String::length: => 10 | ||
| + | ||
| + | ||
| +# block = : | ||
| +# 'potion' print. | ||
| + | ||
| +block: => | ||
| + print('potion') | ||
| + | ||
| + | ||
| +# if (age > 100): 'ancient'. | ||
| + | ||
| +if age > 100 then 'ancient' | ||
| + | ||
| + | ||
| +# author = | ||
| +# if (title == 'Jonathan Strange & Mr. Norrell'): | ||
| +# 'Susanna Clarke'. | ||
| +# elsif (title == 'The Star Diaries'): | ||
| +# 'Stanislaw Lem'. | ||
| +# elsif (title == 'The Slynx'): | ||
| +# 'Tatyana Tolstaya'. | ||
| +# else: | ||
| +# '... probably Philip K. Dick'. | ||
| + | ||
| +switch author | ||
| + when 'Jonathan Strange & Mr. Norrell' | ||
| + 'Susanna Clarke' | ||
| + when 'The Star Diaries' | ||
| + 'Stanislaw Lem' | ||
| + when 'The Slynx' | ||
| + 'Tatyana Tolstaya' | ||
| + else | ||
| + '... probably Philip K. Dick' | ||
| + | ||
| + | ||
| +# count = 8 | ||
| +# while (count > 0): | ||
| +# 'quaff' print | ||
| +# count--. | ||
| + | ||
| +count: 8 | ||
| +while count > 0 | ||
| + print('quaff') | ||
| + count-- | ||
| + | ||
| + | ||
| +# 1 to 5 (a): | ||
| +# a string print. | ||
| + | ||
| +print(a) for a in [1..5] | ||
| + | ||
| + | ||
| +# if (3 ?gender): | ||
| +# "Huh? Numbers are sexed? That's amazing." print. | ||
| + | ||
| +if (3).gender? | ||
| + print("Huh? Numbers are sexed? That's amazing.") | ||
| + | ||
| + | ||
| +# HomePage get = (url): | ||
| +# session = url query ? at ('session'). | ||
| + | ||
| +HomePage::get: url => | ||
| + session: url.query.session if url.query? | ||
| + | ||
| + | ||
| +# BTree = class: /left, /right. | ||
| +# b = BTree () | ||
| +# b /left = BTree () | ||
| +# b /right = BTree () | ||
| + | ||
| +BTree: => | ||
| +b: new BTree() | ||
| +b.left: new BTree() | ||
| +b.right: new BTree() | ||
| + | ||
| + | ||
| +# BTree = class: /left, /right. | ||
| +# b = BTree () | ||
| +# | ||
| +# if (b ? /left): | ||
| +# 'left path found!' print. | ||
| + | ||
| +BTree: => | ||
| +b: new BTree() | ||
| + | ||
| +print('left path found!') if b.left? |
Oops, something went wrong.