Added underscore support to numbers + binary
This commit is contained in:
@@ -1598,6 +1598,7 @@ class Parser {
|
||||
switch( char ) {
|
||||
case 48,49,50,51,52,53,54,55,56,57:
|
||||
n = n * 10 + (char - 48);
|
||||
case '_'.code:
|
||||
case "e".code, "E".code:
|
||||
var tk = token();
|
||||
var pow : Null<Int> = null;
|
||||
@@ -1641,6 +1642,7 @@ class Parser {
|
||||
n = (n << 4) + (char - 55);
|
||||
case 97,98,99,100,101,102: // a-f
|
||||
n = (n << 4) + (char - 87);
|
||||
case '_'.code:
|
||||
default:
|
||||
this.char = char;
|
||||
return TConst(CInt(n));
|
||||
@@ -1657,6 +1659,7 @@ class Parser {
|
||||
n = haxe.Int32.add(haxe.Int32.shl(n,4), cast (char - 55));
|
||||
case 97,98,99,100,101,102: // a-f
|
||||
n = haxe.Int32.add(haxe.Int32.shl(n,4), cast (char - 87));
|
||||
case '_'.code:
|
||||
default:
|
||||
this.char = char;
|
||||
// we allow to parse hexadecimal Int32 in Neko, but when the value will be
|
||||
@@ -1667,6 +1670,41 @@ class Parser {
|
||||
}
|
||||
}
|
||||
#end
|
||||
case "b".code: // Custom thing, not supported in haxe
|
||||
if( n > 0 || exp > 0 )
|
||||
invalidChar(char);
|
||||
// read binary
|
||||
#if haxe3
|
||||
var n = 0;
|
||||
while( true ) {
|
||||
char = readChar();
|
||||
switch( char ) {
|
||||
case 48,49: // 0-1
|
||||
n = (n << 1) + char - 48;
|
||||
case '_'.code:
|
||||
default:
|
||||
this.char = char;
|
||||
return TConst(CInt(n));
|
||||
}
|
||||
}
|
||||
#else
|
||||
var n = haxe.Int32.ofInt(0);
|
||||
while( true ) {
|
||||
char = readChar();
|
||||
switch( char ) {
|
||||
case 48,49: // 0-1
|
||||
n = haxe.Int32.add(haxe.Int32.shl(n,1), cast (char - 48));
|
||||
case '_'.code:
|
||||
default:
|
||||
this.char = char;
|
||||
// we allow to parse binary Int32 in Neko, but when the value will be
|
||||
// evaluated by Interpreter, a failure will occur if no Int32 operation is
|
||||
// performed
|
||||
var v = try CInt(haxe.Int32.toInt(n)) catch( e : Dynamic ) CInt32(n);
|
||||
return TConst(v);
|
||||
}
|
||||
}
|
||||
#end
|
||||
default:
|
||||
this.char = char;
|
||||
var i = Std.int(n);
|
||||
|
||||
Reference in New Issue
Block a user