From 443ce6fef2ff2115b90d1929d33788fb2afe2636 Mon Sep 17 00:00:00 2001 From: Bojidar Marinov Date: Wed, 15 Nov 2017 22:53:08 +0200 Subject: [PATCH] Allow underscores in GDScript numeric literals Closes #12928 --- modules/gdscript/gd_tokenizer.cpp | 5 ++++- scene/gui/text_edit.cpp | 7 ++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/gdscript/gd_tokenizer.cpp b/modules/gdscript/gd_tokenizer.cpp index 98ac0f473d4..e241eacd4fc 100644 --- a/modules/gdscript/gd_tokenizer.cpp +++ b/modules/gdscript/gd_tokenizer.cpp @@ -885,6 +885,9 @@ void GDTokenizerText::_advance() { return; } sign_found = true; + } else if (GETCHAR(i) == '_') { + i++; + continue; // Included for readability, shouldn't be a part of the string } else break; @@ -897,7 +900,7 @@ void GDTokenizerText::_advance() { return; } - INCPOS(str.length()); + INCPOS(i); if (hexa_found) { int64_t val = str.hex_to_int64(); _make_constant(val); diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 5d429f9f916..6da34cd2639 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -894,17 +894,18 @@ void TextEdit::_notification(int p_what) { is_hex_notation = false; } - // check for dot or 'x' for hex notation in floating point number - if ((str[j] == '.' || str[j] == 'x') && !in_word && prev_is_number && !is_number) { + // check for dot or underscore or 'x' for hex notation in floating point number + if ((str[j] == '.' || str[j] == 'x' || str[j] == '_') && !in_word && prev_is_number && !is_number) { is_number = true; is_symbol = false; + is_char = false; if (str[j] == 'x' && str[j - 1] == '0') { is_hex_notation = true; } } - if (!in_word && _is_char(str[j])) { + if (!in_word && _is_char(str[j]) && !is_number) { in_word = true; }