Permalink
...
Comparing changes
Open a pull request
- 4 commits
- 10 files changed
- 0 commit comments
- 1 contributor
Unified
Split
Showing
with
1,005 additions
and 938 deletions.
- +7 −2 coffee-script.gemspec
- +5 −0 documentation/index.html.erb
- +5 −0 index.html
- +1 −1 lib/coffee-script.rb
- +4 −2 lib/coffee_script/grammar.y
- +1 −1 lib/coffee_script/lexer.rb
- +3 −2 lib/coffee_script/nodes.rb
- +959 −930 lib/coffee_script/parser.rb
- +10 −0 test/fixtures/execution/keyword_operators.cs
- +10 −0 test/fixtures/execution/keyword_operators.js
View
9
coffee-script.gemspec
| @@ -1,12 +1,17 @@ | ||
| Gem::Specification.new do |s| | ||
| s.name = 'coffee-script' | ||
| - s.version = '0.1.0' # Keep version in sync with coffee-script.rb | ||
| + s.version = '0.1.1' # Keep version in sync with coffee-script.rb | ||
| s.date = '2009-12-24' | ||
| s.homepage = "http://jashkenas.github.com/coffee-script/" | ||
| s.summary = "The CoffeeScript Compiler" | ||
| s.description = <<-EOS | ||
| - CoffeeScript is a little language that compiles into JavaScript. | ||
| + CoffeeScript is a little language that compiles into JavaScript. Think | ||
| + of it as JavaScript's less ostentatious kid brother -- the same genes, | ||
| + roughly the same height, but a different sense of style. Apart from a | ||
| + handful of bonus goodies, statements in CoffeeScript correspond | ||
| + one-to-one with their equivalent in JavaScript, it's just another | ||
| + way of saying it. | ||
| EOS | ||
| s.authors = ['Jeremy Ashkenas'] | ||
View
5
documentation/index.html.erb
| @@ -405,6 +405,11 @@ coffee-script --print app/scripts/*.cs > concatenation.js</pre> | ||
| 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 | ||
| + string manipulation. Techniques for cleaning this up across the board | ||
| + would be appreciated. | ||
| + </li> | ||
| </ul> | ||
| <h2 id="change_log">Change Log</h2> | ||
View
5
index.html
| @@ -784,6 +784,11 @@ <h2 id="contributing">Contributing</h2> | ||
| 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 | ||
| + string manipulation. Techniques for cleaning this up across the board | ||
| + would be appreciated. | ||
| + </li> | ||
| </ul> | ||
| <h2 id="change_log">Change Log</h2> | ||
View
2
lib/coffee-script.rb
| @@ -9,7 +9,7 @@ | ||
| # Namespace for all CoffeeScript internal classes. | ||
| module CoffeeScript | ||
| - VERSION = '0.1.0' # Keep in sync with the gemspec. | ||
| + VERSION = '0.1.1' # Keep in sync with the gemspec. | ||
| # Compile a script (String or IO) to JavaScript. | ||
| def self.compile(script) | ||
View
6
lib/coffee_script/grammar.y
| @@ -10,8 +10,8 @@ token TRY CATCH FINALLY THROW | ||
| token BREAK CONTINUE | ||
| token FOR IN WHILE | ||
| token SWITCH WHEN | ||
| +token DELETE INSTANCEOF TYPEOF | ||
| token SUPER | ||
| -token DELETE | ||
| token NEWLINE | ||
| token COMMENT | ||
| token JS | ||
| @@ -27,7 +27,7 @@ prechigh | ||
| right '==' '!=' IS AINT | ||
| left '&&' '||' AND OR | ||
| right '-=' '+=' '/=' '*=' | ||
| - right DELETE | ||
| + right DELETE INSTANCEOF TYPEOF | ||
| left "." | ||
| right THROW FOR IN WHILE NEW | ||
| left UNLESS IF ELSE | ||
| @@ -185,6 +185,8 @@ rule | ||
| | Expression '&&:' Expression { result = OpNode.new(val[1], val[0], val[2]) } | ||
| | DELETE Expression { result = OpNode.new(val[0], val[1]) } | ||
| + | TYPEOF Expression { result = OpNode.new(val[0], val[1]) } | ||
| + | Expression INSTANCEOF Expression { result = OpNode.new(val[1], val[0], val[2]) } | ||
| ; | ||
| # Function definition. | ||
View
2
lib/coffee_script/lexer.rb
| @@ -15,7 +15,7 @@ class Lexer | ||
| "for", "in", "while", | ||
| "switch", "when", | ||
| "super", | ||
| - "delete"] | ||
| + "delete", "instanceof", "typeof"] | ||
| # Token matching regexes. | ||
| IDENTIFIER = /\A([a-zA-Z$_]\w*)/ | ||
View
5
lib/coffee_script/nodes.rb
| @@ -342,7 +342,8 @@ class OpNode < Node | ||
| "aint" => "!==", | ||
| 'not' => '!', | ||
| } | ||
| - CONDITIONALS = ['||:', '&&:'] | ||
| + CONDITIONALS = ['||:', '&&:'] | ||
| + PREFIX_OPERATORS = ['typeof', 'delete'] | ||
| attr_reader :operator, :first, :second | ||
| @@ -369,7 +370,7 @@ def compile_conditional(o) | ||
| end | ||
| def compile_unary(o) | ||
| - space = @operator.to_s == 'delete' ? ' ' : '' | ||
| + space = PREFIX_OPERATORS.include?(@operator.to_s) ? ' ' : '' | ||
| parts = [@operator.to_s, space, @first.compile(o)] | ||
| parts.reverse! if @flip | ||
| parts.join('') | ||
View
10
test/fixtures/execution/keyword_operators.cs
| @@ -0,0 +1,10 @@ | ||
| +a: 5 | ||
| +atype: typeof a | ||
| + | ||
| +b: "hello" | ||
| +btype: typeof b | ||
| + | ||
| +Klass: => . | ||
| +k: new Klass() | ||
| + | ||
| +print(atype is 'number' and btype is 'string' and k instanceof Klass) |
View
10
test/fixtures/execution/keyword_operators.js
| @@ -0,0 +1,10 @@ | ||
| +(function(){ | ||
| + var a = 5; | ||
| + var atype = typeof a; | ||
| + var b = "hello"; | ||
| + var btype = typeof b; | ||
| + var Klass = function() { | ||
| + }; | ||
| + var k = new Klass(); | ||
| + print(atype === 'number' && btype === 'string' && k instanceof Klass); | ||
| +})(); |