From 65fa2d21758ae59568e14b9a4a95493add5ae74b Mon Sep 17 00:00:00 2001 From: Nicolas Cannasse Date: Tue, 1 Sep 2015 23:34:10 +0200 Subject: [PATCH] fixed =/== and >= handling in parser (close #33) --- Test.hx | 5 ++++- hscript/Parser.hx | 13 ++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Test.hx b/Test.hx index 48e6fa0..ab43822 100644 --- a/Test.hx +++ b/Test.hx @@ -2,8 +2,9 @@ import hscript.Macro; class Test { - static function test(x,v:Dynamic,?vars : Dynamic) { + static function test(x,v:Dynamic,?vars : Dynamic,allowTypes=false) { var p = new hscript.Parser(); + p.allowTypes = allowTypes; var program = p.parseString(x); var bytes = hscript.Bytes.encode(program); program = hscript.Bytes.decode(bytes); @@ -86,6 +87,8 @@ class Test { test("function bug(){ \n }\nbug().x", null); test("1 + 2 == 3", true); test("-2 == 3 - 5", true); + test("var x=-3; x", -3); + test("var a:Array=[1,2,4]; a[2]", 4, null, true); trace("Done"); } diff --git a/hscript/Parser.hx b/hscript/Parser.hx index 00cb7bb..b9bdb87 100644 --- a/hscript/Parser.hx +++ b/hscript/Parser.hx @@ -735,7 +735,12 @@ class Parser { t = token(); switch( t ) { case TComma: continue; - case TOp(op): if( op == ">" ) break; + case TOp(op): + if( op == ">" ) break; + if( op.charCodeAt(0) == ">".code ) { + tokens.add(TOp(op.substr(1))); + break; + } default: } unexpected(t); @@ -1049,6 +1054,12 @@ class Parser { case 34: return TConst( CString(readString(34)) ); case 63: return TQuestion; case 58: return TDoubleDot; + case '='.code: + char = readChar(); + if( char == '='.code ) + return TOp("=="); + this.char = char; + return TOp("="); default: if( ops[char] ) { var op = String.fromCharCode(char);