From cfa357cbc325f5295372de43dd35a72518d76da5 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Mon, 11 Jan 2010 00:01:16 -0500 Subject: [PATCH] CoffeeScript 0.2.3, with 'of', not 'ino' --- coffee-script.gemspec | 2 +- .../coffee/expressions_comprehension.coffee | 2 +- .../coffee/object_comprehensions.coffee | 2 +- documentation/index.html.erb | 12 +++++-- documentation/underscore.html | 36 +++++++++---------- examples/potion.coffee | 2 +- examples/underscore.coffee | 8 ++--- index.html | 20 +++++++---- lib/coffee-script.rb | 2 +- .../Syntaxes/CoffeeScript.tmLanguage | 4 +-- lib/coffee_script/grammar.y | 6 ++-- lib/coffee_script/lexer.rb | 2 +- package.json | 2 +- .../execution/test_array_comprehension.coffee | 4 +-- 14 files changed, 58 insertions(+), 46 deletions(-) diff --git a/coffee-script.gemspec b/coffee-script.gemspec index b1114071..902be5bd 100644 --- a/coffee-script.gemspec +++ b/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/" diff --git a/documentation/coffee/expressions_comprehension.coffee b/documentation/coffee/expressions_comprehension.coffee index 2a4d2be2..4c51e3f5 100644 --- a/documentation/coffee/expressions_comprehension.coffee +++ b/documentation/coffee/expressions_comprehension.coffee @@ -1,3 +1,3 @@ # The first ten global properties. -globals: (name for name ino window)[0...10] \ No newline at end of file +globals: (name for name of window)[0...10] \ No newline at end of file diff --git a/documentation/coffee/object_comprehensions.coffee b/documentation/coffee/object_comprehensions.coffee index ba88f448..bf582af8 100644 --- a/documentation/coffee/object_comprehensions.coffee +++ b/documentation/coffee/object_comprehensions.coffee @@ -1,4 +1,4 @@ years_old: {max: 10, ida: 9, tim: 11} -ages: for child, age ino years_old +ages: for child, age of years_old child + " is " + age \ No newline at end of file diff --git a/documentation/index.html.erb b/documentation/index.html.erb index b4185c50..f79ff39f 100644 --- a/documentation/index.html.erb +++ b/documentation/index.html.erb @@ -51,7 +51,7 @@

Latest Version: - 0.2.2 + 0.2.3

Table of Contents

@@ -415,8 +415,8 @@ coffee --print app/scripts/*.coffee > concatenation.js <%= code_for('range_comprehensions', 'countdown') %>

Comprehensions can also be used to iterate over the keys and values in - an object. Use ino to signal comprehension over an object instead - of an array. + an object. Use of to signal comprehension over the properties of + an object instead of the values in an array.

<%= code_for('object_comprehensions', 'ages.join(", ")') %> @@ -588,6 +588,12 @@ coffee --print app/scripts/*.coffee > concatenation.js

Change Log

+ +

+ 0.2.3 + Axed the unsatisfactory ino keyword, replacing it with of for + object comprehensions. They now look like: for key, value of object. +

0.2.2 diff --git a/documentation/underscore.html b/documentation/underscore.html index 7ad08ae8..5ce7f0cc 100644 --- a/documentation/underscore.html +++ b/documentation/underscore.html @@ -41,7 +41,7 @@ 22 # can be used OO-style. This wrapper holds altered versions of all the 23 # underscore functions. Wrapped objects may be chained. 24 wrapper: obj => - 25 this._wrapped: obj + 25 this._wrapped: obj 26 this 27 28 @@ -54,7 +54,7 @@ 35 36 37 # Export the Underscore object for CommonJS. - 38 if typeof(exports) != 'undefined' then exports._: _ + 38 if typeof(exports) != 'undefined' then exports._: _ 39 40 41 # Create quick reference variables for speed access to core prototypes. @@ -66,7 +66,7 @@ 47 48 49 # Current version. - 50 _.VERSION: '0.5.5' + 50 _.VERSION: '0.5.5' 51 52 53 # ------------------------ Collection Functions: --------------------------- @@ -79,7 +79,7 @@ 60 return obj.forEach(iterator, context) if obj.forEach 61 if _.isArray(obj) or _.isArguments(obj) 62 return iterator.call(context, obj[i], i, obj) for i in [0...obj.length] - 63 iterator.call(context, val, key, obj) for key, val ino obj + 63 iterator.call(context, val, key, obj) for key, val of obj 64 catch e 65 throw e if e isnt breaker 66 obj @@ -167,7 +167,7 @@ 148 # based on '==='. 149 _.include: obj, target => 150 return _.indexOf(obj, target) isnt -1 if _.isArray(obj) - 151 for key, val ino obj + 151 for key, val of obj 152 return true if val is target 153 false 154 @@ -399,7 +399,7 @@ 380 # Retrieve the names of an object's properties. 381 _.keys: obj => 382 return _.range(0, obj.length) if _.isArray(obj) - 383 key for key, val ino obj + 383 key for key, val of obj 384 385 386 # Retrieve the values of an object's properties. @@ -414,7 +414,7 @@ 395 396 # Extend a given object with all of the properties in a source object. 397 _.extend: destination, source => - 398 for key, val ino source + 398 for key, val of source 399 destination[key]: val 400 destination 401 @@ -522,7 +522,7 @@ 503 # Run Underscore.js in noConflict mode, returning the '_' variable to its 504 # previous owner. Returns a reference to the Underscore object. 505 _.noConflict: => - 506 root._: previousUnderscore + 506 root._: previousUnderscore 507 this 508 509 @@ -561,15 +561,15 @@ 542 543 # ------------------------------- Aliases ---------------------------------- 544 - 545 _.forEach: _.each - 546 _.foldl: _.inject: _.reduce - 547 _.foldr: _.reduceRight - 548 _.filter: _.select - 549 _.every: _.all - 550 _.some: _.any - 551 _.head: _.first - 552 _.tail: _.rest - 553 _.methods: _.functions + 545 _.forEach: _.each + 546 _.foldl: _.inject: _.reduce + 547 _.foldr: _.reduceRight + 548 _.filter: _.select + 549 _.every: _.all + 550 _.some: _.any + 551 _.head: _.first + 552 _.tail: _.rest + 553 _.methods: _.functions 554 555 556 # /*------------------------ Setup the OOP Wrapper: --------------------------*/ @@ -605,7 +605,7 @@ 586 587 # Start chaining a wrapped Underscore object. 588 wrapper::chain: => - 589 this._chain: true + 589 this._chain: true 590 this 591 592 diff --git a/examples/potion.coffee b/examples/potion.coffee index 7e45ca40..de8f72c5 100644 --- a/examples/potion.coffee +++ b/examples/potion.coffee @@ -45,7 +45,7 @@ foods[2] # (dog='canine', cat='feline', fox='vulpine') each (key, val): # (key, ' is a ', val) join print. -for key, val ino {dog: 'canine', cat: 'feline', fox: 'vulpine'} +for key, val of {dog: 'canine', cat: 'feline', fox: 'vulpine'} print(key + ' is a ' + val) diff --git a/examples/underscore.coffee b/examples/underscore.coffee index 8da8cc58..edc3cb9a 100644 --- a/examples/underscore.coffee +++ b/examples/underscore.coffee @@ -60,7 +60,7 @@ return obj.forEach(iterator, context) if obj.forEach if _.isArray(obj) or _.isArguments(obj) return iterator.call(context, obj[i], i, obj) for i in [0...obj.length] - iterator.call(context, val, key, obj) for key, val ino obj + iterator.call(context, val, key, obj) for key, val of obj catch e throw e if e isnt breaker obj @@ -148,7 +148,7 @@ # based on '==='. _.include: obj, target => return _.indexOf(obj, target) isnt -1 if _.isArray(obj) - for key, val ino obj + for key, val of obj return true if val is target false @@ -380,7 +380,7 @@ # Retrieve the names of an object's properties. _.keys: obj => return _.range(0, obj.length) if _.isArray(obj) - key for key, val ino obj + key for key, val of obj # Retrieve the values of an object's properties. @@ -395,7 +395,7 @@ # Extend a given object with all of the properties in a source object. _.extend: destination, source => - for key, val ino source + for key, val of source destination[key]: val destination diff --git a/index.html b/index.html index 7c992eda..63bfc390 100644 --- a/index.html +++ b/index.html @@ -37,7 +37,7 @@

Latest Version: - 0.2.2 + 0.2.3

Table of Contents

@@ -782,12 +782,12 @@ egg_delivery = function egg_delivery() { ;alert(countdown);'>run: countdown

Comprehensions can also be used to iterate over the keys and values in - an object. Use ino to signal comprehension over an object instead - of an array. + an object. Use of to signal comprehension over the properties of + an object instead of the values in an array.

years_old: {max: 10, ida: 9, tim: 11}
 
-ages: for child, age ino years_old
+ages: for child, age of years_old
   child + " is " + age
 
var __a, __b, age, ages, child, years_old;
 years_old = {
@@ -928,7 +928,7 @@ six = (one = 1) + (two = 2) + (three = 3);
     

# The first ten global properties.
 
-globals: (name for name ino window)[0...10]
+globals: (name for name of window)[0...10]
 
var __a, __b, globals, name;
 // The first ten global properties.
 globals = ((function() {
@@ -1002,13 +1002,13 @@ globals = ((function() {
 Animal::move: meters =>
   alert(this.name + " moved " + meters + "m.")
 
-Snake: name => this.name: name
+Snake: name => this.name: name
 Snake extends Animal
 Snake::move: =>
   alert("Slithering...")
   super(5)
 
-Horse: name => this.name: name
+Horse: name => this.name: name
 Horse extends Animal
 Horse::move: =>
   alert("Galloping...")
@@ -1281,6 +1281,12 @@ world...";
     
 
     

Change Log

+ +

+ 0.2.3 + Axed the unsatisfactory ino keyword, replacing it with of for + object comprehensions. They now look like: for key, value of object. +

0.2.2 diff --git a/lib/coffee-script.rb b/lib/coffee-script.rb index 839b1e61..e6944231 100644 --- a/lib/coffee-script.rb +++ b/lib/coffee-script.rb @@ -10,7 +10,7 @@ require "coffee_script/parse_error" # Namespace for all CoffeeScript internal classes. module CoffeeScript - VERSION = '0.2.2' # Keep in sync with the gemspec. + VERSION = '0.2.3' # Keep in sync with the gemspec. # Compile a script (String or IO) to JavaScript. def self.compile(script, options={}) diff --git a/lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage b/lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage index 6cc3c32a..5a60ab24 100644 --- a/lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage +++ b/lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage @@ -208,7 +208,7 @@ match - \b(break|by|catch|continue|else|finally|for|if|return|switch|then|throw|try|unless|when|while)\b + \b(break|by|catch|continue|else|finally|for|in|of|if|return|switch|then|throw|try|unless|when|while)\b name keyword.control.coffee @@ -263,7 +263,7 @@ match - !|%|&|\*|\/|\-\-|\-|\+\+|\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\?|\|\||\:|\*=|(?<!\()/=|%=|\+=|\-=|&=|\^=|\b(in|ino|instanceof|new|delete|typeof|and|or|is|isnt|not)\b + !|%|&|\*|\/|\-\-|\-|\+\+|\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\?|\|\||\:|\*=|(?<!\()/=|%=|\+=|\-=|&=|\^=|\b(instanceof|new|delete|typeof|and|or|is|isnt|not)\b name keyword.operator.coffee diff --git a/lib/coffee_script/grammar.y b/lib/coffee_script/grammar.y index 12567351..457b1713 100644 --- a/lib/coffee_script/grammar.y +++ b/lib/coffee_script/grammar.y @@ -8,7 +8,7 @@ token IDENTIFIER PROPERTY_ACCESS PROTOTYPE_ACCESS token CODE PARAM NEW RETURN token TRY CATCH FINALLY THROW token BREAK CONTINUE -token FOR IN INO BY WHEN WHILE +token FOR IN OF BY WHEN WHILE token SWITCH LEADING_WHEN token DELETE INSTANCEOF TYPEOF token SUPER EXTENDS @@ -34,7 +34,7 @@ prechigh left '.' right INDENT left OUTDENT - right WHEN LEADING_WHEN IN INO BY + right WHEN LEADING_WHEN IN OF BY right THROW FOR NEW SUPER left EXTENDS left ASSIGN '||=' '&&=' @@ -361,7 +361,7 @@ rule # The source of the array comprehension can optionally be filtered. ForSource: IN Expression { result = {:source => val[1]} } - | INO Expression { result = {:source => val[1], :object => true} } + | OF Expression { result = {:source => val[1], :object => true} } | ForSource WHEN Expression { result = val[0].merge(:filter => val[2]) } | ForSource diff --git a/lib/coffee_script/lexer.rb b/lib/coffee_script/lexer.rb index a629be28..575d7108 100644 --- a/lib/coffee_script/lexer.rb +++ b/lib/coffee_script/lexer.rb @@ -12,7 +12,7 @@ module CoffeeScript "new", "return", "try", "catch", "finally", "throw", "break", "continue", - "for", "in", "ino", "by", "where", "while", + "for", "in", "of", "by", "where", "while", "switch", "when", "super", "extends", "arguments", diff --git a/package.json b/package.json index 537848a1..59d5d3a3 100644 --- a/package.json +++ b/package.json @@ -5,5 +5,5 @@ "description": "Unfancy JavaScript", "keywords": ["javascript", "language"], "author": "Jeremy Ashkenas", - "version": "0.2.2" + "version": "0.2.3" } diff --git a/test/fixtures/execution/test_array_comprehension.coffee b/test/fixtures/execution/test_array_comprehension.coffee index 7bde3d83..5599ba2f 100644 --- a/test/fixtures/execution/test_array_comprehension.coffee +++ b/test/fixtures/execution/test_array_comprehension.coffee @@ -5,8 +5,8 @@ print(results.join(',') is '2,18') obj: {one: 1, two: 2, three: 3} -names: key + '!' for key ino obj -odds: key + '!' for key, value ino obj when value % 2 isnt 0 +names: key + '!' for key of obj +odds: key + '!' for key, value of obj when value % 2 isnt 0 print(names.join(' ') is "one! two! three!") print(odds.join(' ') is "one! three!")