diff --git a/TestHScript.hx b/TestHScript.hx index eb50d11..db27955 100644 --- a/TestHScript.hx +++ b/TestHScript.hx @@ -131,6 +131,38 @@ class TestHScript extends TestCase { assertScript("pt2?.pt?.x", 10, vars); } + function testIsOperator():Void { + var vars = { + String: String, + Bool: Bool, + Int: Int, + Float: Float, + Dynamic: Dynamic + } + assertScript("10 is Int", true, vars); + assertScript("10.0 is Int", true, vars); + assertScript("10.1 is Int", false, vars); + assertScript("10 is Float", true, vars); + assertScript("10.0 is Float", true, vars); + assertScript("10.1 is Float", true, vars); + assertScript("10 is String", false, vars); + assertScript('"hscript" is String', true, vars); + assertScript('"" is String', true, vars); + assertScript('true is Bool', true, vars); + assertScript('false is Bool', true, vars); + assertScript('0 is Bool', false, vars); + assertScript('1 is Bool', false, vars); + assertScript('1 is Bool', false, vars); + assertScript("10 is Dynamic", true, vars); + assertScript("10.1 is Dynamic", true, vars); + assertScript('"hscript" is Dynamic', true, vars); + assertScript('null is Int', false, vars); + assertScript('null is Float', false, vars); + assertScript('null is String', false, vars); + assertScript('null is Bool', false, vars); + assertScript('null is Dynamic', false, vars); + } + function testMap():Void { var objKey = { ok:true }; var vars = { diff --git a/hscript/Interp.hx b/hscript/Interp.hx index e33c669..4663239 100644 --- a/hscript/Interp.hx +++ b/hscript/Interp.hx @@ -116,6 +116,7 @@ class Interp { binops.set("&&",function(e1,e2) return me.expr(e1) == true && me.expr(e2) == true); binops.set("=",assign); binops.set("...",function(e1,e2) return new #if (haxe_211 || haxe3) IntIterator #else IntIter #end(me.expr(e1),me.expr(e2))); + binops.set("is",function(e1,e2) return #if (haxe_ver >= 4.2) Std.isOfType #else Std.is #end (me.expr(e1), me.expr(e2))); assignOp("+=",function(v1:Dynamic,v2:Dynamic) return v1 + v2); assignOp("-=",function(v1:Float,v2:Float) return v1 - v2); assignOp("*=",function(v1:Float,v2:Float) return v1 * v2); diff --git a/hscript/Parser.hx b/hscript/Parser.hx index af93198..12c51e7 100644 --- a/hscript/Parser.hx +++ b/hscript/Parser.hx @@ -804,6 +804,8 @@ class Parser { return parseExprNext(mk(EUnop(op,false,e1),pmin(e1))); } return makeBinop(op,e1,parseExpr()); + case TId(op) if ( op == 'is' ): + return makeBinop(op,e1,parseExpr()); case TDot: var field = getIdent(); return parseExprNext(mk(EField(e1,field),pmin(e1)));