diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-07-17 11:44:01 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-07-17 11:44:01 +0200 |
commit | c2b91e2986c825a9ff04f6cad3aab70665555aa5 (patch) | |
tree | 78811d9ec02e81c088d47c8243cf5c488d7829fa /modules/gdscript | |
parent | a526445fda17872d492327097f1fedb03428eadb (diff) | |
parent | 06e732c3ed85bdbe67702b3778b53c21f8d24c81 (diff) | |
download | redot-engine-c2b91e2986c825a9ff04f6cad3aab70665555aa5.tar.gz |
Merge pull request #94327 from HolonProduction/underscore_identifier
GDScript: Restore support for `Token::UNDERSCORE` in identifiers
Diffstat (limited to 'modules/gdscript')
3 files changed, 19 insertions, 1 deletions
diff --git a/modules/gdscript/gdscript_tokenizer.cpp b/modules/gdscript/gdscript_tokenizer.cpp index 5b1639e250..404b61fb40 100644 --- a/modules/gdscript/gdscript_tokenizer.cpp +++ b/modules/gdscript/gdscript_tokenizer.cpp @@ -574,7 +574,9 @@ GDScriptTokenizer::Token GDScriptTokenizerText::potential_identifier() { if (len == 1 && _peek(-1) == '_') { // Lone underscore. - return make_token(Token::UNDERSCORE); + Token token = make_token(Token::UNDERSCORE); + token.literal = "_"; + return token; } String name(_start, len); diff --git a/modules/gdscript/tests/scripts/runtime/features/single_underscore_node_name.gd b/modules/gdscript/tests/scripts/runtime/features/single_underscore_node_name.gd new file mode 100644 index 0000000000..b07c40b6da --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/single_underscore_node_name.gd @@ -0,0 +1,15 @@ +extends Node + +func test() -> void: + var node1 := Node.new() + node1.name = "_" + var node2 := Node.new() + node2.name = "Child" + var node3 := Node.new() + node3.name = "Child" + + add_child(node1) + node1.add_child(node2) + add_child(node3) + + assert(get_node("_/Child") == $_/Child) diff --git a/modules/gdscript/tests/scripts/runtime/features/single_underscore_node_name.out b/modules/gdscript/tests/scripts/runtime/features/single_underscore_node_name.out new file mode 100644 index 0000000000..d73c5eb7cd --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/single_underscore_node_name.out @@ -0,0 +1 @@ +GDTEST_OK |