yaml-rust2 0.8.1

A fully YAML 1.2 compliant YAML parser
Documentation
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
%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
file_extensions:
  - make
  - GNUmakefile
  - makefile
  - Makefile
  - OCamlMakefile
  - mak
  - mk
first_line_match: ^#!\s*/usr/bin/make\b
scope: source.makefile
#-------------------------------------------------------------------------------
variables:

  varassign: (\?|\+|::?)?=
  shellassign: '!='
  startdirective: ifn?(def|eq)
  include: '[s-]?include'
  ruleassign: :(?!=)
  function_call_token_begin: \$\$?\(

  # The big "rule lookahead". What we want to do is 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.
  nps: '[^()]*'
  open: '(?:\('
  close: '\))?'       # ignore this invalid.illegal
  just_eat: |         # WARNING: INSANITY FOLLOWS!
    (?x)              # ignore whitespace in this regex
      {{nps}}         #       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
      {{nps}}         #       level 0
  rule_lookahead: '{{just_eat}}{{ruleassign}}{{just_eat}}'

  var_lookahead_base: '{{just_eat}}({{varassign}}|{{shellassign}}){{just_eat}}'
  # Just as with rules we want to look ahead if we are going to define a var.
  # However, due to the possibility of "target-specific" variables (see 6.11),
  # we want to NOT match if there's a {{ruleassign}} before a {{varassign}}.
  var_lookahead: (?!{{rule_lookahead}}){{var_lookahead_base}}

  first_assign_then_colon: |
    (?x)
      {{just_eat}}
        {{varassign}}
      {{just_eat}}
        {{ruleassign}}
      {{just_eat}}

#-------------------------------------------------------------------------------
contexts:

  # 3.1 What Makefiles Contain
  # Makefiles contain five kinds of things: explicit rules, implicit rules,
  # variable definitions, directives, and comments.
  main:
    - include: comments
    - include: variable-definitions
    - match: (?={{rule_lookahead}})
      push: expect-rule
    - include: variable-substitutions
    - include: control-flow
    - 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: string.quoted.single.makefile
        - match: "'"
          scope: punctuation.definition.string.end.makefile
          pop: true
        - include: escape-literals
        - include: line-continuation
        - include: variable-substitutions
    - match: '"'
      scope: punctuation.definition.string.begin.makefile
      push:
        - meta_scope: string.quoted.double.makefile
        - match: '"'
          scope: punctuation.definition.string.end.makefile
          pop: true
        - 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: true
        - 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: 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: 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: variable.language.wildcard.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: true

  recipe-inline:
    - meta_content_scope: meta.function.body.makefile
    - include: recipe-junction-between-spaces-or-tabs
    - include: control-flow
    - match: $
      set: recipe-junction-between-spaces-or-tabs
    - match: ""
      push: shell

  recipe-with-spaces:
    - meta_content_scope: meta.function.body.makefile
    - match: ^([ ]+)([-@]{1,2})?
      captures:
        2: constant.language.makefile
      push: shell
    - match: ^(\t)([-@]{1,2})?
      captures:
        1: invalid.illegal.inconsistent.expected.spaces.makefile
        2: constant.language.makefile
    - include: recipe-common
    - match: ^(?![ ]+)
      pop: true

  recipe-with-tabs:
    - meta_content_scope: meta.function.body.makefile
    - match: ^\t([-@]{1,2})?
      captures:
        1: constant.language.makefile
      push: shell
    - match: ^([ ]+)([-@]{1,2})?
      captures:
        1: invalid.illegal.inconsistent.expected.tab.makefile
        2: constant.language.makefile
    - include: recipe-common
    - match: ^(?!\t)
      pop: true

  recipe-common:
    - include: control-flow
    - match: ^\n
    
  shell:
    # Due to how the shell syntax handles comments, we must account for the case
    # where a recipe-line is a single comment in combination with an "@" or "-"
    # from Make.
    - match: \s*(#)
      captures:
        1: punctuation.definition.comment.begin.shell
      set:
        # I don't like putting the string "source.shell" here, as the delegation
        # seeps into this syntax now. But I don't see a cleaner way right now.
        - meta_scope: source.shell comment.line.number-sign.shell
        - include: pop-on-line-end
    # Otherwise, delegate to the shell syntax (with various extra prototypes).
    - match: ""
      set: scope:source.shell
      with_prototype:
        - include: line-continuation
        - include: variable-substitutions
        - include: pop-on-line-end

  line-continuation:
    - match: (\\)([ ]*)$\n?
      captures:
        1: punctuation.separator.continuation.line.makefile
      # make sure to resume parsing at next line
      push:
        - match: (?=\S|^\s*$)
          pop: true

  pop-on-line-end:
    - match: $
      pop: true

  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_scope: string.quoted.single.makefile
        - match: "'"
          scope: punctuation.definition.string.end.makefile
          pop: true
        - include: escape-literals
        - include: line-continuation
        - include: variable-substitutions
    - match: '"'
      scope: punctuation.definition.string.begin.makefile
      push:
        - meta_scope: string.quoted.double.makefile
        - match: '"'
          scope: punctuation.definition.string.end.makefile
          pop: true
        - 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:
        - match: \#
          scope: punctuation.definition.comment.makefile
          set:
            - meta_scope: comment.line.number-sign.makefile
            - include: pop-on-line-end
    # This is the "normal" comment parsing logic, but not sufficient in every
    # case (see above).
    - match: \#
      scope: punctuation.definition.comment.makefile
      push:
        - meta_scope: comment.line.number-sign.makefile
        - include: pop-on-line-end

  inside-function-call:
    - meta_content_scope: meta.function-call.arguments.makefile
    - match: \)
      scope: keyword.other.block.end.makefile
      pop: true
    - match: \(
      push: textual-parenthesis-balancer
    - match: \,
      scope: punctuation.separator.makefile
    - 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:
            - 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: true
        - 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:
        - match: \)
          scope: keyword.other.block.end.makefile
          pop: true
        - match: ''
          push: scope:source.shell
          with_prototype:
            - match: (?=\))
              pop: true
            - include: variable-substitutions
            - include: quoted-string
            - match: \(
              push: textual-parenthesis-balancer

  variable-definitions:
    - match: \s*(override)\b
      captures:
        1: keyword.control.makefile
      set:
        - match: \bdefine\b
          scope: keyword.control.makefile
          push: inside-define-directive-context
        - include: variable-definitions
        - include: continuation-or-pop-on-line-end
    - 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}}|{{first_assign_then_colon}})
      push:
        - meta_content_scope: variable.other.makefile
        - match: (?=\s*!=)
          set:
            - match: '!='
              scope: keyword.operator.assignment.makefile
              set: scope:source.shell
              with_prototype:
                - include: variable-substitutions
                - include: pop-on-line-end
                - include: textual-parenthesis-balancer
        - match: (?=\s*(!|\?|\+|::?)?=)
          set:
            - match: (!|\?|\+|::?)?=
              scope: keyword.operator.assignment.makefile
              set: [value-to-be-defined, eat-whitespace-then-pop]
            - include: variable-substitutions
            - include: continuation-or-pop-on-line-end
        - include: variable-substitutions

  textual-parenthesis-balancer:
    - match: \)
      pop: true
    - include: variable-substitutions

  eat-whitespace-then-pop:
    - clear_scopes: 1
    - match: \s*
      pop: true

  value-to-be-defined:
    - meta_content_scope: string.unquoted.makefile
    - include: escape-literals
    - match: (?=#)
      set:
        - match: \#
          scope: punctuation.definition.comment.makefile
          set:
            - meta_scope: comment.line.number-sign.makefile
            - include: pop-on-line-end
    - include: variable-substitutions
    - include: continuation-or-pop-on-line-end

  inside-define-directive-context:
    - meta_content_scope: variable.other.makefile
    - match: \s*(?=(!|\?|\+|::?)?=\s*$\n)
      set:
        - match: ((!|\?|\+|::?)?=)\s*$\n
          captures:
            1: keyword.operator.assignment.makefile
          set:
            - meta_content_scope: string.unquoted.makefile
            - match: ^\s*(endef)
              captures:
                1: keyword.control.makefile
              pop: true
    # Need to eat the actual newline character in order to start the
    # string.unquoted scope on the next line.
    - match: $\n
      set:
        - meta_content_scope: string.unquoted.makefile
        - match: ^\s*(endef)
          captures:
            1: keyword.control.makefile
          pop: true
    - include: variable-substitutions

  variable-sub-common:
    - match: ':'
      scope: punctuation.definition.substitution.makefile
    - match: =
      scope: punctuation.definition.assignment.makefile
    - include: highlight-percentage-sign
    - include: variable-substitutions

  variable-substitutions:
    - include: function-invocations
    - match: \$\$?\(
      scope: keyword.other.block.begin.makefile
      push:
        - meta_scope: variable.parameter.makefile
        - match: \)
          scope: keyword.other.block.end.makefile
          pop: true
        - include: variable-sub-common
    - match: \$\$?{
      scope: keyword.other.block.begin.makefile
      push:
        - meta_scope: variable.parameter.makefile
        - match: \}
          scope: keyword.other.block.end.makefile
          pop: true
        - include: variable-sub-common
    - match: \$\$?[@%<?^+|*]
      scope: variable.language.automatic.makefile
    - match: \$\$
      scope: constant.character.escape.makefile
    - match: (\$)[[:alpha:]]
      captures:
        0: variable.parameter.makefile
        1: keyword.other.single-character-variable.makefile