summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2022-08-30 09:17:41 +0200
committerGitHub <noreply@github.com>2022-08-30 09:17:41 +0200
commit2a4c1bd7c18daddf1c71692278647880edd24d3a (patch)
treeb5ea9a7b294f50f37df29ced92c32262a1ec2e80
parent21b218c9ea5f46df46448e89fb35fd40f3afdb27 (diff)
parent1342b8ccd6d8a93abe85994b32170011cc9deac9 (diff)
Merge pull request #65052 from MewPurPur/fix-number-highlighting-followup
-rw-r--r--modules/gdscript/editor/gdscript_highlighter.cpp29
1 files changed, 15 insertions, 14 deletions
diff --git a/modules/gdscript/editor/gdscript_highlighter.cpp b/modules/gdscript/editor/gdscript_highlighter.cpp
index 95fc9b34a0..02922086f0 100644
--- a/modules/gdscript/editor/gdscript_highlighter.cpp
+++ b/modules/gdscript/editor/gdscript_highlighter.cpp
@@ -279,23 +279,24 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
in_number = true;
}
- // Special cases for numbers: Unary operators, separator '_', decimal point '.', literals '0x' and '0b', and scientific notation 'e'.
+ // Special cases for numbers
if (in_number && !is_a_digit) {
- if ((str[j] == '+' || str[j] == '-') && j > 0 && str[j - 1] == 'e' && !prev_is_digit) {
- in_number = true;
- } else if ((str[j] == 'e' || str[j] == '_' || str[j] == '.') && prev_is_digit) {
- in_number = true;
- } else if ((str[j] == 'b' || str[j] == 'x') && (j > 0 && str[j - 1] == '0')) {
- in_number = true;
- if (str[j] == 'b') {
- is_bin_notation = true;
- } else if (str[j] == 'x') {
- is_hex_notation = true;
- }
- } else {
+ if (str[j] == 'b' && str[j - 1] == '0') {
+ is_bin_notation = true;
+ } else if (str[j] == 'x' && str[j - 1] == '0') {
+ is_hex_notation = true;
+ } else if (!((str[j] == '-' || str[j] == '+') && str[j - 1] == 'e' && !prev_is_digit) &&
+ !(str[j] == '_' && (prev_is_digit || str[j - 1] == 'b' || str[j - 1] == 'x' || str[j - 1] == '.')) &&
+ !((str[j] == 'e' || str[j] == '.') && (prev_is_digit || str[j - 1] == '_')) &&
+ !((str[j] == '-' || str[j] == '+' || str[j] == '~') && !prev_is_binary_op && str[j - 1] != 'e')) {
+ /* 1st row of condition: '+' or '-' after scientific notation;
+ 2nd row of condition: '_' as a numeric separator;
+ 3rd row of condition: Scientific notation 'e' and floating points;
+ 4th row of condition: Multiple unary operators. */
in_number = false;
}
- } else if ((str[j] == '.' || str[j] == '+' || str[j] == '-' || str[j] == '~') && !is_binary_op) {
+ } else if ((str[j] == '-' || str[j] == '+' || str[j] == '~' || (str[j] == '.' && str[j + 1] != '.' && (j == 0 || (j > 0 && str[j - 1] != '.')))) && !is_binary_op) {
+ // Start a number from unary mathematical operators and floating points, except for '..'
in_number = true;
}