|
@@ -376,6 +376,11 @@ static bool _is_hex(CharType c) {
|
|
|
return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
|
|
|
}
|
|
|
|
|
|
+static bool _is_bin(CharType c) {
|
|
|
+
|
|
|
+ return (c == '0' || c == '1');
|
|
|
+}
|
|
|
+
|
|
|
void GDScriptTokenizerText::_make_token(Token p_type) {
|
|
|
|
|
|
TokenData &tk = tk_rb[tk_rb_pos];
|
|
@@ -877,6 +882,7 @@ void GDScriptTokenizerText::_advance() {
|
|
|
bool period_found = false;
|
|
|
bool exponent_found = false;
|
|
|
bool hexa_found = false;
|
|
|
+ bool bin_found = false;
|
|
|
bool sign_found = false;
|
|
|
|
|
|
String str;
|
|
@@ -887,16 +893,28 @@ void GDScriptTokenizerText::_advance() {
|
|
|
if (period_found || exponent_found) {
|
|
|
_make_error("Invalid numeric constant at '.'");
|
|
|
return;
|
|
|
+ } else if (bin_found) {
|
|
|
+ _make_error("Invalid binary constant at '.'");
|
|
|
+ return;
|
|
|
+ } else if (hexa_found) {
|
|
|
+ _make_error("Invalid hexadecimal constant at '.'");
|
|
|
+ return;
|
|
|
}
|
|
|
period_found = true;
|
|
|
} else if (GETCHAR(i) == 'x') {
|
|
|
- if (hexa_found || str.length() != 1 || !((i == 1 && str[0] == '0') || (i == 2 && str[1] == '0' && str[0] == '-'))) {
|
|
|
+ if (hexa_found || bin_found || str.length() != 1 || !((i == 1 && str[0] == '0') || (i == 2 && str[1] == '0' && str[0] == '-'))) {
|
|
|
_make_error("Invalid numeric constant at 'x'");
|
|
|
return;
|
|
|
}
|
|
|
hexa_found = true;
|
|
|
+ } else if (GETCHAR(i) == 'b') {
|
|
|
+ if (hexa_found || bin_found || str.length() != 1 || !((i == 1 && str[0] == '0') || (i == 2 && str[1] == '0' && str[0] == '-'))) {
|
|
|
+ _make_error("Invalid numeric constant at 'b'");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ bin_found = true;
|
|
|
} else if (!hexa_found && GETCHAR(i) == 'e') {
|
|
|
- if (exponent_found) {
|
|
|
+ if (exponent_found || bin_found) {
|
|
|
_make_error("Invalid numeric constant at 'e'");
|
|
|
return;
|
|
|
}
|
|
@@ -905,6 +923,8 @@ void GDScriptTokenizerText::_advance() {
|
|
|
//all ok
|
|
|
} else if (hexa_found && _is_hex(GETCHAR(i))) {
|
|
|
|
|
|
+ } else if (bin_found && _is_bin(GETCHAR(i))) {
|
|
|
+
|
|
|
} else if ((GETCHAR(i) == '-' || GETCHAR(i) == '+') && exponent_found) {
|
|
|
if (sign_found) {
|
|
|
_make_error("Invalid numeric constant at '-'");
|
|
@@ -930,6 +950,9 @@ void GDScriptTokenizerText::_advance() {
|
|
|
if (hexa_found) {
|
|
|
int64_t val = str.hex_to_int64();
|
|
|
_make_constant(val);
|
|
|
+ } else if (bin_found) {
|
|
|
+ int64_t val = str.bin_to_int64();
|
|
|
+ _make_constant(val);
|
|
|
} else if (period_found || exponent_found) {
|
|
|
double val = str.to_double();
|
|
|
_make_constant(val);
|