-
Notifications
You must be signed in to change notification settings - Fork 18
/
GDScript.sublime-syntax
310 lines (292 loc) · 10.8 KB
/
GDScript.sublime-syntax
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
%YAML 1.2
---
# http://www.sublimetext.com/docs/3/syntax.html
#
# Useful references for GDScript lexical analysis:
# - https://github.com/godotengine/godot-docs/blob/master/extensions/gdscript.py
# - https://github.com/godotengine/godot/blob/master/modules/gdscript/gdscript_tokenizer.cpp
name: GDScript (Godot Engine)
file_extensions:
- gd
scope: source.gdscript
variables:
# Godot doesn't allow single underscore as var name, for example, `var x = _`
# and `func f(_)` are illegal. `func _()` and `_()`, however, are legal so this
# inconsistency might be a Godot bug.
identifier: \b[a-zA-Z_][a-zA-Z_0-9]*\b
contexts:
prototype:
- include: comments
- include: line-continuation
main:
- include: docstrings
- include: expressions
- include: assignments
docstrings:
- match: ^\s*(""")
captures:
1: punctuation.definition.comment.begin.gdscript
push:
- meta_scope: comment.block.documentation.gdscript
- meta_include_prototype: false
- include: character-escapes
- match: \"""
scope: punctuation.definition.comment.end.gdscript
pop: true
literals:
- include: strings
- match: '@"'
push:
# Should probably be combined with the strings context
- meta_scope: string.quoted.double.node-path.gdscript
- match: (?<!\\)"
pop: true
- match: \b(?i:0x\h*)\b
scope: constant.numeric.integer.hexadecimal.gdscript
- match: '\b(?i:(\d+\.\d*(e[\-\+]?\d+)?))\b'
scope: constant.numeric.float.gdscript
- match: '\b(?i:(\.\d+(e[\-\+]?\d+)?))\b'
scope: constant.numeric.float.gdscript
- match: '\b(?i:(\d+e[\-\+]?\d+))\b'
scope: constant.numeric.float.gdscript
- match: \b\d+\b
scope: constant.numeric.integer.gdscript
expressions:
- include: literals
- include: builtin-types
- include: dictionaries
- match: \b(?i:elif|else|for|if|while|break|continue|pass|return|match)\b
scope: keyword.control.flow.gdscript
- match: \b(?i:&&|and|in|is|!|not|\|\||or)\b
scope: keyword.operator.logical.gdscript
- match: <=|>=|==|<|>|!=
scope: keyword.operator.comparison.gdscript
- match: \+=|-=|\*=|/=|%=|&=|\|=|\*|/|%|\+|-|<<|>>|&|\||\^|~
scope: keyword.operator.arithmetic.gdscript
- include: yields
- include: function-calls
assignments:
- match: "="
scope: keyword.operator.assignment.gdscript
- match: '^\s*(?i:(class))\s+({{identifier}})\s*'
captures:
1: storage.type.class.gdscript
2: entity.name.type.class.gdscript
- include: functions
- include: signals
- match: '(?i:\b(?:(onready)\s+)?(var))\s+({{identifier}})'
captures:
1: keyword.other.onready.gdscript
2: storage.type.var.gdscript
3: variable.other.gdscript
- match: '\b(?i:(const))\s+({{identifier}})'
captures:
1: storage.type.const.gdscript
2: variable.other.gdscript
- match: '\b(?i:(enum))\s+({{identifier}})?'
captures:
1: storage.type.enum.gdscript
2: entity.name.type.gdscript
- match: \b(?i:extends|assert|breakpoint)\b
scope: keyword.other.gdscript
- match: '(?<=extends)\s+{{identifier}}(\.({{identifier}}))?'
scope: entity.other.inherited-class.gdscript
- match: \b(?i:true|false|null)\b
scope: constant.language.gdscript
- match: \b(?i:export|tool)\b
scope: storage.modifier.static.gdscript
- match: \b(setget)\b\s*({{identifier}})?\s*(,)?\s*({{identifier}})?
captures:
1: keyword.operator.setget.gdscript
2: variable.function.setter.gdscript
3: punctuation.separator.parameters.gdscript
4: variable.function.getter.gdscript
comments:
- match: (#).*
scope: comment.line.number-sign.gdscript
captures:
1: punctuation.definition.comment.number-sign.gdscript
strings:
- match: \"""
scope: punctuation.definition.string.begin.gdscript
push:
- meta_scope: meta.string.gdscript string.quoted.double.block.gdscript
- meta_include_prototype: false
- include: character-escapes
- match: \"""
scope: punctuation.definition.string.end.gdscript
pop: true
# GDScript has double-quoted multiline strings but not single-quoted
- match: \"
scope: punctuation.definition.string.begin.gdscript
push:
- meta_scope: meta.string.gdscript string.quoted.double.gdscript
- meta_include_prototype: false
- include: character-escapes
- match: \"
scope: punctuation.definition.string.end.gdscript
pop: true
- match: \'
scope: punctuation.definition.string.begin.gdscript
push:
- meta_scope: meta.string.gdscript string.quoted.single.gdscript
- meta_include_prototype: false
- include: character-escapes
- match: \'
scope: punctuation.definition.string.end.gdscript
pop: true
character-escapes:
# Should add the rest of the character escapes here
- match: \\["'\\]
scope: constant.character.escape.gdscript
builtin-types:
# It's debateable whether these "built-in types" should be categorized as ``storage`` or
# ``support``. I chose storage because the default color scheme differentiates it from
# support and that's useful because things descended from Object get instantiated by
# calling ``new()``, but these don't
#
# https://docs.godotengine.org/en/3.1/getting_started/scripting/gdscript/gdscript_basics.html#built-in-types
- match: \b(?:bool|int|float|String|funcref)\b
scope: storage.type.basic.gdscript
- match: '\b(?:Vector[23]|Rect2|Matrix32?|Plane|Quat|AABB|Transform)\b'
scope: storage.type.vector.gdscript
- match: \b(?:Color|Image|NodePath|RID|Object|InputEvent)\b
scope: storage.type.engine.gdscript
- match: '\b(Array|Dictionary|ByteArray|IntArray|FloatArray|StringArray|Vector[23]Array|ColorArray)\b'
scope: storage.type.container.gdscript
functions:
- match: ^\s*(?:(static|remote|sync|master|slave)\s+)?(func)\b
captures:
1: storage.modifier.gdscript
2: storage.type.function.gdscript
push:
- meta_scope: meta.function.gdscript
- match: '{{identifier}}'
scope: entity.name.function.gdscript
- match: (?=\()
set:
- meta_scope: meta.function.parameters.gdscript
- match: \(
scope: punctuation.section.parameters.begin.gdscript
- match: '{{identifier}}'
scope: variable.parameter.gdscript
- match: ','
scope: punctuation.separator.parameters.gdscript
- match: \)
scope: punctuation.section.parameters.end.gdscript
set:
- meta_scope: meta.function.gdscript
- include: start-func-body
- match: ->
scope: keyword.operator.arrow.forward.gdscript
set:
- meta_scope: meta.function.return-type
- include: start-func-body
- include: builtin-types
- match: \bvoid\b
scope: storage.type.basic.gdscript
- match: '{{identifier}}'
scope: support.class.gdscript
start-func-body:
- match: ':'
scope: punctuation.section.function.begin.gdscript
pop: true
signals:
- match: ^\s*signal\b
scope: storage.type.signal.gdscript
push:
- meta_scope: meta.signal.gdscript
- match: '{{identifier}}'
scope: entity.name.signal.gdscript
- match: $
pop: true
- match: (?=\()
set:
- meta_scope: meta.signal.parameters.gdscript
- match: \(
scope: punctuation.section.parameters.begin.gdscript
- match: '{{identifier}}'
scope: variable.parameter.gdscript
- match: ','
scope: punctuation.separator.parameters.gdscript
- match: \)
scope: punctuation.section.parameters.end.gdscript
pop: true
dictionaries:
- match: '{'
scope: punctuation.section.mapping.begin.gdscript
set: dictionary-keys
dictionary-keys:
# Scope meta.mapping.gdscript appears twice immediately before delimiter, why?
- meta_scope: meta.mapping.gdscript
- include: dictionary-close-pop
- match: '[:=]'
scope: punctuation.separator.mapping.key-value.gdscript
set: dictionary-values # prevent infinite loop
- match: ',' # enum key without an explicit value
scope: punctuation.separator.mapping.key-value.gdscript
- match: (?=\S)
set:
- meta_scope: meta.mapping.key.gdscript
- match: '{{identifier}}(?=\s*=)'
set: dictionary-keys
- match: '{{identifier}}(?=\s*[,}\n])'
# Would be better not to nest enum matching under dictionary since this
# won't correctly scope `enum {X=1}`, for example.
scope: entity.name.enum.gdscript
set: dictionary-keys
- match: (?=\s*[:=])
set: dictionary-keys
- include: expressions
dictionary-values:
- meta_scope: meta.mapping.gdscript
- include: dictionary-close-pop
- match: ','
scope: punctuation.separator.mapping.gdscript
set: dictionary-keys # prevent infinite loop
- match: (?=\S)
set:
- meta_scope: meta.mapping.value.gdscript
- include: dictionary-close-pop
- match: (?=\s*,)
set: dictionary-values
- include: expressions
dictionary-close-pop:
- match: '\s*(})'
captures:
1: punctuation.section.mapping.end.gdscript
pop: true
function-calls:
- match: '{{identifier}}\s*(?=\()'
scope: meta.function-call.gdscript variable.function.gdscript
- match: (?=\()
push:
- meta_scope: meta.function-call.arguments.gdscript
- include: arguments-list
yields:
- match: \byield\b
scope: keyword.control.flow.yield.gdscript
push:
- match: (?=\()
push:
# Not sure if there's an appropriate meta scope for yield args, so
# giving them none for now
- include: arguments-list
- match: ''
pop: true
arguments-list:
- match: \(
scope: punctuation.section.arguments.begin.gdscript
- include: expressions
- match: ','
scope: punctuation.separator.arguments.gdscript
- match: \)
scope: punctuation.section.arguments.end.gdscript
pop: true
line-continuation:
# From Sublime's built-in Python syntax, with slight modification
- match: (\\)(.*)$\n?
captures:
1: punctuation.separator.continuation.line.gdscript
2: invalid.illegal.unexpected-text.gdscript
# Python syntax has special handling for docstrings here