fixed =/== and >= handling in parser (close #33)

This commit is contained in:
Nicolas Cannasse
2015-09-01 23:34:10 +02:00
parent 83e7c4a5fe
commit 65fa2d2175
2 changed files with 16 additions and 2 deletions
+4 -1
View File
@@ -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<Dynamic>=[1,2,4]; a[2]", 4, null, true);
trace("Done");
}
+12 -1
View File
@@ -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);