From 023b7349f850ea53e1588488e870faa15f566c07 Mon Sep 17 00:00:00 2001 From: Nicolas Cannasse Date: Tue, 1 Sep 2015 23:46:25 +0200 Subject: [PATCH] allowed /**/ comment (close #34) --- Test.hx | 1 + hscript/Parser.hx | 18 +++++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Test.hx b/Test.hx index ab43822..49fdb4b 100644 --- a/Test.hx +++ b/Test.hx @@ -89,6 +89,7 @@ class Test { test("-2 == 3 - 5", true); test("var x=-3; x", -3); test("var a:Array=[1,2,4]; a[2]", 4, null, true); + test("/**/0", 0); trace("Done"); } diff --git a/hscript/Parser.hx b/hscript/Parser.hx index b9bdb87..6d55306 100644 --- a/hscript/Parser.hx +++ b/hscript/Parser.hx @@ -1066,7 +1066,7 @@ class Parser { while( true ) { char = readChar(); if( !ops[char] ) { - if( op.charCodeAt(0) == 47 ) + if( op.charCodeAt(0) == '/'.code ) return tokenComment(op,char); this.char = char; return TOp(op); @@ -1095,9 +1095,9 @@ class Parser { function tokenComment( op : String, char : Int ) { var c = op.charCodeAt(1); var s = input; - if( c == 47 ) { // comment + if( c == '/'.code ) { // comment try { - while( char != 10 && char != 13 ) { + while( char != '\r'.code && char != '\n'.code ) { incPos(); char = s.readByte(); } @@ -1106,18 +1106,22 @@ class Parser { } return token(); } - if( c == 42 ) { /* comment */ + if( c == '*'.code ) { /* comment */ var old = line; + if( op == "/**/" ) { + this.char = char; + return token(); + } try { while( true ) { - while( char != 42 ) { - if( char == 10 ) line++; + while( char != '*'.code ) { + if( char == '\n'.code ) line++; incPos(); char = s.readByte(); } incPos(); char = s.readByte(); - if( char == 47 ) + if( char == '/'.code ) break; } } catch( e : Dynamic ) {