-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathJust.sublime-syntax
More file actions
677 lines (576 loc) · 17.6 KB
/
Just.sublime-syntax
File metadata and controls
677 lines (576 loc) · 17.6 KB
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
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
%YAML 1.2
---
# Syntax for the just command runner
#
# Based on the just.sublime-syntax file by @TonioGela
# Largely rewritten in 2022 by @nk9 using examples by @deathaxe
# https://www.sublimetext.com/docs/syntax.html
name: Just
scope: source.just
version: 2
hidden: false
file_extensions:
- .justfile
- just
- justfile
variables:
valid_name: '[a-zA-Z_][a-zA-Z0-9_-]*'
built_in_functions: |-
(?x:
absolute_path
| append
| arch
| blake3
| blake3_file
| cache_dir
| cache_directory
| canonicalize
| capitalize
| choose
| clean
| config_dir
| config_directory
| config_local_dir
| config_local_directory
| data_dir
| data_directory
| data_local_dir
| data_local_directory
| datetime
| datetime_utc
| encode_uri_component
| env
| env_var
| env_var_or_default
| error
| executable_dir
| executable_directory
| extension
| file_name
| file_stem
| home_dir
| home_directory
| invocation_dir
| invocation_dir_native
| invocation_directory
| invocation_directory_native
| is_dependency
| join
| just_executable
| just_pid
| justfile
| justfile_dir
| justfile_directory
| kebabcase
| lowercamelcase
| lowercase
| module_dir
| module_directory
| module_file
| num_cpus
| os
| os_family
| parent_dir
| parent_directory
| path_exists
| prepend
| quote
| read
| replace
| replace_regex
| require
| semver_matches
| sha256
| sha256_file
| shell
| shoutykebabcase
| shoutysnakecase
| snakecase
| source_dir
| source_directory
| source_file
| style
| titlecase
| trim
| trim_end
| trim_end_match
| trim_end_matches
| trim_start
| trim_start_match
| trim_start_matches
| uppercamelcase
| uppercase
| uuid
| which
| without_extension
)
boolean_settings: |-
(?x: allow-duplicate-recipes | dotenv-load | export | fallback | ignore-comments
| positional-arguments | windows-powershell )
string_settings: |-
(?x: tempdir )
shell_settings: |-
(?x: shell | windows-shell )
recipe_attributes: |-
(?x: linux | macos | no-cd | no-exit-message | private | unix | windows )
###############################################################################
# MAIN CONTEXT
###############################################################################
contexts:
main:
- include: includes
- include: settings
- include: aliases
- include: comments
- include: assignment
- include: recipe-attribute
- include: recipe-definition
- include: recipe-generic-line
prototype:
- include: comments
###[ COMMENTS ]################################################################
comments:
- match: '#[^!]'
scope: punctuation.definition.comment.begin.just
push: comment-line
comment-line:
- meta_include_prototype: false
- meta_scope: comment.line.number-sign.just
- include: line-end
###[ IMPORTS ]#################################################################
includes:
- match: ^(!include) (.*)$
scope: meta.statement.import.just
captures:
1: keyword.control.import.just
2: meta.generic-name.just
###[ ALIASES ]#################################################################
aliases:
- match: ^(alias)\s+({{valid_name}})\s*(:=)\s+({{valid_name}})(?=.*$)
captures:
1: support.function.export.just
2: variable.other.just
3: keyword.operator.assignment.just
4: variable.function.just
###[ STATEMENTS ]##############################################################
just-expressions:
- include: groups
- include: operators
- include: function-calls
- include: if-statements
- include: strings
- include: operands-variables
###[ FUNCTION CALL ]###########################################################
function-calls:
- match: '{{built_in_functions}}\s*(?=\()'
scope:
meta.function-call.identifier.just
support.function.builtin.just
push: function-call-arguments
function-call-arguments:
- meta_include_prototype: false
- match: \(
scope: punctuation.section.group.begin.just
set: function-call-arguments-body
function-call-arguments-body:
- meta_scope: meta.function-call.arguments.just
- include: group-end
- include: just-expressions
- match: ({{valid_name}})\s*
captures:
1: variable.parameter.just
###[ GROUPS ]##################################################################
groups:
- match: \(
scope: punctuation.section.group.begin.just
push: group-body
group-end:
- match: \)
scope: punctuation.section.group.end.just
pop: 1
group-body:
- meta_scope: meta.group.just
- include: group-end
- include: just-expressions
###[ IF STATEMENT ]############################################################
if-statements:
- match: if\b
scope: keyword.control.conditional.if.just
push: if-statement-condition-body
- match: else\b
scope: keyword.control.conditional.else.just
push: else-statement-block
if-statement-condition-body:
- meta_scope: meta.statement.conditional.if.just
- match: \{
scope: punctuation.section.block.begin.just
push: if-else-block-body
- match: '!=|==|=~'
scope: keyword.operator.comparison.just
- include: just-expressions
- include: else-pop
else-statement-block:
- meta_scope: meta.statement.conditional.else.just
- match: \{
scope: punctuation.section.block.begin.just
push: if-else-block-body
- include: else-pop
if-else-block-body:
- meta_scope: meta.block.just
- match: \}
scope: punctuation.section.block.end.just
pop: 2
- include: just-expressions
###[ OPERATORS ]###############################################################
operators:
- include: punctuation-separators
- match: (\+|\/)
scope: keyword.operator.arithmetic.just
punctuation-separators:
- match: ','
scope: punctuation.separator.sequence.just
###[ CHARACTERS ]##############################################################
strings:
- include: single-quote-block-strings
- include: single-quote-strings
- include: double-quote-block-strings
- include: double-quote-strings
- include: backtick-quote-block-strings
- include: backtick-quote-strings
backtick-quote-block-strings:
- match: '```'
scope: punctuation.section.interpolation.begin.just
push:
- meta_scope: meta.string.shell meta.interpolation.command.shell
- meta_include_prototype: false
- match: '```'
scope: punctuation.section.interpolation.end.just
pop: 1
backtick-quote-strings:
- match: '`'
scope: punctuation.section.interpolation.begin.just
push:
- meta_scope: meta.string.shell meta.interpolation.command.shell
- meta_include_prototype: false
- match: '`'
scope: punctuation.section.interpolation.end.just
pop: 1
double-quote-block-strings:
- match: '"""'
scope: punctuation.definition.string.begin.just
push:
- meta_scope: string.quoted.double.block.just
- meta_include_prototype: false
- match: \\.
scope: constant.character.escape.just
- match: '"""'
scope: punctuation.definition.string.end.just
pop: 1
double-quote-strings:
- match: '"'
scope: punctuation.definition.string.begin.just
push:
- meta_scope: string.quoted.double.just
- meta_include_prototype: false
- match: \\.
scope: constant.character.escape.just
- match: '"'
scope: punctuation.definition.string.end.just
pop: 1
single-quote-block-strings:
- match: "'''"
scope: punctuation.definition.string.begin.just
push:
- meta_scope: string.quoted.single.block.just
- meta_include_prototype: false
- match: "'''"
scope: punctuation.definition.string.end.just
pop: 1
single-quote-strings:
- match: "'"
scope: punctuation.definition.string.begin.just
push:
- meta_scope: string.quoted.single.just
- meta_include_prototype: false
- match: "'"
scope: punctuation.definition.string.end.just
pop: 1
###[ VARIABLES ]###############################################################
operands-variables:
# First check for an invalid function
- match: \b({{valid_name}})\b\s*(\()
captures:
1: source.just
2: invalid.illegal.just
- match: \b(?:{{valid_name}})\b
scope: variable.other.just
###[ VARIABLE ASSIGNMENT ]#####################################################
assignment:
- match: (export)?\s*({{valid_name}})\s*(?=:=)
captures:
1: keyword.declaration.variable.just
2: variable.other.just
push: assignment-value
assignment-value:
- meta_include_prototype: false
- match: :=
scope: keyword.operator.assignment.just
set: assignment-value-body
assignment-value-body:
- include: eol-pop
- include: just-expressions
###[ RECIPE DEFINITION ]#######################################################
# Recipe definition lines, including attributes, arguments and dependencies
recipe-attribute:
- match: ^\[\s*({{recipe_attributes}})\s*\]\s*$ # Only one attribute allowed per line
scope: meta.annotation.just variable.annotation.just
recipe-definition:
- match: (?=^@?{{valid_name}}(?![^:]*:=)) # Matches '^recipeName' but not '^varName :='
push:
- recipe-body
- recipe-name
- recipe-modifier
recipe-modifier:
- match: ^@
scope: meta.function.just storage.modifier.quiet.just
- include: else-pop
recipe-name:
- match: \b{{valid_name}}
scope: meta.function.just entity.name.function.just
pop: 1 # Only match the first instance
push:
- recipe-dependencies
- recipe-assignment
- recipe-parameter
- include: else-pop
recipe-assignment:
- match: ':'
scope: keyword.operator.assignment.just
- include: eol-pop
- include: else-pop
recipe-parameter:
- meta_content_scope: meta.function.parameters.just
- match: (?=[\+\*$a-zA-Z_])
push:
- recipe-parameter-assignment
- recipe-parameter-name
- recipe-export-operator
- recipe-variadic-operator
- include: else-pop
recipe-variadic-operator:
- match: '[\+\*](?!\s*:)'
scope: keyword.operator.variadic.just
pop: 1 # Only one allowed
- include: else-pop
recipe-export-operator:
- match: \$(?=\s*{{valid_name}})
scope: keyword.operator.exported.just
- match: '[\+\*\$]'
scope: invalid.illegal.just
- include: else-pop
recipe-parameter-assignment:
- match: =
scope: keyword.operator.assignment.just
push:
- include: just-expressions
- match: (\s+|(?=:))
pop: 1
- include: else-pop
recipe-parameter-name:
- match: \b{{valid_name}}\b
scope: variable.parameter.just
- include: else-pop
recipe-dependencies:
- match: (?=\()
push: recipe-dependency-with-args
- match: \b{{valid_name}}\b
scope: variable.function.just
- match: '&&'
scope: keyword.operator.logical.just
- include: eol-pop
- include: else-pop
recipe-dependency-with-args:
- match: \(
scope: punctuation.section.group.begin.just
push: recipe-dependency-with-args-body
recipe-dependency-with-args-body:
- meta_scope: meta.group.just
- match: \b{{valid_name}}
scope: variable.function.just
push:
- include: just-expressions
- include: else-pop
- include: recipe-dependency-group-end
recipe-dependency-group-end:
- match: \)
scope: punctuation.section.group.end.just
pop: 2 # End dependency group
recipe-body:
# Python script shebang
- match: ^\s+(?=#!.*\bpython(?:\d(?:\.\d+)?)?\b)
pop: 1
embed: scope:source.python.embedded.just
escape: ^(?=\S)
# Shell script shebang
- match: ^\s+(?=#!.*\b(bash|zsh|sh)\b)
pop: 1
embed: scope:source.shell.embedded.just
escape: ^(?=\S)
- match: ^
comment: Content using the default shell
pop: 1
###[ RECIPE CONTENTS ]#########################################################
recipe-generic-line:
- match: ^(?=\s+\S)
push:
- recipe-generic-content
- recipe-content-modifiers
recipe-generic-content:
- include: recipe-content-interpolations
- include: recipe-content-strings
- match: (\\)$\n?
captures:
1: punctuation.separator.continuation.line.just
- match: $\n
comment: |
No trailing '?', so this will NOT match lines matched by the previous rule.
There is no pop there, so this context will remain on the stack WITHOUT the
recipe-content-modifiers. This ensures those modifiers are matched
IFF they occur at the beginning of non-continuation lines.
pop: 1
recipe-content-modifiers:
- match: ^\s+((@)|(-)(@)|(-)|(@)(-))(?!-)
captures:
2: storage.modifier.quiet.just
3: storage.modifier.ignore-error.just
4: storage.modifier.quiet.just
5: storage.modifier.ignore-error.just
6: storage.modifier.quiet.just
7: storage.modifier.ignore-error.just
- include: else-pop
recipe-content-interpolations:
- match: \{\{\{\{
comment: Escaped double brace. Do nothing
- match: \{\{(?!\{)
scope: punctuation.section.interpolation.begin.just
push: recipe-content-interpolation-body
recipe-content-interpolation-body:
- meta_scope: meta.interpolation.just
- match: \}\}
scope: punctuation.section.interpolation.end.just
pop: 1
- include: just-expressions
# Sadly, almost an exact duplicate of the 'strings' context, but
# needed to include interpolations, which would have to be nested
# inside a push: in the other context.
recipe-content-strings:
- match: '"'
scope: punctuation.definition.string.begin.just
push:
- meta_scope: meta.string.just string.quoted.double.just
- meta_include_prototype: false
- match: \\.
scope: constant.character.escape.just
- match: '"'
scope: punctuation.definition.string.end.just
pop: 1
- include: recipe-content-string-interpolations
- match: "'"
scope: punctuation.definition.string.begin.just
push:
- meta_scope: meta.string.just string.quoted.single.just
- meta_include_prototype: false
- match: "'"
scope: punctuation.definition.string.end.just
pop: 1
- include: recipe-content-string-interpolations
recipe-content-string-interpolations:
- match: \{\{\{\{
comment: Escaped double brace. Do nothing
- match: \{\{(?!\{)
scope: punctuation.section.interpolation.begin.just
push: recipe-content-string-interpolation-body
recipe-content-string-interpolation-body:
- clear_scopes: 1
- meta_scope: meta.interpolation.just
- include: recipe-content-interpolation-body
###[ Set Expressions ]#########################################################
# Ex: "set shell := ['zsh', '-cu']", "set dotenv-load", "set export := false"
settings:
- match: ^set(?=\s)
scope: storage.modifier.definition.just
push: settings-name
settings-name:
- include: settings-boolean-name
- include: settings-shell-name
- include: settings-string-name
- include: settings-invalid-name
- include: else-pop
settings-boolean-name:
- match: '{{boolean_settings}}\b'
scope: entity.name.definition.just
set:
- settings-boolean-value
- assignment-operator
settings-boolean-value:
- match: (?:true|false)\b
scope: constant.language.boolean.just
pop: 1
- include: else-pop
- include: eol-pop
settings-invalid-name:
- match: ({{valid_name}})\b\s*:=
captures:
1: invalid.illegal.just
push: eol-pop
settings-shell-name:
- match: '{{shell_settings}}\b'
scope: entity.name.definition.just
set:
- settings-shell-value
- assignment-operator
settings-shell-value:
- match: \[
scope: punctuation.section.brackets.start.just
set: string-array-body
- include: else-pop
- include: eol-pop
string-array-body:
- meta_scope: meta.sequence.list.just
- match: \]
scope: punctuation.section.brackets.end.just
pop: 1
- match: ','
scope: punctuation.separator.parameters.just
- include: strings
- include: eol-pop #??
settings-string-name:
- match: '{{string_settings}}\b'
scope: entity.name.definition.just
set:
- settings-string-value
- assignment-operator
settings-string-value:
- include: strings
- include: eol-pop
# ###[ General Types ]##########################################################
variable-name:
- match: \b{{valid_name}}\b
scope: variable.other.just
- include: else-pop
assignment-operator:
- match: :=
scope: keyword.operator.assignment.just
- include: else-pop
###[ Common Prototypes ]#######################################################
line-end:
- match: $
pop: 1
# Remove the current stack item when we're about to reach a new character
# Learn more: https://github.com/sublimehq/Packages/issues/757#issuecomment-287193733
else-pop:
- match: (?=\S)
pop: 1
eol-pop:
- match: $\n?
pop: 1