-
Notifications
You must be signed in to change notification settings - Fork 594
/
Copy pathMakefile.sublime-syntax
675 lines (629 loc) · 21.5 KB
/
Makefile.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
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
%YAML 1.2
# http://www.sublimetext.com/docs/3/syntax.html
# https://www.gnu.org/software/make/manual/make.html
--- #---------------------------------------------------------------------------
# Converted from Makefile Improved by Kay-Uwe (Kiwi) Lorenz
# Includes a few improvement like special-target, a bit more shell command,
# better variable recognition, fix ifeq/ifneq missing highlight ...
# Rewritten by Raoul Wols on May 2017.
#
# All number references refer to the "Make manual" (see link above).
name: Makefile
scope: source.makefile
version: 2
file_extensions:
- mk
- mak
- make
hidden_file_extensions:
- GNUmakefile
- Makefile
- Makefile.am
- Makefile.in
- OCamlMakefile
first_line_match: |-
(?xi:
^ \#! .* \bmake\b | # shebang
^ \s* \# .*? -\*- .*? \bmakefile\b .*? -\*- # editorconfig
)
#-------------------------------------------------------------------------------
variables:
varassign: (\?|\+|::?)?=
shellassign: '!='
startdirective: ifn?(def|eq)
include: '[s-]?include'
ruleassign: :(?!=)
function_call_token_begin: \$\$?\(
# The big "rule lookahead". What we want to do here is detect if the
# line that we are parsing is going to define a rule. So we need to check
# if we have something of the form <rule-name> : <rule-prerequisites>
# However matters become complicated by the fact that we can have arbitrary
# variable substitutions anywhere. We try to remedy this by hacking in a
# regex that matches up to four levels of nested parentheses, and ignores
# whatever's inside the parentheses.
nps0: '[^()=]*' # doesn't look like assignment
nps: '[^()]*'
open: '(?:\('
close: '\))?' # ignore this invalid.illegal
just_eat: | # WARNING: INSANITY FOLLOWS!
(?x) # ignore whitespace in this regex
{{nps0}} # level 0
{{open}} # start level 1 __
{{nps}} # level 1 _______ /*_>-<
{{open}} # start level 2 ___/ _____ \__/ /
{{nps}} # level 2 <____/ \____/
{{open}} # start level 3 is like snek... (by Valerie Haecky)
{{nps}} # level 3
{{open}} # start level 4
{{nps}} # level 4
{{close}} # end level 4
{{nps}} # level 3
{{close}} # end level 3
{{nps}} # level 2
{{open}} # start level 3
{{nps}} # level 3
{{open}} # start level 4
{{nps}} # level 4
{{close}} # end level 4
{{nps}} # level 3
{{close}} # end level 3
{{nps}} # level 2
{{close}} # end level 2
{{nps}} # level 1
{{open}} # start level 2
{{nps}} # level 2
{{open}} # start level 3
{{nps}} # level 3
{{open}} # start level 4
{{nps}} # level 4
{{close}} # end level 4
{{nps}} # level 3
{{close}} # end level 3
{{nps}} # level 2
{{open}} # start level 3
{{nps}} # level 3
{{open}} # start level 4
{{nps}} # level 4
{{close}} # end level 4
{{nps}} # level 3
{{close}} # end level 3
{{nps}} # level 2
{{open}} # start level 3
{{nps}} # level 3
{{open}} # start level 4
{{nps}} # level 4
{{close}} # end level 4
{{nps}} # level 3
{{close}} # end level 3
{{nps}} # level 2
{{close}} # end level 2
{{nps}} # level 1
{{close}} # end level 1
{{nps0}} # level 0
rule_lookahead: '{{just_eat}}{{ruleassign}}'
# Just as with rules we want to look ahead if we are going to define a var.
var_lookahead: '{{just_eat}}(?:{{varassign}}|{{shellassign}})'
#-------------------------------------------------------------------------------
contexts:
# 3.1 What Makefiles Contain
# Makefiles contain five kinds of things: explicit rules, implicit rules,
# variable definitions, directives, and comments.
main:
- include: comments
- match: (?={{rule_lookahead}})
push: expect-rule
- include: variable-definitions
- include: variable-substitutions
- include: control-flow
- include: line-continuation
- match: ^\s*(endef)
captures:
1: invalid.illegal.stray.endef.makefile
inside-control-flow:
- meta_scope: meta.group.makefile
- match: "'"
scope: punctuation.definition.string.begin.makefile
push:
- meta_scope: meta.string.makefile string.quoted.single.makefile
- match: "'"
scope: punctuation.definition.string.end.makefile
pop: 1
- include: escape-literals
- include: line-continuation
- include: variable-substitutions
- match: '"'
scope: punctuation.definition.string.begin.makefile
push:
- meta_scope: meta.string.makefile string.quoted.double.makefile
- match: '"'
scope: punctuation.definition.string.end.makefile
pop: 1
- include: escape-literals
- include: line-continuation
- include: variable-substitutions
- match: \(
scope: punctuation.section.group.begin.makefile
push:
- match: \)
scope: punctuation.section.group.end.makefile
pop: 1
- include: variable-substitutions
- match: \,
scope: punctuation.separator.makefile
- match: \)
scope: invalid.illegal.stray.paren.makefile
- include: continuation-or-pop-on-line-end
control-flow:
- match: ^\s*(vpath)\s
captures:
1: keyword.control.vpath.makefile
push:
- include: highlight-wildcard-sign
- match: \s
set:
- meta_content_scope: meta.string.makefile string.unquoted.makefile
- include: pop-on-line-end
- include: pop-on-line-end
- match: ^\s*(vpath)$
captures: keyword.control.vpath.makefile
- match: ^\s*({{include}})\s+
captures:
1: keyword.control.import.makefile
push:
- meta_content_scope: meta.string.makefile string.unquoted.makefile
- include: continuation-or-pop-on-line-end
- include: variable-substitutions
- include: comments
- match: \b{{startdirective}}\b
scope: keyword.control.conditional.makefile
push: inside-control-flow
- match: ^\s*(else)\b
captures:
1: keyword.control.conditional.makefile
push:
- include: control-flow
- include: comments
- include: pop-on-line-end
- match: ^\s*(endif)\b
captures:
1: keyword.control.conditional.makefile
push:
- include: comments
- include: pop-on-line-end
highlight-percentage-sign:
- match: \%
scope: variable.language.makefile
highlight-wildcard-sign:
- match: \*
scope: constant.other.wildcard.asterisk.makefile
expect-rule:
# Anything before the colon is part of the rule's name.
- meta_scope: meta.function.makefile entity.name.function.makefile
- include: line-continuation
- include: variable-substitutions
- include: highlight-percentage-sign
- match: (?= *::?[^=]+[!:?]?=)
set:
- match: ::?
scope: keyword.operator.assignment.makefile
set:
- include: variable-definitions
- include: variable-substitutions
- include: continuation-or-pop-on-line-end
- match: (?= *::?)
set:
- match: (::?)\s*
captures:
1: keyword.operator.assignment.makefile
set:
- meta_content_scope:
meta.function.arguments.makefile
string.unquoted.makefile
- include: line-continuation
- include: variable-substitutions
- include: highlight-percentage-sign
- match: (?=#)
set:
- match: \#
scope: punctuation.definition.comment.makefile
set:
- meta_scope: comment.line.number-sign.makefile
- match: $
set: recipe-junction-between-spaces-or-tabs
- match: $
set: recipe-junction-between-spaces-or-tabs
- match: (?=\s*;)
set:
- match: ;
scope: punctuation.terminator.makefile
set: recipe-inline
recipe-junction-between-spaces-or-tabs:
- meta_content_scope: meta.function.body.makefile
- include: comments
- match: ^\s*({{startdirective}})
captures:
1: keyword.control.conditional.makefile
push:
- include: inside-control-flow
- include: recipe-junction-between-spaces-or-tabs
- match: ^(?=[ ]+([-@]{1,2})?)
set: recipe-with-spaces
- match: ^(?=\t([-@]{1,2})?)
set: recipe-with-tabs
- match: ^
pop: 1
recipe-inline:
- meta_content_scope: meta.function.body.makefile source.shell.embedded.makefile
- include: recipe-junction-between-spaces-or-tabs
- include: control-flow
- match: $
set: recipe-junction-between-spaces-or-tabs
- include: shell-content
recipe-with-spaces:
- meta_content_scope: meta.function.body.makefile
- match: ^([ ]+)([-@]{1,2})?
captures:
2: constant.language.makefile
push: shell-common
- match: ^(\t)([-@]{1,2})?
captures:
1: invalid.illegal.inconsistent.expected.spaces.makefile
2: constant.language.makefile
- include: recipe-common
- match: ^(?![ ]+)
pop: 1
recipe-with-tabs:
- meta_content_scope: meta.function.body.makefile
- match: ^\t([-@]{1,2})?
captures:
1: constant.language.makefile
push: shell-common
- match: ^([ ]+)([-@]{1,2})?
captures:
1: invalid.illegal.inconsistent.expected.tab.makefile
2: constant.language.makefile
- include: recipe-common
- match: ^(?!\t)
pop: 1
recipe-common:
- include: control-flow
- match: ^\n
shell-common:
- meta_content_scope: source.shell.embedded.makefile
- include: pop-on-line-end
- include: shell-content
shell-content:
- include: Packages/Makefile/Embeddings/Shell (for Makefile).sublime-syntax
apply_prototype: true
line-continuation:
- match: (\\)([ ]*)$\n?
captures:
1: punctuation.separator.continuation.line.makefile
# make sure to resume parsing at next line
push:
- match: (?=\S|^\s*$)
pop: 1
pop-on-line-end:
- match: $
pop: 1
continuation-or-pop-on-line-end:
- include: line-continuation
- include: pop-on-line-end
quoted-string:
- match: "'"
scope: punctuation.definition.string.begin.makefile
push:
- meta_include_prototype: false
- meta_scope: meta.string.makefile string.quoted.single.makefile
- match: "'"
scope: punctuation.definition.string.end.makefile
pop: 1
- include: escape-literals
- include: line-continuation
- include: variable-substitutions
- match: '"'
scope: punctuation.definition.string.begin.makefile
push:
- meta_include_prototype: false
- meta_scope: meta.string.makefile string.quoted.double.makefile
- match: '"'
scope: punctuation.definition.string.end.makefile
pop: 1
- include: escape-literals
- include: line-continuation
- include: variable-substitutions
escape-literals:
- match: \\.
scope: constant.character.escape.makefile
comments:
# This hack is here in order to circumvent false-positives for the big
# rule lookahead. For example, if this match is not present, then things
# like
#
# # A comment with a : colon
#
# will match the rule-lookahead.
- match: (?=^\s*#)
push: comment
# This is the "normal" comment parsing logic, but not sufficient in every
# case (see above).
- match: \#
scope: punctuation.definition.comment.makefile
push: comment-body
comment:
- match: \#
scope: punctuation.definition.comment.makefile
set: comment-body
comment-body:
- meta_scope: comment.line.number-sign.makefile
- include: line-continuation
- match: \\\\
- match: \n
pop: 1
inside-function-call:
- meta_content_scope: meta.function-call.arguments.makefile
- match: \)
scope: keyword.other.block.end.makefile
pop: 1
- match: \(
push: textual-parenthesis-balancer
- match: \,
scope: punctuation.separator.makefile
# eat escaped or unbalanced quotation marks in front of the `,` separator
# to highlight them as ordinary part of the surrounding unquoted string
- match: '\\[''""]|[''""](?=\s*,)'
- include: variable-substitutions
- include: quoted-string
function-invocations:
- match: ({{function_call_token_begin}})(call)\s
captures:
0: meta.function-call.makefile
1: keyword.other.block.begin.makefile
2: constant.language.call.makefile
push:
- meta_content_scope:
meta.function-call.makefile
variable.function.makefile
- match: (?=\))
set: inside-function-call
- match: (?=,)
set:
- meta_content_scope: meta.function-call.makefile
- match: \,
scope: punctuation.separator.makefile
set: inside-function-call
- include: variable-substitutions
- match: ({{function_call_token_begin}})(patsubst|filter)\s
captures:
0: meta.function-call.makefile
1: keyword.other.block.begin.makefile
2: support.function.builtin.makefile
push:
- meta_content_scope: meta.function-call.arguments.makefile
- include: highlight-percentage-sign
- include: inside-function-call
- match: ({{function_call_token_begin}})(wildcard)\s
captures:
0: meta.function-call.makefile
1: keyword.other.block.begin.makefile
2: support.function.builtin.makefile
push:
- meta_content_scope: meta.function-call.arguments.makefile
- include: inside-function-call
- include: highlight-wildcard-sign
- match: ({{function_call_token_begin}})(info|warning|error)\s
captures:
0: meta.function-call.makefile
1: keyword.other.block.begin.makefile
2: support.function.builtin.makefile
push:
- meta_content_scope: meta.function-call.arguments.makefile
- match: \)
scope: keyword.other.block.end.makefile
pop: 1
- match: \(
push: textual-parenthesis-balancer
- match: \,
scope: punctuation.separator.makefile
- include: variable-substitutions
- match: | # multiline string
(?x) # ignore whitespace
({{function_call_token_begin}})
(
subst|
strip|
findstring|
filter-out|
sort|
word|
wordlist|
words|
firstword|
lastword|
dir|
notdir|
suffix|
basename|
addsuffix|
addprefix|
join|
realpath|
abspath|
if|
or|
and|
foreach|
file|
value|
eval|
origin|
flavor|
guile
)
\s
captures:
0: meta.function-call.makefile
1: keyword.other.block.begin.makefile
2: support.function.builtin.makefile
push: inside-function-call
- match: ({{function_call_token_begin}})(shell)\s
captures:
1: keyword.other.block.begin.makefile
2: support.function.builtin.makefile
push:
- meta_content_scope: source.shell.embedded.makefile
- match: \)
scope: keyword.other.block.end.makefile
pop: 1
- include: shell-content
variable-definitions:
- match: \s*(override)\b
captures:
1: keyword.control.makefile
- match: \s*(define)\b
captures:
1: keyword.control.makefile
push: inside-define-directive-context
- match: ^\s*(export)\b
captures:
1: keyword.control.makefile
push:
- meta_content_scope: variable.other.makefile
- include: continuation-or-pop-on-line-end
- include: variable-substitutions
- match: (\?|\+|::?)?=
scope: keyword.operator.assignment.makefile
set: [value-to-be-defined, eat-whitespace-then-pop]
- match: (?={{var_lookahead}})
push:
- meta_content_scope: variable.other.makefile
- match: (?=\s*!=)
set:
- match: '!='
scope: keyword.operator.assignment.makefile
set: shell-common
- match: (?=\s*(!|\?|\+|::?)?=)
set:
- match: (!|\?|\+|::?)?=
scope: keyword.operator.assignment.makefile
set: [value-maybe-shellscript, eat-whitespace-then-pop]
- include: variable-substitutions
- include: continuation-or-pop-on-line-end
- include: variable-substitutions
textual-parenthesis-balancer:
- match: \)
pop: 1
- include: variable-substitutions
eat-whitespace-then-pop:
- clear_scopes: 1
- match: \s*
pop: 1
value-maybe-shellscript:
- match: ((?:bash|sh|zsh)\s+-c\s+)(['"`])
captures:
1: meta.string.makefile string.unquoted.makefile
2: meta.string.makefile meta.interpolation.makefile punctuation.section.interpolation.begin.makefile
embed: shell-content
embed_scope: meta.string.makefile meta.interpolation.makefile source.shell.embedded.makefile
escape: (?!<\\)\2
escape_captures:
0: meta.string.makefile meta.interpolation.makefile punctuation.section.interpolation.end.makefile
- match: ''
set: value-to-be-defined
value-to-be-defined:
- meta_content_scope: meta.string.makefile string.unquoted.makefile
- include: escape-literals
- match: (?=#)
set: comment
- include: variable-substitutions
- include: continuation-or-pop-on-line-end
inside-define-directive-context:
- meta_content_scope: variable.other.makefile
- match: (?=(!|\?|\+|::?)?=\s*\n)
set:
- match: ((!|\?|\+|::?)?=)\s*\n
captures:
1: keyword.operator.assignment.makefile
set: inside-define-directive-value
# Need to eat the actual newline character in order to start the
# string.unquoted scope on the next line.
- match: \n
set: inside-define-directive-value
- include: variable-substitutions
inside-define-directive-value:
- meta_content_scope: meta.string.makefile string.unquoted.makefile
- match: ^\s*(endef)\b
captures:
1: keyword.control.makefile
pop: 1
# keep in balance with nested define statements
# see: https://github.com/sublimehq/Packages/issues/1998
- match: ^\s*define\b
push:
- match: ^\s*endef\b
pop: 1
variable-substitution-common:
- match: ':'
scope: punctuation.definition.substitution.makefile
pop: 1
- include: highlight-percentage-sign
- include: variable-substitutions
variable-substitution-name-inside-paren:
- meta_content_scope: variable.parameter.makefile
- match: \)
scope: keyword.other.block.end.makefile
pop: 2
- include: variable-substitution-common
variable-substitution-reference-inside-paren:
- meta_scope: meta.interpolation.makefile
- match: \)
scope: keyword.other.block.end.makefile
pop: 1
- include: variable-substitution-reference-common
variable-substitution-name-inside-brace:
- meta_content_scope: variable.parameter.makefile
- match: \}
scope: keyword.other.block.end.makefile
pop: 2
- include: variable-substitution-common
variable-substitution-reference-inside-brace:
- meta_scope: meta.interpolation.makefile
- match: \}
scope: keyword.other.block.end.makefile
pop: 1
- include: variable-substitution-reference-common
variable-substitution-reference-common:
- match: =
scope: keyword.operator.assignment.makefile
- include: highlight-percentage-sign
- include: variable-substitutions
variable-substitutions:
- include: function-invocations
- match: \$\(
scope: keyword.other.block.begin.makefile
push:
- variable-substitution-reference-inside-paren
- variable-substitution-name-inside-paren
- match: \${
scope: keyword.other.block.begin.makefile
push:
- variable-substitution-reference-inside-brace
- variable-substitution-name-inside-brace
- match: \$\$?[@%<?^+|*]
scope: variable.language.automatic.makefile
- match: \$(?=\$[{\w])
scope: constant.character.escape.makefile
push:
- include: scope:source.shell.bash#parameter-expansions
- match: ''
pop: 1
- match: \$(?=\$\()
scope: constant.character.escape.makefile
push:
- include: scope:source.shell.embedded.makefile#command-expansions
- match: ''
pop: 1
- match: (\$)[[:alpha:]]
captures:
0: variable.parameter.makefile
1: keyword.other.single-character-variable.makefile