From 1342b8ccd6d8a93abe85994b32170011cc9deac9 Mon Sep 17 00:00:00 2001 From: VolTer Date: Mon, 29 Aug 2022 19:23:28 +0200 Subject: Follow-up fixes to number highlighting --- modules/gdscript/editor/gdscript_highlighter.cpp | 29 ++++++++++++------------ 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'modules/gdscript') 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; } -- cgit v1.2.3