From e1f6bad13d0066506940157286d7dcbc4aa98088 Mon Sep 17 00:00:00 2001 From: Nicolas Cannasse Date: Fri, 12 Sep 2008 17:11:05 +0000 Subject: [PATCH] allow .154 and fixed bug in makeBinop --- Test.hx | 2 ++ hscript/Parser.hx | 34 +++++++++++++++++++++++++--------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/Test.hx b/Test.hx index 5726b70..5f6371b 100644 --- a/Test.hx +++ b/Test.hx @@ -17,6 +17,7 @@ class Test { test("-123",-123); test("- 123",-123); test("1.546",1.546); + test(".545",.545); test("'bla'","bla"); test("null",null); test("true",true); @@ -45,6 +46,7 @@ class Test { test("var a = 1; a++; a",2); test("var a = 1; ++a",2); test("var a = 1; a *= 3",3); + test("a = b = 3; a + b",6); test("add(1,2)",3,{ add : function(x,y) return x + y }); test("a.push(5); a.pop() + a.pop()",8,{ a : [3] }); test("if( true ) 1 else 2",1); diff --git a/hscript/Parser.hx b/hscript/Parser.hx index daffb62..1f9ebf5 100644 --- a/hscript/Parser.hx +++ b/hscript/Parser.hx @@ -186,14 +186,14 @@ class Parser { } } - function makeBinop( op, e1, e2 ) { - return switch( e2 ) { + function makeBinop( op, e1, e ) { + return switch( e ) { case EBinop(op2,e2,e3): if( priority(op) > priority(op2) ) EBinop(op2,makeBinop(op,e1,e2),e3); else - EBinop(op,e1,e2); - default: EBinop(op,e1,e2); + EBinop(op,e1,e); + default: EBinop(op,e1,e); } } @@ -486,14 +486,30 @@ class Parser { case 44: return TComma; case 46: char = readChar(s); - if( char != 46 ) { + switch( char ) { + case 48,49,50,51,52,53,54,55,56,57: + var n = char - 48; + var exp = 1; + while( true ) { + char = readChar(s); + exp *= 10; + switch( char ) { + case 48,49,50,51,52,53,54,55,56,57: + n = n * 10 + (char - 48); + default: + this.char = char; + return TConst( CFloat(n/exp) ); + } + } + case 46: + char = readChar(s); + if( char != 46 ) + throw Error.EInvalidChar(char); + return TOp("..."); + default: this.char = char; return TDot; } - char = readChar(s); - if( char != 46 ) - throw Error.EInvalidChar(char); - return TOp("..."); case 123: return TBrOpen; case 125: return TBrClose; case 91: return TBkOpen;