diff options
author | VolTer <mew.pur.pur@abv.bg> | 2023-03-01 21:08:51 +0100 |
---|---|---|
committer | Yuri Sizov <yuris@humnom.net> | 2023-03-27 16:58:50 +0200 |
commit | 2e37c05fe6aa16625b7e09f3c30c58804405da84 (patch) | |
tree | 73a4f119d2ff47014f1d4679c3631ad6bcdd8e5f /modules | |
parent | 46d475b067dcab6929fa76d1aad9bc6b9453e22b (diff) |
Make GDScript number highlighting stricter
(cherry picked from commit 952703d92155226137fc4bb53c61c8dbc7887ed7)
Diffstat (limited to 'modules')
-rw-r--r-- | modules/gdscript/editor/gdscript_highlighter.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/modules/gdscript/editor/gdscript_highlighter.cpp b/modules/gdscript/editor/gdscript_highlighter.cpp index 5883ec863d..bba11363d5 100644 --- a/modules/gdscript/editor/gdscript_highlighter.cpp +++ b/modules/gdscript/editor/gdscript_highlighter.cpp @@ -294,17 +294,27 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l !(str[j] == '_' && (prev_is_digit || str[j - 1] == 'b' || str[j - 1] == 'x' || str[j - 1] == '.')) && !(str[j] == 'e' && (prev_is_digit || str[j - 1] == '_')) && !(str[j] == '.' && (prev_is_digit || (!prev_is_binary_op && (j > 0 && (str[j - 1] == '-' || str[j - 1] == '+' || str[j - 1] == '~'))))) && - !((str[j] == '-' || str[j] == '+' || str[j] == '~') && !prev_is_binary_op && str[j - 1] != 'e')) { - /* This condition continues Number highlighting in special cases. - 1st row: '+' or '-' after scientific notation; + !((str[j] == '-' || str[j] == '+' || str[j] == '~') && !is_binary_op && !prev_is_binary_op && str[j - 1] != 'e')) { + /* This condition continues number highlighting in special cases. + 1st row: '+' or '-' after scientific notation (like 3e-4); 2nd row: '_' as a numeric separator; 3rd row: Scientific notation 'e' and floating points; 4th row: Floating points inside the number, or leading if after a unary mathematical operator; - 5th row: Multiple unary mathematical operators */ + 5th row: Multiple unary mathematical operators (like ~-7)*/ in_number = false; } - } else if (!is_binary_op && (str[j] == '-' || str[j] == '+' || str[j] == '~' || (str[j] == '.' && str[j + 1] != '.' && (j == 0 || (j > 0 && str[j - 1] != '.'))))) { + } else if (str[j] == '.' && !is_binary_op && is_digit(str[j + 1]) && (j == 0 || (j > 0 && str[j - 1] != '.'))) { + // Start number highlighting from leading decimal points (like .42) in_number = true; + } else if ((str[j] == '-' || str[j] == '+' || str[j] == '~') && !is_binary_op) { + // Only start number highlighting on unary operators if a digit follows them. + int non_op = j + 1; + while (str[non_op] == '-' || str[non_op] == '+' || str[non_op] == '~') { + non_op++; + } + if (is_digit(str[non_op]) || (str[non_op] == '.' && non_op < line_length && is_digit(str[non_op + 1]))) { + in_number = true; + } } if (!in_word && is_unicode_identifier_start(str[j]) && !in_number) { |