Skip to content

Commit d6550fd

Browse files
committed
chore: run ruff:format
1 parent f35520b commit d6550fd

1 file changed

Lines changed: 223 additions & 64 deletions

File tree

gdscript_lexer.py

Lines changed: 223 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
Punctuation,
1111
)
1212

13+
1314
class GDScriptLexer(RegexLexer):
1415
"""
1516
For GDScript source code.
1617
"""
1718

1819
name = "GDScript"
19-
url = 'https://www.godotengine.org'
20+
url = "https://www.godotengine.org"
2021
aliases = ["gdscript", "gd"]
2122
filenames = ["*.gd"]
2223
mimetypes = ["text/x-gdscript", "application/x-gdscript"]
@@ -25,9 +26,11 @@ class GDScriptLexer(RegexLexer):
2526
def innerstring_rules(ttype):
2627
return [
2728
# the old style '%s' % (...) string formatting
28-
(r"%(\(\w+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?"
29+
(
30+
r"%(\(\w+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?"
2931
"[hlL]?[E-GXc-giorsux%]",
30-
String.Interpol),
32+
String.Interpol,
33+
),
3134
# backslashes, quotes, and formatting signs must be parsed one at a time
3235
(r'[^\\\'"%\n]+', ttype),
3336
(r'[\'"\\]', ttype),
@@ -37,60 +40,204 @@ def innerstring_rules(ttype):
3740
]
3841

3942
tokens = {
40-
"whitespace": [(r'\s+', Whitespace)],
43+
"whitespace": [(r"\s+", Whitespace)],
4144
"comment": [
4245
(r"#.*$", Comment.Single),
4346
# """ """ and ''' '''
44-
(r'^(\s*)([rRuUbB]{,2})("""(?:.|\n)*?""")',
45-
bygroups(Whitespace, String.Affix, String.Doc)),
46-
(r"^(\s*)([rRuUbB]{,2})('''(?:.|\n)*?''')",
47-
bygroups(Whitespace, String.Affix, String.Doc)),
47+
(
48+
r'^(\s*)([rRuUbB]{,2})("""(?:.|\n)*?""")',
49+
bygroups(Whitespace, String.Affix, String.Doc),
50+
),
51+
(
52+
r"^(\s*)([rRuUbB]{,2})('''(?:.|\n)*?''')",
53+
bygroups(Whitespace, String.Affix, String.Doc),
54+
),
4855
],
4956
"punctuation": [
5057
(r"[]{}(),:;[]", Punctuation),
5158
(r":\n", Punctuation),
5259
(r"\\", Punctuation),
5360
],
5461
"keywords": [
55-
(words(("and", "in", "not", "or", "as", "breakpoint", "class",
56-
"class_name", "extends", "is", "setget", "signal",
57-
"tool", "const", "enum", "export", "onready", "static",
58-
"var", "break", "continue", "if", "elif", "else", "for",
59-
"pass", "return", "match", "while", "remote", "master",
60-
"puppet", "remotesync", "mastersync", "puppetsync"),
61-
suffix=r"\b"), Keyword),
62+
(
63+
words(
64+
(
65+
"and",
66+
"in",
67+
"not",
68+
"or",
69+
"as",
70+
"breakpoint",
71+
"class",
72+
"class_name",
73+
"extends",
74+
"is",
75+
"setget",
76+
"signal",
77+
"tool",
78+
"const",
79+
"enum",
80+
"export",
81+
"onready",
82+
"static",
83+
"var",
84+
"break",
85+
"continue",
86+
"if",
87+
"elif",
88+
"else",
89+
"for",
90+
"pass",
91+
"return",
92+
"match",
93+
"while",
94+
"remote",
95+
"master",
96+
"puppet",
97+
"remotesync",
98+
"mastersync",
99+
"puppetsync",
100+
),
101+
suffix=r"\b",
102+
),
103+
Keyword,
104+
),
62105
],
63106
"builtins": [
64-
(words(("yield", "true", "false", "PI", "TAU", "NAN", "INF"),
65-
prefix=r"(?<!\.)", suffix=r"\b"),
66-
Name.Builtin),
67-
(words(("Color8", "ColorN", "abs", "acos", "asin", "assert", "atan",
68-
"atan2", "bytes2var", "ceil", "char", "clamp", "convert",
69-
"cos", "cosh", "db2linear", "decimals", "dectime", "deg2rad",
70-
"dict2inst", "ease", "exp", "floor", "fmod", "fposmod",
71-
"funcref", "hash", "inst2dict", "instance_from_id", "is_inf",
72-
"is_nan", "lerp", "linear2db", "load", "log", "max", "min",
73-
"nearest_po2", "pow", "preload", "print", "print_stack",
74-
"printerr", "printraw", "prints", "printt", "rad2deg",
75-
"rand_range", "rand_seed", "randf", "randi", "randomize",
76-
"range", "round", "seed", "sign", "sin", "sinh", "sqrt",
77-
"stepify", "str", "str2var", "tan", "tan", "tanh",
78-
"type_exist", "typeof", "var2bytes", "var2str", "weakref"
79-
), prefix=r"(?<!\.)", suffix=r"\b"),
80-
Name.Builtin.Function),
107+
(
108+
words(
109+
("yield", "true", "false", "PI", "TAU", "NAN", "INF"),
110+
prefix=r"(?<!\.)",
111+
suffix=r"\b",
112+
),
113+
Name.Builtin,
114+
),
115+
(
116+
words(
117+
(
118+
"Color8",
119+
"ColorN",
120+
"abs",
121+
"acos",
122+
"asin",
123+
"assert",
124+
"atan",
125+
"atan2",
126+
"bytes2var",
127+
"ceil",
128+
"char",
129+
"clamp",
130+
"convert",
131+
"cos",
132+
"cosh",
133+
"db2linear",
134+
"decimals",
135+
"dectime",
136+
"deg2rad",
137+
"dict2inst",
138+
"ease",
139+
"exp",
140+
"floor",
141+
"fmod",
142+
"fposmod",
143+
"funcref",
144+
"hash",
145+
"inst2dict",
146+
"instance_from_id",
147+
"is_inf",
148+
"is_nan",
149+
"lerp",
150+
"linear2db",
151+
"load",
152+
"log",
153+
"max",
154+
"min",
155+
"nearest_po2",
156+
"pow",
157+
"preload",
158+
"print",
159+
"print_stack",
160+
"printerr",
161+
"printraw",
162+
"prints",
163+
"printt",
164+
"rad2deg",
165+
"rand_range",
166+
"rand_seed",
167+
"randf",
168+
"randi",
169+
"randomize",
170+
"range",
171+
"round",
172+
"seed",
173+
"sign",
174+
"sin",
175+
"sinh",
176+
"sqrt",
177+
"stepify",
178+
"str",
179+
"str2var",
180+
"tan",
181+
"tan",
182+
"tanh",
183+
"type_exist",
184+
"typeof",
185+
"var2bytes",
186+
"var2str",
187+
"weakref",
188+
),
189+
prefix=r"(?<!\.)",
190+
suffix=r"\b",
191+
),
192+
Name.Builtin.Function,
193+
),
81194
(r"((?<!\.)(self)" r")\b", Name.Builtin.Pseudo),
82-
(words(("bool", "int", "float", "String", "NodePath", "Vector2",
83-
"Rect2", "Transform2D", "Vector3", "Rect3", "Plane", "Quat",
84-
"Basis", "Transform", "Color", "RID", "Object", "NodePath",
85-
"Dictionary", "Array", "PackedByteArray", "PackedInt32Array",
86-
"PackedInt64Array", "PackedFloat32Array", "PackedFloat64Array",
87-
"PackedStringArray", "PackedVector2Array", "PackedVector3Array",
88-
"PackedColorArray", "null", "void"),
89-
prefix=r"(?<!\.)", suffix=r"\b"),
90-
Name.Builtin.Type),
195+
(
196+
words(
197+
(
198+
"bool",
199+
"int",
200+
"float",
201+
"String",
202+
"NodePath",
203+
"Vector2",
204+
"Rect2",
205+
"Transform2D",
206+
"Vector3",
207+
"Rect3",
208+
"Plane",
209+
"Quat",
210+
"Basis",
211+
"Transform",
212+
"Color",
213+
"RID",
214+
"Object",
215+
"NodePath",
216+
"Dictionary",
217+
"Array",
218+
"PackedByteArray",
219+
"PackedInt32Array",
220+
"PackedInt64Array",
221+
"PackedFloat32Array",
222+
"PackedFloat64Array",
223+
"PackedStringArray",
224+
"PackedVector2Array",
225+
"PackedVector3Array",
226+
"PackedColorArray",
227+
"null",
228+
"void",
229+
),
230+
prefix=r"(?<!\.)",
231+
suffix=r"\b",
232+
),
233+
Name.Builtin.Type,
234+
),
91235
],
92236
"operator": [
93-
(r"!=|==|<<|>>|&&|\+=|-=|\*=|/=|%=|&=|\|=|\|\||:=|[-~+/*%=<>&^.!|$]", Operator),
237+
(
238+
r"!=|==|<<|>>|&&|\+=|-=|\*=|/=|%=|&=|\|=|\|\||:=|[-~+/*%=<>&^.!|$]",
239+
Operator,
240+
),
94241
(r"(in|and|or|not)\b", Operator.Word),
95242
],
96243
"numbers": [
@@ -138,44 +285,56 @@ def innerstring_rules(ttype):
138285
include("comment"),
139286
include("punctuation"),
140287
include("builtins"),
141-
142288
# strings
143-
('([rR]|[uUbB][rR]|[rR][uUbB])(""")',
289+
(
290+
'([rR]|[uUbB][rR]|[rR][uUbB])(""")',
144291
bygroups(String.Affix, String.Double),
145-
"triple_double_quotes"),
146-
("([rR]|[uUbB][rR]|[rR][uUbB])(''')",
292+
"triple_double_quotes",
293+
),
294+
(
295+
"([rR]|[uUbB][rR]|[rR][uUbB])(''')",
147296
bygroups(String.Affix, String.Single),
148-
"triple_single_quotes"),
149-
('([rR]|[uUbB][rR]|[rR][uUbB])(")',
297+
"triple_single_quotes",
298+
),
299+
(
300+
'([rR]|[uUbB][rR]|[rR][uUbB])(")',
150301
bygroups(String.Affix, String.Double),
151-
"double_quotes"),
152-
("([rR]|[uUbB][rR]|[rR][uUbB])(')",
302+
"double_quotes",
303+
),
304+
(
305+
"([rR]|[uUbB][rR]|[rR][uUbB])(')",
153306
bygroups(String.Affix, String.Single),
154-
"single_quotes"),
155-
('([uUbB]?)(""")',
307+
"single_quotes",
308+
),
309+
(
310+
'([uUbB]?)(""")',
156311
bygroups(String.Affix, String.Double),
157-
combined("stringescape", "triple_double_quotes")),
158-
("([uUbB]?)(''')",
312+
combined("stringescape", "triple_double_quotes"),
313+
),
314+
(
315+
"([uUbB]?)(''')",
159316
bygroups(String.Affix, String.Single),
160-
combined("stringescape", "triple_single_quotes")),
161-
('([uUbB]?)(")',
317+
combined("stringescape", "triple_single_quotes"),
318+
),
319+
(
320+
'([uUbB]?)(")',
162321
bygroups(String.Affix, String.Double),
163-
combined("stringescape", "double_quotes")),
164-
("([uUbB]?)(')",
322+
combined("stringescape", "double_quotes"),
323+
),
324+
(
325+
"([uUbB]?)(')",
165326
bygroups(String.Affix, String.Single),
166-
combined("stringescape", "single_quotes")),
167-
327+
combined("stringescape", "single_quotes"),
328+
),
168329
include("operator"),
169330
include("keywords"),
170331
(r"(func)(\s+)", bygroups(Keyword, Whitespace), "funcname"),
171-
(r'\b([a-zA-Z_][a-zA-Z0-9_]*)\s*(?=\()', Name.Function),
172-
332+
(r"\b([a-zA-Z_][a-zA-Z0-9_]*)\s*(?=\()", Name.Function),
173333
# NOTE:
174334
# This matches all PascalCase as a class. If this raises issues
175335
# please report it.
176336
# see: https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_styleguide.html#naming-conventions
177-
(r'\s*([A-Z][a-zA-Z0-9_]*)', Name.Class),
178-
337+
(r"\s*([A-Z][a-zA-Z0-9_]*)", Name.Class),
179338
include("name"),
180339
include("numbers"),
181340
],

0 commit comments

Comments
 (0)