Skip to content

Commit 86abd40

Browse files
committed
chore: close #10
1 parent d6550fd commit 86abd40

2 files changed

Lines changed: 204 additions & 61 deletions

File tree

gdscript_lexer.py

Lines changed: 195 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from pygments.lexer import RegexLexer, include, bygroups, words, combined
22
from pygments.token import (
33
Keyword,
4+
Literal,
45
Name,
56
Comment,
67
String,
@@ -58,160 +59,247 @@ def innerstring_rules(ttype):
5859
(r":\n", Punctuation),
5960
(r"\\", Punctuation),
6061
],
62+
# NOTE: from github.com/godotengine/godot-docs
6163
"keywords": [
6264
(
6365
words(
6466
(
65-
"and",
66-
"in",
67-
"not",
68-
"or",
69-
"as",
70-
"breakpoint",
67+
# modules/gdscript/gdscript.cpp - GDScriptLanguage::get_reserved_words()
68+
# Declarations.
7169
"class",
7270
"class_name",
73-
"extends",
74-
"is",
75-
"setget",
76-
"signal",
77-
"tool",
7871
"const",
7972
"enum",
80-
"export",
81-
"onready",
73+
"extends",
74+
"func",
75+
"namespace", # Reserved for potential future use.
76+
"signal",
8277
"static",
78+
"trait", # Reserved for potential future use.
8379
"var",
80+
# Other keywords.
81+
"await",
82+
"breakpoint",
83+
"self",
84+
"super",
85+
"yield", # Reserved for potential future use.
86+
# Not really keywords, but used in property syntax.
87+
"set",
88+
"get",
89+
),
90+
suffix=r"\b",
91+
),
92+
Keyword,
93+
),
94+
(
95+
words(
96+
(
97+
# modules/gdscript/gdscript.cpp - GDScriptLanguage::get_reserved_words()
98+
# Control flow.
8499
"break",
85100
"continue",
86-
"if",
87101
"elif",
88102
"else",
89103
"for",
104+
"if",
105+
"match",
90106
"pass",
91107
"return",
92-
"match",
108+
"when",
93109
"while",
94-
"remote",
95-
"master",
96-
"puppet",
97-
"remotesync",
98-
"mastersync",
99-
"puppetsync",
110+
"yield",
100111
),
101112
suffix=r"\b",
102113
),
103-
Keyword,
114+
# Custom control flow class used to give control flow keywords a different color,
115+
# like in the Godot editor.
116+
Keyword.ControlFlow,
104117
),
105118
],
119+
106120
"builtins": [
107121
(
108122
words(
109-
("yield", "true", "false", "PI", "TAU", "NAN", "INF"),
123+
("true", "false", "PI", "TAU", "NAN", "INF"),
110124
prefix=r"(?<!\.)",
111125
suffix=r"\b",
112126
),
113-
Name.Builtin,
127+
Literal,
114128
),
129+
# NOTE: from github.com/godotengine/godot-docs
115130
(
116131
words(
117132
(
118-
"Color8",
119-
"ColorN",
133+
# doc/classes/@GlobalScope.xml
120134
"abs",
135+
"absf",
136+
"absi",
121137
"acos",
138+
"acosh",
139+
"angle_difference",
122140
"asin",
123-
"assert",
141+
"asinh",
124142
"atan",
125143
"atan2",
126-
"bytes2var",
144+
"atanh",
145+
"bezier_derivative",
146+
"bezier_interpolate",
147+
"bytes_to_var",
148+
"bytes_to_var_with_objects",
127149
"ceil",
128-
"char",
150+
"ceilf",
151+
"ceili",
129152
"clamp",
130-
"convert",
153+
"clampf",
154+
"clampi",
131155
"cos",
132156
"cosh",
133-
"db2linear",
134-
"decimals",
135-
"dectime",
136-
"deg2rad",
137-
"dict2inst",
157+
"cubic_interpolate",
158+
"cubic_interpolate_angle",
159+
"cubic_interpolate_angle_in_time",
160+
"cubic_interpolate_in_time",
161+
"db_to_linear",
162+
"deg_to_rad",
138163
"ease",
164+
"error_string",
139165
"exp",
140166
"floor",
167+
"floorf",
168+
"floori",
141169
"fmod",
142170
"fposmod",
143-
"funcref",
144171
"hash",
145-
"inst2dict",
146172
"instance_from_id",
173+
"inverse_lerp",
174+
"is_equal_approx",
175+
"is_finite",
147176
"is_inf",
177+
"is_instance_id_valid",
178+
"is_instance_valid",
148179
"is_nan",
180+
"is_same",
181+
"is_zero_approx",
149182
"lerp",
150-
"linear2db",
151-
"load",
183+
"lerp_angle",
184+
"lerpf",
185+
"linear_to_db",
152186
"log",
153187
"max",
188+
"maxf",
189+
"maxi",
154190
"min",
191+
"minf",
192+
"mini",
193+
"move_toward",
155194
"nearest_po2",
195+
"pingpong",
196+
"posmod",
156197
"pow",
157-
"preload",
158198
"print",
159-
"print_stack",
199+
"print_rich",
200+
"print_verbose",
160201
"printerr",
161202
"printraw",
162203
"prints",
163204
"printt",
164-
"rad2deg",
165-
"rand_range",
166-
"rand_seed",
205+
"push_error",
206+
"push_warning",
207+
"rad_to_deg",
208+
"rand_from_seed",
167209
"randf",
210+
"randf_range",
211+
"randfn",
168212
"randi",
213+
"randi_range",
169214
"randomize",
170-
"range",
215+
"remap",
216+
"rid_allocate_id",
217+
"rid_from_int64",
218+
"rotate_toward",
171219
"round",
220+
"roundf",
221+
"roundi",
172222
"seed",
173223
"sign",
224+
"signf",
225+
"signi",
174226
"sin",
175227
"sinh",
228+
"smoothstep",
229+
"snapped",
230+
"snappedf",
231+
"snappedi",
176232
"sqrt",
177-
"stepify",
233+
"step_decimals",
178234
"str",
179-
"str2var",
180-
"tan",
235+
"str_to_var",
181236
"tan",
182237
"tanh",
183-
"type_exist",
238+
"type_convert",
239+
"type_string",
184240
"typeof",
185-
"var2bytes",
186-
"var2str",
241+
"var_to_bytes",
242+
"var_to_bytes_with_objects",
243+
"var_to_str",
187244
"weakref",
245+
"wrap",
246+
"wrapf",
247+
"wrapi",
248+
249+
# modules/gdscript/doc_classes/@GDScript.xml
250+
"Color8",
251+
"assert",
252+
"char",
253+
"convert",
254+
"dict_to_inst",
255+
"get_stack",
256+
"inst_to_dict",
257+
"is_instance_of",
258+
"len",
259+
"load",
260+
"preload",
261+
"print_debug",
262+
"print_stack",
263+
"range",
264+
"type_exists",
188265
),
189266
prefix=r"(?<!\.)",
190267
suffix=r"\b",
191268
),
192269
Name.Builtin.Function,
193270
),
194271
(r"((?<!\.)(self)" r")\b", Name.Builtin.Pseudo),
272+
# NOTE: from github.com/godotengine/godot-docs
195273
(
196274
words(
197275
(
276+
# core/variant/variant.cpp - Variant::get_type_name()
277+
# `Nil` is excluded because it is not allowed in GDScript.
198278
"bool",
199279
"int",
200280
"float",
201281
"String",
202-
"NodePath",
203282
"Vector2",
283+
"Vector2i",
204284
"Rect2",
285+
"Rect2i",
205286
"Transform2D",
206287
"Vector3",
207-
"Rect3",
288+
"Vector3i",
289+
"Vector4",
290+
"Vector4i",
208291
"Plane",
209-
"Quat",
292+
"AABB",
293+
"Quaternion",
210294
"Basis",
211-
"Transform",
295+
"Transform3D",
296+
"Projection",
212297
"Color",
213298
"RID",
214299
"Object",
300+
"Callable",
301+
"Signal",
302+
"StringName",
215303
"NodePath",
216304
"Dictionary",
217305
"Array",
@@ -224,14 +312,61 @@ def innerstring_rules(ttype):
224312
"PackedVector2Array",
225313
"PackedVector3Array",
226314
"PackedColorArray",
227-
"null",
315+
"PackedVector4Array",
316+
# The following are also considered types in GDScript.
317+
"Variant",
228318
"void",
229319
),
230320
prefix=r"(?<!\.)",
231321
suffix=r"\b",
232322
),
233323
Name.Builtin.Type,
234324
),
325+
# NOTE: from github.com/godotengine/godot-docs
326+
(
327+
words(
328+
(
329+
# modules/gdscript/doc_classes/@GDScript.xml
330+
"@export",
331+
"@export_category",
332+
"@export_color_no_alpha",
333+
"@export_custom",
334+
"@export_dir",
335+
"@export_enum",
336+
"@export_exp_easing",
337+
"@export_file",
338+
"@export_flags",
339+
"@export_flags_2d_navigation",
340+
"@export_flags_2d_physics",
341+
"@export_flags_2d_render",
342+
"@export_flags_3d_navigation",
343+
"@export_flags_3d_physics",
344+
"@export_flags_3d_render",
345+
"@export_flags_avoidance",
346+
"@export_global_dir",
347+
"@export_global_file",
348+
"@export_group",
349+
"@export_multiline",
350+
"@export_node_path",
351+
"@export_placeholder",
352+
"@export_range",
353+
"@export_storage",
354+
"@export_subgroup",
355+
"@export_tool_button",
356+
"@icon",
357+
"@onready",
358+
"@rpc",
359+
"@static_unload",
360+
"@tool",
361+
"@warning_ignore",
362+
"@warning_ignore_restore",
363+
"@warning_ignore_start",
364+
),
365+
prefix=r"(?<!\.)",
366+
suffix=r"\b",
367+
),
368+
Name.Decorator,
369+
),
235370
],
236371
"operator": [
237372
(
@@ -244,6 +379,7 @@ def innerstring_rules(ttype):
244379
(r"(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?j?", Number.Float),
245380
(r"\d+[eE][+-]?[0-9]+j?", Number.Float),
246381
(r"0[xX][a-fA-F0-9]+", Number.Hex),
382+
(r"(-)?0[bB]([01]|(?<=[01])_)+", Number.Bin),
247383
(r"\d+j?", Number.Integer),
248384
],
249385
"name": [(r"[a-zA-Z_]\w*", Name)],
@@ -280,6 +416,9 @@ def innerstring_rules(ttype):
280416
include("strings-single"),
281417
include("whitespace"),
282418
],
419+
#######################################################################
420+
# LEXER ENTRY POINT
421+
#######################################################################
283422
"root": [
284423
include("whitespace"),
285424
include("comment"),

0 commit comments

Comments
 (0)