diff --git a/Test.hx b/Test.hx index 6693e0e..35fba99 100644 --- a/Test.hx +++ b/Test.hx @@ -30,6 +30,7 @@ class Test { test("0 < 0",false); test("-1 <= -1",true); test("1 + 2",3); + test("~545",-546); test("'abc' + 55","abc55"); test("'abc' + 'de'","abcde"); test("-1 + 2",1); diff --git a/hscript/Interp.hx b/hscript/Interp.hx index f593a8e..611fe7e 100644 --- a/hscript/Interp.hx +++ b/hscript/Interp.hx @@ -246,6 +246,12 @@ class Interp { return increment(e,prefix,1); case "--": return increment(e,prefix,-1); + case "~": + #if neko + return haxe.Int32.complement(expr(e)); + #else + return ~expr(e); + #end default: throw Error.EInvalidOp(op); } diff --git a/hscript/Parser.hx b/hscript/Parser.hx index 1f9ebf5..4268cb1 100644 --- a/hscript/Parser.hx +++ b/hscript/Parser.hx @@ -61,7 +61,7 @@ class Parser { public function new() { line = 1; - opChars = "+*/-=!><&|^%"; + opChars = "+*/-=!><&|^%~"; identChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_"; opPriority = [ "...", @@ -74,7 +74,7 @@ class Parser { "*","/", "%" ]; - unopsPrefix = ["!","++","--","-"]; + unopsPrefix = ["!","++","--","-","~"]; unopsSuffix = ["++","--"]; }