-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmcfunction.tmLanguage.yaml
462 lines (437 loc) · 13.5 KB
/
mcfunction.tmLanguage.yaml
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
name: Syntax Mcfunction
scopeName: source.mcfunction
uuid: 8918dadd-8ebe-42d9-b1e9-0489ab228d9d
fileTypes:
- mcfunction
- bolt
patterns:
- include: "#root"
repository:
root:
patterns:
- include: "#literals"
- include: "#comments"
- include: "#say"
- include: "#names" # we do names before inline since inline comments can eat
- include: "#comments_inline"
- include: "#subcommands"
- include: "#property"
- include: "#operators" # ideally not so low but this eats into fakeplayers
- include: "#selectors"
# Comments have two styles
# 1. Basic `# comment`, single line
# 2. `#>`, etc. block comments
#
# We provide a subset of command highlighting within comments to enable
# docstring-esque type highlighting
comments:
patterns:
- applyEndPatternLast: 1
begin: ^\s*(#[>!#])(.+)$
beginCaptures:
"1":
name: comment.block.mcfunction
"2":
name: markup.bold.mcfunction
captures:
"0":
name: comment.block.mcfunction
end: ^(?!#)
name: meta.comments
patterns:
- include: "#comments_block"
- captures:
"0":
name: comment.line.mcfunction
match: '^\s*#.*$'
name: meta.comments
# `execute if entity @a run tellraw "hello" # cool command here`
# ^^^^^^^^^^^^^^^^^^^
comments_inline:
patterns:
- captures:
"0":
name: comment.line.mcfunction
match: "#.*$"
name: meta.comments
comments_block:
patterns:
- applyEndPatternLast: 1
begin: ^\s*#[>!]
captures:
"0":
name: comment.block.mcfunction
end: $
name: meta.comments_block
patterns:
- include: "#comments_block_emphasized"
- applyEndPatternLast: 1
begin: ^\s*#
captures:
"0":
name: comment.block.mcfunction
end: $
name: meta.comments_block
patterns:
- include: "#comments_block_normal"
# Header comments (just bolded)
# `#> This function does cool things`
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
comments_block_emphasized:
patterns:
- include: "#comments_block_special"
- captures:
"0":
name: markup.bold.mcfunction
match: \S+
name: meta.comments_block_emphasized
#> Normal comments within a comment block
comments_block_normal:
patterns:
- include: "#comments_block_special"
- captures:
"0":
name: comment.block.mcfunction
match: \S+
name: meta.comments_block_normal
- include: "#whitespace"
# Special highlighting for resource locations and params
# `# Taco Bell @rx97`
# ^^^^^
# `# Caching handled by storage:location/over/here`
# ^^^^^^^^^^^^^^^^^^^^^^^^^^
# `# $mypack.raycast.result return`
# ^^^^^^^^^^^^^^^^^^^^^^
comments_block_special:
patterns:
- captures:
"0":
name: markup.heading.mcfunction
match: '@\S+'
name: meta.comments_block_special
- include: "#resource-name"
- captures:
"0":
name: variable.other.mcfunction
match: "[#%$][A-Za-z0-9_.#%$]+"
name: meta.comments_block_special
# Literals encompasses numbers, booleans, UUIDs, and strings
literals:
patterns:
- captures:
"0":
name: constant.numeric.boolean.mcfunction
match: \b(true|false|True|False)\b
name: meta.literals
- captures:
"0":
name: variable.uuid.mcfunction
match: \b[0-9a-fA-F]+(?:-[0-9a-fA-F]+){4}\b
name: meta.names
- captures:
"0":
name: constant.numeric.float.mcfunction
match: '[+-]?\d*\.?\d+([eE]?[+-]?\d+)?[df]?\b'
name: meta.literals
- captures:
"0":
name: constant.numeric.integer.mcfunction
match: '[+-]?\d+(b|B|L|l|s|S)?\b'
name: meta.literals
# yea this should be operator, but i need this to exist before #names
# otherwise `..0.5` will be a valid name
- captures:
"0":
name: variable.other.mcfunction
match: \.\.
name: meta.ellipse.literals
# Strings will encompass multiple lines meaning an unclosed quote will
# eat extra tokens.
- applyEndPatternLast: 1
begin: '"'
beginCaptures:
"0":
name: punctuation.definition.string.begin.mcfunction
end: '"'
endCaptures:
"0":
name: punctuation.definition.string.end.mcfunction
name: string.quoted.double.mcfunction
patterns:
- include: "#literals_string-double"
- applyEndPatternLast: 1
begin: "'"
beginCaptures:
"0":
name: punctuation.definition.string.begin.mcfunction
end: "'"
endCaptures:
"0":
name: punctuation.definition.string.begin.mcfunction
name: string.quoted.single.mcfunction
patterns:
- include: "#literals_string-single"
# Simplistic highlighting for basic subcommands.
subcommands:
patterns:
- captures:
"0":
name: entity.name.class.mcfunction
match: "[a-z_]+" # "[A-Za-z_]+"
name: meta.literals
# Strings also have to account for `\`s esp, solo at the end of a line
literals_string-double:
patterns:
- captures:
"0":
name: constant.character.escape.mcfunction
match: \\.
name: meta.literals_string-double
- captures:
"0":
name: constant.character.escape.mcfunction
match: \\
name: meta.literals_string-double
- include: "#macro-name"
- captures:
"0":
name: string.quoted.double.mcfunction
match: '[^\\"]'
name: meta.literals_string-double
literals_string-single:
patterns:
- captures:
"0":
name: constant.character.escape.mcfunction
match: \\.
name: meta.literals_string-single
- captures:
"0":
name: constant.character.escape.mcfunction
match: \\
name: meta.literals_string-double
- include: "#macro-name"
- captures:
"0":
name: string.quoted.single.mcfunction
match: '[^\\'']'
name: meta.literals_string-single
# We need to hardcode `say` to avoid greedy `'`s to break formatting
# ex: `say Bob's uncle was pretty cool`, this would break commands that follow
say:
patterns:
- begin: ^(\s*)(say)
beginCaptures:
"1":
name: whitespace.mcfunction
"2":
name: keyword.control.flow.mcfunction
end: \n
name: meta.say.mcfunction
patterns:
- captures:
"0":
name: constant.character.escape.mcfunction
match: \\\s*\n
meta: meta.say.backslash.mcfunction
- include: "#literals_string-double"
- include: "#literals_string-single"
- begin: (run)(\s+)(say)
beginCaptures:
"1":
name: entity.name.mcfunction
"2":
name: whitespace.mcfunction
"3":
name: keyword.control.flow.mcfunction
end: \n
name: meta.say.mcfunction
patterns:
- captures:
"0":
name: constant.character.escape.mcfunction
match: \\\s*\n
meta: meta.say.backslash.mcfunction
- include: "#literals_string-double"
- include: "#literals_string-single"
# Names are a very generic term in this grammar. They specially highlight the
# beginning of a line (and a word after `run`), handle macro commands, and
# fakeplayers.
names:
patterns:
- captures:
"1":
name: whitespace.mcfunction
"2":
name: keyword.control.flow.mcfunction
match: ^(\s*)([a-z_]+)(?=\s)
name: meta.names
- captures:
"1":
name: whitespace.mcfunction
"2":
name: markup.italic.mcfunction
"3":
name: whitespace.mcfunction
"4":
name: keyword.control.flow.mcfunction
match: ^(\s*)(\$)( ?)([a-z_]*)
name: meta.names
- captures:
"1":
name: entity.name.mcfunction
"2":
name: whitespace.mcfunction
"3":
name: keyword.control.flow.mcfunction
match: (run)(\s+)([a-z_]+)
name: meta.names
- include: "#resource-name"
- captures:
"0":
name: entity.name.mcfunction
match: '[A-Za-z]+(?=\W)'
name: meta.names
- captures:
"0":
name: string.unquoted.mcfunction
match: "[A-Za-z_][A-Za-z0-9_.#%$]*"
name: meta.names
- include: "#macro-name"
- captures:
"0":
name: variable.other.mcfunction
match: '([#%$]|((?<=\s)\.))[A-Za-z0-9_.#%$\-]+'
name: meta.names
# These are for macro-names defined within a macro-line (including strings).
# TODO: only activate this if the beginning of the line starts with `$`
macro-name:
patterns:
- captures:
"1":
name: punctuation.definition.template-expression.begin.mcfunction
"2":
name: variable.other.mcfunction
"3":
name: punctuation.definition.template-expression.end.mcfunction
match: '(\$\()([A-Za-z0-9_]*)(\))'
name: meta.macro-name
# General operators (including beyond mcfunction)
operators:
patterns:
- captures:
"0":
name: constant.numeric.mcfunction
match: "[~^]"
name: meta.operators
- captures:
"0":
name: keyword.operator.mcfunction
match: '[\-%?!+*<>\\/|&=.:,;]'
name: meta.operators
# Properties are a subset of definitions that exist within `{}`, `[]`, or `()`s. They are a
# generic formula for highlighting key-value pairs, but are also capable of doing a good job
# for generic scoping (such as in mcbuild), JSON, or even python/js esque expressions. They
# can be nested as many times as needed as long as the brackets match!
#
# Unfortuntely, there's a bit of limitations based on how strict it is with mcfunction
# vs how accepting it is of foreign syntax. For example `[key:val]` and `[key: val]`
# highlight very differently as either a resource-name or a key/value.
#
# In the future, we could attempt a stricter property key-value scheme and then fall-back
# to a generic, more forgiving highlighting if the strict one fails. This would be complex
# though maybe needing some lookaheads, etc which could be not worth.
property:
patterns:
- applyEndPatternLast: 1
begin: \{
captures:
"0":
name: punctuation.mcfunction
end: \}
name: meta.property.curly
patterns:
- include: "#resource-name"
- include: "#literals"
- include: "#property_key"
- include: "#operators"
- include: "#property_value"
- include: $self
- applyEndPatternLast: 1
begin: \[
captures:
"0":
name: variable.other.mcfunction
end: \]
name: meta.property.square
patterns:
- include: "#resource-name"
- include: "#literals"
- include: "#property_key"
- include: "#operators"
- include: "#property_value"
- include: $self
- applyEndPatternLast: 1
begin: \(
captures:
"0":
name: punctuation.mcfunction
end: \)
name: meta.property.paren
patterns:
- include: "#resource-name"
- include: "#literals"
- include: "#property_key"
- include: "#operators"
- include: "#property_value"
- include: $self
property_key:
patterns:
- captures:
"0":
name: variable.other.mcfunction
match: '#?[a-z_][a-z_\.\-]*\:[a-z0-9_\.\-/]+(?=\s*\=:)'
name: meta.property_key
- captures:
"0":
name: variable.other.mcfunction
match: '#?[a-z_][a-z0-9_\.\-/]+'
name: meta.property_key
- captures:
"0":
name: variable.other.mcfunction
match: '[A-Za-z_]+[A-Za-z_\-\+]*'
name: meta.property_key
property_value:
patterns:
- captures:
"0":
name: string.unquoted.mcfunction
match: '#?[a-z_][a-z_\.\-]*\:[a-z0-9_\.\-/]+'
name: meta.property_value
- captures:
"0":
name: string.unquoted.mcfunction
match: '#?[a-z_][a-z0-9_\.\-/]+'
name: meta.property_value
resource-name:
patterns:
- captures:
"0":
name: entity.name.function.mcfunction
match: "#?[a-z_][a-z0-9_.-]*:[a-z0-9_./-]+"
name: meta.resource-name
- captures:
"0":
name: entity.name.function.mcfunction
match: '#?[a-z0-9_\.\-]+\/[a-z0-9_\.\-\/]+'
name: meta.resource-name
# Selectors consume more than 1 char after an `@` symbol to allow for fancier
# `@param` style highlighting like python decorators or even modded selectors.
selectors:
patterns:
- captures:
"0":
name: support.class.mcfunction
match: "@[a-z]+"
name: meta.selectors