GDScript: Check for missing exponent when parsing numbers

Also forbid multiple underscores in a row as numeric separator.
This commit is contained in:
George Marques 2020-08-31 20:25:15 -03:00
parent f8fa5e4738
commit 164cc8705b
No known key found for this signature in database
GPG Key ID: 046BD46A3201E43D
1 changed files with 32 additions and 0 deletions

View File

@ -621,7 +621,19 @@ GDScriptTokenizer::Token GDScriptTokenizer::number() {
}
// Allow '_' to be used in a number, for readability.
bool previous_was_underscore = false;
while (digit_check_func(_peek()) || _peek() == '_') {
if (_peek() == '_') {
if (previous_was_underscore) {
Token error = make_error(R"(Only one underscore can be used as a numeric separator.)");
error.start_column = column;
error.leftmost_column = column;
error.end_column = column + 1;
error.rightmost_column = column + 1;
push_error(error);
}
previous_was_underscore = true;
}
_advance();
}
@ -672,7 +684,27 @@ GDScriptTokenizer::Token GDScriptTokenizer::number() {
_advance();
}
// Consume exponent digits.
if (!_is_digit(_peek())) {
Token error = make_error(R"(Expected exponent value after "e".)");
error.start_column = column;
error.leftmost_column = column;
error.end_column = column + 1;
error.rightmost_column = column + 1;
push_error(error);
}
previous_was_underscore = false;
while (_is_digit(_peek()) || _peek() == '_') {
if (_peek() == '_') {
if (previous_was_underscore) {
Token error = make_error(R"(Only one underscore can be used as a numeric separator.)");
error.start_column = column;
error.leftmost_column = column;
error.end_column = column + 1;
error.rightmost_column = column + 1;
push_error(error);
}
previous_was_underscore = true;
}
_advance();
}
}