From f62d891c63ef2dc2a3bed9feffed3cd9d79c8cc4 Mon Sep 17 00:00:00 2001 From: ncannasse Date: Thu, 23 Nov 2017 12:17:23 +0100 Subject: [PATCH] reduce OpNeg(CInt/CFloat) to negative Int/Float like haxe parser does --- hscript/Parser.hx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/hscript/Parser.hx b/hscript/Parser.hx index 20ea34e..9072086 100644 --- a/hscript/Parser.hx +++ b/hscript/Parser.hx @@ -400,8 +400,19 @@ class Parser { } return mk(EBlock(a),p1); case TOp(op): - if( unops.exists(op) ) - return makeUnop(op,parseExpr()); + if( unops.exists(op) ) { + var start = tokenMin; + var e = parseExpr(); + if( op == "-" ) + switch( expr(e) ) { + case EConst(CInt(i)): + return mk(EConst(CInt(-i)), start, pmax(e)); + case EConst(CFloat(f)): + return mk(EConst(CFloat(-f)), start, pmax(e)); + default: + } + return makeUnop(op,e); + } return unexpected(tk); case TBkOpen: var a = new Array();