Skip to content

Commit c291b22

Browse files
authored
Merge pull request #10182 from dalexeev/update-gdscript-syntax-highlighter
Update GDScript syntax highlighter
2 parents 7cb7a6a + b646c65 commit c291b22

File tree

1 file changed

+51
-23
lines changed

1 file changed

+51
-23
lines changed

_extensions/gdscript.py

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ def innerstring_rules(ttype):
8080
(r"[]{}:(),;[]", Punctuation),
8181
(r"(\\)(\n)", Whitespace),
8282
(r"\\", Text),
83-
(r"(in|and|or|not)\b", Operator.Word),
83+
# modules/gdscript/gdscript.cpp - GDScriptLanguage::get_reserved_words()
84+
# Operators.
85+
(r"(and|as|in|is|not|or)\b", Operator.Word),
8486
(
8587
r"!=|==|<<|>>|&&|\+=|-=|\*=|/=|%=|&=|\|=|\|\||[-~+/*%=<>&^.!|$]",
8688
Operator,
@@ -138,26 +140,28 @@ def innerstring_rules(ttype):
138140
(
139141
words(
140142
(
141-
"and",
142-
"await",
143-
"in",
144-
"get",
145-
"set",
146-
"not",
147-
"or",
148-
"as",
149-
"breakpoint",
143+
# modules/gdscript/gdscript.cpp - GDScriptLanguage::get_reserved_words()
144+
# Declarations.
150145
"class",
151146
"class_name",
147+
"const",
148+
"enum",
152149
"extends",
153-
"is",
154150
"func",
151+
"namespace", # Reserved for potential future use.
155152
"signal",
156-
"const",
157-
"enum",
158153
"static",
154+
"trait", # Reserved for potential future use.
159155
"var",
156+
# Other keywords.
157+
"await",
158+
"breakpoint",
159+
"self",
160160
"super",
161+
"yield", # Reserved for potential future use.
162+
# Not really keywords, but used in property syntax.
163+
"set",
164+
"get",
161165
),
162166
suffix=r"\b",
163167
),
@@ -168,12 +172,14 @@ def innerstring_rules(ttype):
168172
(
169173
words(
170174
(
175+
# modules/gdscript/gdscript.cpp - GDScriptLanguage::get_reserved_words()
176+
# Control flow.
171177
"break",
172178
"continue",
173179
"elif",
174180
"else",
175-
"if",
176181
"for",
182+
"if",
177183
"match",
178184
"pass",
179185
"return",
@@ -196,9 +202,13 @@ def innerstring_rules(ttype):
196202
"absf",
197203
"absi",
198204
"acos",
205+
"acosh",
206+
"angle_difference",
199207
"asin",
208+
"asinh",
200209
"atan",
201210
"atan2",
211+
"atanh",
202212
"bezier_derivative",
203213
"bezier_interpolate",
204214
"bytes_to_var",
@@ -234,6 +244,7 @@ def innerstring_rules(ttype):
234244
"is_instance_id_valid",
235245
"is_instance_valid",
236246
"is_nan",
247+
"is_same",
237248
"is_zero_approx",
238249
"lerp",
239250
"lerp_angle",
@@ -271,6 +282,7 @@ def innerstring_rules(ttype):
271282
"remap",
272283
"rid_allocate_id",
273284
"rid_from_int64",
285+
"rotate_toward",
274286
"round",
275287
"roundf",
276288
"roundi",
@@ -290,6 +302,8 @@ def innerstring_rules(ttype):
290302
"str_to_var",
291303
"tan",
292304
"tanh",
305+
"type_convert",
306+
"type_string",
293307
"typeof",
294308
"var_to_bytes",
295309
"var_to_bytes_with_objects",
@@ -307,47 +321,54 @@ def innerstring_rules(ttype):
307321
"dict_to_inst",
308322
"get_stack",
309323
"inst_to_dict",
324+
"is_instance_of",
310325
"len",
311326
"load",
312327
"preload",
313328
"print_debug",
314329
"print_stack",
315330
"range",
316-
"str",
317331
"type_exists",
318332
),
319333
prefix=r"(?<!\.)",
320334
suffix=r"\b",
321335
),
322336
Name.Builtin,
323337
),
324-
(r"((?<!\.)(self|super|false|true)|(PI|TAU|NAN|INF)" r")\b", Name.Builtin.Pseudo),
338+
# modules/gdscript/gdscript.cpp - GDScriptLanguage::get_reserved_words()
339+
# Special values. Constants.
340+
(r"((?<!\.)(false|null|true)|(INF|NAN|PI|TAU))\b", Name.Builtin.Pseudo),
325341
(
326342
words(
327343
(
344+
# core/variant/variant.cpp - Variant::get_type_name()
345+
# `Nil` is excluded because it is not allowed in GDScript.
328346
"bool",
329347
"int",
330348
"float",
331349
"String",
332-
"StringName",
333-
"NodePath",
334350
"Vector2",
335351
"Vector2i",
336352
"Rect2",
337353
"Rect2i",
338354
"Transform2D",
339355
"Vector3",
340356
"Vector3i",
341-
"AABB",
342-
"Plane",
343-
"Quaternion",
344357
"Vector4",
345358
"Vector4i",
359+
"Plane",
360+
"AABB",
361+
"Quaternion",
346362
"Basis",
347363
"Transform3D",
364+
"Projection",
348365
"Color",
349366
"RID",
350367
"Object",
368+
"Callable",
369+
"Signal",
370+
"StringName",
371+
"NodePath",
351372
"Dictionary",
352373
"Array",
353374
"PackedByteArray",
@@ -358,9 +379,10 @@ def innerstring_rules(ttype):
358379
"PackedStringArray",
359380
"PackedVector2Array",
360381
"PackedVector3Array",
361-
"PackedVector4Array",
362382
"PackedColorArray",
363-
"null",
383+
"PackedVector4Array",
384+
# The following are also considered types in GDScript.
385+
"Variant",
364386
"void",
365387
),
366388
prefix=r"(?<!\.)",
@@ -373,9 +395,11 @@ def innerstring_rules(ttype):
373395
(
374396
words(
375397
(
398+
# modules/gdscript/doc_classes/@GDScript.xml
376399
"@export",
377400
"@export_category",
378401
"@export_color_no_alpha",
402+
"@export_custom",
379403
"@export_dir",
380404
"@export_enum",
381405
"@export_exp_easing",
@@ -387,17 +411,21 @@ def innerstring_rules(ttype):
387411
"@export_flags_3d_navigation",
388412
"@export_flags_3d_physics",
389413
"@export_flags_3d_render",
414+
"@export_flags_avoidance",
390415
"@export_global_dir",
391416
"@export_global_file",
392417
"@export_group",
393418
"@export_multiline",
394419
"@export_node_path",
395420
"@export_placeholder",
396421
"@export_range",
422+
"@export_storage",
397423
"@export_subgroup",
424+
"@export_tool_button",
398425
"@icon",
399426
"@onready",
400427
"@rpc",
428+
"@static_unload",
401429
"@tool",
402430
"@warning_ignore",
403431
),

0 commit comments

Comments
 (0)