From f773589a370b3e81359829da5dec3e000f9ecf58 Mon Sep 17 00:00:00 2001 From: Jaime Humberto Macias Bustamante Date: Thu, 26 Jun 2025 16:37:04 -0700 Subject: [PATCH] Improved "is" operator Official implementation of "is" operator. --- hscript/Parser.hx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/hscript/Parser.hx b/hscript/Parser.hx index f9339b1..31aa847 100644 --- a/hscript/Parser.hx +++ b/hscript/Parser.hx @@ -589,7 +589,8 @@ class Parser { return mk(EBinop(op,e1,e),pmin(e1),pmax(e1)); return switch( expr(e) ) { case EBinop(op2,e2,e3): - if( opPriority.get(op) <= opPriority.get(op2) && !opRightAssoc.exists(op) ) + var delta = opPriority.get(op) - opPriority.get(op2); + if( delta < 0 || (delta == 0 && !opRightAssoc.exists(op)) ) mk(EBinop(op2,makeBinop(op,e1,e2),e3),pmin(e1),pmax(e3)); else mk(EBinop(op, e1, e), pmin(e1), pmax(e)); @@ -1275,6 +1276,8 @@ class Parser { return parseExprNext(mk(EUnop(op,false,e1),pmin(e1))); } return makeBinop(op,e1,parseExpr()); + case TId(op) if( opPriority.exists(op) ): + return parseExprNext(makeBinop(op,e1,parseExpr())); case TDot | TQuestionDot: var field = getIdent(); return parseExprNext(mk(EField(e1, field, tk == TQuestionDot), pmin(e1))); @@ -2086,7 +2089,7 @@ class Parser { if( StringTools.isEof(char) ) char = 0; if( !idents[char] ) { this.char = char; - if(id == "is") return TOp("is"); + //if(id == "is") return TOp("is"); return TId(id); } id += String.fromCharCode(char);