From 96762b2a1c20522a702287e818ff00e7579bbbf8 Mon Sep 17 00:00:00 2001 From: Daelon Suzuka Date: Thu, 12 Oct 2023 02:51:44 -0400 Subject: [PATCH] Multiple highlighting improvements --- syntaxes/GDScript.tmLanguage.json | 94 +++++++++++++++++++++++++------ syntaxes/examples/gdscript1.gd | 27 ++++++--- syntaxes/examples/gdscript2.gd | 9 +++ 3 files changed, 106 insertions(+), 24 deletions(-) diff --git a/syntaxes/GDScript.tmLanguage.json b/syntaxes/GDScript.tmLanguage.json index 2cdcd20d4..148e27c49 100644 --- a/syntaxes/GDScript.tmLanguage.json +++ b/syntaxes/GDScript.tmLanguage.json @@ -132,7 +132,23 @@ "end": "'''" }, { - "begin": "\"", + "begin": "(r)?\"\"\"", + "end": "\"\"\"", + "patterns": [ + { + "name": "constant.character.escape.untitled", + "match": "\\\\." + } + ], + "beginCaptures": { + "1": { + "name": "constant.character.escape.untitled" + } + }, + "name": "string.quoted.triple.gdscript" + }, + { + "begin": "(r)?\"", "end": "\"", "patterns": [ { @@ -140,10 +156,15 @@ "match": "\\\\." } ], + "beginCaptures": { + "1": { + "name": "constant.character.escape.untitled" + } + }, "name": "string.quoted.double.gdscript" }, { - "begin": "'", + "begin": "(r)?'", "end": "'", "patterns": [ { @@ -151,6 +172,11 @@ "match": "\\\\." } ], + "beginCaptures": { + "1": { + "name": "constant.character.escape.untitled" + } + }, "name": "string.quoted.single.gdscript" }, { @@ -309,37 +335,41 @@ "name": "keyword.operator.assignment.gdscript" }, "control_flow": { - "match": "\\b(?i:if|elif|else|for|while|break|continue|pass|return|match|yield|await)\\b", + "match": "\\b(?:if|elif|else|for|while|break|continue|pass|return|match|yield|await)\\b", "name": "keyword.control.gdscript" }, "keywords": { - "match": "\\b(?i:class|class_name|extends|is|onready|tool|static|export|as|void|enum|preload|assert|breakpoint|rpc|sync|remote|master|puppet|slave|remotesync|mastersync|puppetsync|trait|namespace)\\b", + "match": "\\b(?:class|class_name|extends|is|onready|tool|static|export|as|void|enum|preload|assert|breakpoint|rpc|sync|remote|master|puppet|slave|remotesync|mastersync|puppetsync|trait|namespace)\\b", "name": "keyword.language.gdscript" }, "letter": { - "match": "\\b(?i:true|false|null)\\b", + "match": "\\b(?:true|false|null)\\b", "name": "constant.language.gdscript" }, "numbers": { "patterns": [ { - "match": "\\b(?i:0x\\h*)\\b", + "match": "\\b(?:0b[01_]+)\\b", + "name": "constant.numeric.integer.binary.gdscript" + }, + { + "match": "\\b(?:0x[0-9A-Fa-f_]+)\\b", "name": "constant.numeric.integer.hexadecimal.gdscript" }, { - "match": "\\b(?i:(\\d+\\.\\d*(e[\\-\\+]?\\d+)?))\\b", + "match": "\\b(?:([0-9_]+\\.[0-9_]*(e[\\-\\+]?[0-9_]+)?))\\b", "name": "constant.numeric.float.gdscript" }, { - "match": "\\b(?i:(\\.\\d+(e[\\-\\+]?\\d+)?))\\b", + "match": "\\b(?:(\\.[0-9_]+(e[\\-\\+]?[0-9_]+)?))\\b", "name": "constant.numeric.float.gdscript" }, { - "match": "\\b(?i:(\\d+e[\\-\\+]?\\d+))\\b", + "match": "\\b(?:([0-9_]+e[\\-\\+]?\\[0-9_]))\\b", "name": "constant.numeric.float.gdscript" }, { - "match": "\\b\\d+\\b", + "match": "\\b[0-9_]+\\b", "name": "constant.numeric.integer.gdscript" } ] @@ -494,6 +524,9 @@ }, "builtin_get_node_shorthand": { "patterns": [ + { + "include": "#builtin_get_nodepath_shorthand_quoted" + }, { "include": "#builtin_get_node_shorthand_quoted" }, @@ -502,6 +535,30 @@ } ] }, + "builtin_get_nodepath_shorthand_quoted": { + "begin": "(&|\\^|@)([\"'])", + "end": "([\"'])", + "name": "support.function.builtin.shorthand.gdscript", + "beginCaptures": { + "1": { + "name": "variable.other.enummember" + }, + "2": { + "name": "constant.character.escape" + } + }, + "endCaptures": { + "1": { + "name": "constant.character.escape" + } + }, + "patterns": [ + { + "match": "[^%^\"^']*", + "name": "constant.character.escape" + } + ] + }, "builtin_get_node_shorthand_quoted": { "begin": "(\\$)([\"'])", "end": "([\"'])", @@ -531,7 +588,7 @@ ] }, "builtin_get_node_shorthand_bare": { - "begin": "(\\$)", + "begin": "(\\$|%)", "end": "[^\\w%]", "name": "support.function.builtin.shorthand.gdscript", "beginCaptures": { @@ -541,12 +598,15 @@ }, "patterns": [ { - "match": "[a-zA-Z_]\\w*/?", - "name": "constant.character.escape" - }, - { - "match": "%[a-zA-Z_]\\w*/?", - "name": "invalid.illegal.escape.gdscript" + "match": "(%)?([a-zA-Z_]\\w*/?)", + "captures": { + "1": { + "name": "keyword.control.flow" + }, + "2": { + "name": "constant.character.escape" + } + } } ] }, diff --git a/syntaxes/examples/gdscript1.gd b/syntaxes/examples/gdscript1.gd index 41384cc3f..7618bbb27 100644 --- a/syntaxes/examples/gdscript1.gd +++ b/syntaxes/examples/gdscript1.gd @@ -12,6 +12,16 @@ var var_f:bool=true var var_g : string = 'foo' var var_h : string = "foo" +var integer = 12_345_678 # Equal to 12345678. +var floating = 3.141_592_7 # Equal to 3.1415927. +var hex_a = 0x10101 +var hex_b = 0x8080_0000_ffff # Equal to 0x80800000ffff. +var binary_a = 0b10101 +var binary_b = 0b11_00_11_00 # Equal to 0b11001100. + +var sci_float_a = 58.1e-10 +var sci_float_b = 58.1e-10 + const const_a = 0 const const_b = true const const_c := true @@ -126,6 +136,9 @@ func one_line_fn() -> void: return # ------------------------------------------------------------------------------ +var stringname_nodepath_a = @"test" +var stringname_nodepath_b = @'test' + var q = "double quotes" var r = 'single quotes' var s = """ @@ -158,13 +171,13 @@ 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 unique_node_a = $%Unique +onready var unique_node_b = $Child/%Unique +onready var unique_node_c = $Child/GrandChild/%Unique +onready var unique_node_d = $Child/%Unique/ChildOfUnique +onready var unique_node_e = %Unique +onready var unique_node_f = %Unique/Child +onready var unique_node_g = %Unique/%UniqueChild onready var node_i = $"%Unique" onready var node_ii = get_node("%Unique") diff --git a/syntaxes/examples/gdscript2.gd b/syntaxes/examples/gdscript2.gd index 482022d46..54d541337 100644 --- a/syntaxes/examples/gdscript2.gd +++ b/syntaxes/examples/gdscript2.gd @@ -9,6 +9,15 @@ class_name TestClass2 @export var z : String @export_node_path(Resource) var resource_name +var raw_string_a = r"test" +var raw_string_b = r'test' +var raw_string_c = r"""test""" + +var nodepath_a = &"test" +var nodepath_b = &'test' +var stringname_a = ^"test" +var stringname_b = ^'test' + var array_a: Array[int] = [1, 2, 3] var array_b: Array[String] = ['1', '2', '3']