added the instanceof operator to the grammar as an operation node

This commit is contained in:
Jeremy Ashkenas
2009-12-24 11:46:51 -08:00
parent 2e8f03b4cc
commit 5d1ec9d2a9
4 changed files with 24 additions and 3 deletions

View File

@@ -10,8 +10,8 @@ token TRY CATCH FINALLY THROW
token BREAK CONTINUE
token FOR IN WHILE
token SWITCH WHEN
token DELETE INSTANCEOF
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
left "."
right THROW FOR IN WHILE NEW
left UNLESS IF ELSE
@@ -185,6 +185,7 @@ rule
| Expression '&&:' Expression { result = OpNode.new(val[1], val[0], val[2]) }
| DELETE 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"]
# Token matching regexes.
IDENTIFIER = /\A([a-zA-Z$_]\w*)/

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