diff --git a/syntaxes/GDScript.tmLanguage.json b/syntaxes/GDScript.tmLanguage.json index 58a7b4b..a9fa893 100644 --- a/syntaxes/GDScript.tmLanguage.json +++ b/syntaxes/GDScript.tmLanguage.json @@ -181,13 +181,19 @@ { "begin": "[\\\"\\']", "end": "[\\\"\\']", - "name": "constant.character.escape" + "name": "constant.character.escape", + "patterns": [ + { + "match": "%", + "name": "keyword.control.flow" + } + ] } ] }, "nodepath_function": { "name": "meta.literal.nodepath.gdscript", - "begin": "(get_node_or_null|has_node|find_node|get_node)\\s*(?:\\()", + "begin": "(get_node_or_null|has_node|has_node_and_resource|find_node|get_node)\\s*(?:\\()", "beginCaptures": { "1": { "name": "entity.name.function.gdscript" @@ -198,7 +204,13 @@ { "begin": "[\\\"\\']", "end": "[\\\"\\']", - "name": "constant.character.escape" + "name": "constant.character.escape", + "patterns": [ + { + "match": "%", + "name": "keyword.control.flow" + } + ] } ] }, @@ -404,16 +416,62 @@ "name": "support.function.builtin.gdscript" }, "builtin_get_node_shorthand": { - "match": "(\\$)([\\\"\\'].*[\\\"\\']|(?:[a-zA-Z_][a-zA-Z_0-9]*/?)*)", + "patterns": [ + { + "include": "#builtin_get_node_shorthand_quoted" + }, + { + "include": "#builtin_get_node_shorthand_bare" + } + ] + }, + "builtin_get_node_shorthand_quoted": { + "begin": "(\\$)([\\\"\\'])", + "end": "([\\\"\\'])", "name": "support.function.builtin.shorthand.gdscript", - "captures": { + "beginCaptures": { "1": { "name": "keyword.control.flow" }, "2": { "name": "constant.character.escape" } - } + }, + "endCaptures": { + "1": { + "name": "constant.character.escape" + } + }, + "patterns": [ + { + "match": "%", + "name": "keyword.control.flow" + }, + { + "match": "[^%]*", + "name": "constant.character.escape" + } + ] + }, + "builtin_get_node_shorthand_bare": { + "begin": "(\\$)", + "end": "[^\\w%]", + "name": "support.function.builtin.shorthand.gdscript", + "beginCaptures": { + "1": { + "name": "keyword.control.flow" + } + }, + "patterns": [ + { + "match": "[a-zA-Z_][a-zA-Z_0-9]*/?", + "name": "constant.character.escape" + }, + { + "match": "%[a-zA-Z_][a-zA-Z_0-9]*/?", + "name": "invalid.illegal.escape.gdscript" + } + ] }, "decorators": { "match": "(@)(export|export_color_no_alpha|export_dir|export_enum|export_exp_easing|export_file|export_flags|export_flags_2d_navigation|export_flags_2d_physics|export_flags_2d_render|export_flags_3d_navigation|export_flags_3d_physics|export_flags_3d_render|export_global_dir|export_global_file|export_multiline|export_node_path|export_placeholder|export_range|icon|onready|rpc|tool|warning_ignore)\\b", diff --git a/syntaxes/examples/gdscript1.gd b/syntaxes/examples/gdscript1.gd index 82f1e26..7ad26f1 100644 --- a/syntaxes/examples/gdscript1.gd +++ b/syntaxes/examples/gdscript1.gd @@ -127,6 +127,27 @@ onready var node_h = get_node("../Sibling") if has_node('Child') and get_node('Child').has_node('GrandChild'): pass +#! NOTE: scene unique nodes can only appear inside quoted nodepaths, not +#! naked ones using the $ operator + +onready var bad_unique_nodepath_a = $%Unique +onready var bad_unique_nodepath_b = $Child/%Unique +onready var bad_unique_nodepath_c = $Child/GrandChild/%Unique +onready var bad_unique_nodepath_c = $Child/%Unique/ChildOfUnique + +onready var node_i = $"%Unique" +onready var node_ii = get_node("%Unique") +onready var node_iii = NodePath("%Unique") +onready var node_j = $'%Unique/Child' +onready var node_jj = get_node('%Unique/Child') +onready var node_jjj = NodePath('%Unique/Child') +onready var node_k = $"%Unique/%UniqueChild" +onready var node_kk = get_node("%Unique/%UniqueChild") +onready var node_kkk = NodePath("%Unique/%UniqueChild") + +if has_node('%Unique') and get_node('%Child').has_node('%GrandChild'): + pass + onready var node_i = $badlyNamedChild onready var node_j = $badlyNamedChild/badly_named_grandchild