Compare commits

...

4 Commits
0.1.0 ... 0.1.1

Author SHA1 Message Date
Jeremy Ashkenas
a4bc24817d bumping to 0.1.1 2009-12-24 11:59:19 -08:00
Jeremy Ashkenas
9eeac9b272 added the typeof operater as an OpNode 2009-12-24 11:50:44 -08:00
Jeremy Ashkenas
f859eb6cec added the instanceof operator to the grammar as an operation node 2009-12-24 11:46:51 -08:00
Jeremy Ashkenas
b29afc2c09 another wish 2009-12-24 10:31:44 -08:00
10 changed files with 1042 additions and 975 deletions

View File

@@ -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 File

@@ -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 File

@@ -784,6 +784,11 @@ world...";
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 File

@@ -9,7 +9,7 @@ require "coffee_script/parse_error"
# 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 File

@@ -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 File

@@ -15,7 +15,7 @@ module CoffeeScript
"for", "in", "while",
"switch", "when",
"super",
"delete"]
"delete", "instanceof", "typeof"]
# Token matching regexes.
IDENTIFIER = /\A([a-zA-Z$_]\w*)/

View File

@@ -342,7 +342,8 @@ module CoffeeScript
"aint" => "!==",
'not' => '!',
}
CONDITIONALS = ['||:', '&&:']
CONDITIONALS = ['||:', '&&:']
PREFIX_OPERATORS = ['typeof', 'delete']
attr_reader :operator, :first, :second
@@ -369,7 +370,7 @@ module CoffeeScript
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('')

File diff suppressed because it is too large Load Diff

View File

@@ -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 File

@@ -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);
})();