@konomanoasa/tree-sitter-yaml 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/grammar.js ADDED
@@ -0,0 +1,820 @@
1
+ const problems = [
2
+ ["invalid_encoding", "invalid_syntax", "invalid_encoding"],
3
+ ["invalid_character", "invalid_syntax", "invalid_character"],
4
+ ["invalid_escape", "invalid_syntax", "invalid_escape"],
5
+ ["incomplete_escape", "incomplete_syntax", "incomplete_escape"],
6
+ [
7
+ "invalid_line_continuation",
8
+ "invalid_syntax",
9
+ "invalid_line_continuation",
10
+ "escape_indicator",
11
+ ],
12
+ ["invalid_scalar_start", "invalid_syntax", "invalid_scalar_start"],
13
+ ["missing_flow_separator", "invalid_syntax", "missing_flow_separator"],
14
+ ["unexpected_flow_separator", "invalid_syntax", "unexpected_flow_separator"],
15
+ ["invalid_indentation", "invalid_syntax", "invalid_indentation"],
16
+ ["missing_indentation", "invalid_syntax", "missing_indentation"],
17
+ ["missing_separation", "invalid_syntax", "missing_separation"],
18
+ ["invalid_block_header", "invalid_syntax", "invalid_block_header"],
19
+ ["invalid_tag_handle", "invalid_syntax", "invalid_tag_handle"],
20
+ ["invalid_tag_character", "invalid_syntax", "invalid_tag_character"],
21
+ ["invalid_uri_escape", "invalid_syntax", "invalid_uri_escape"],
22
+ ["incomplete_uri_escape", "incomplete_syntax", "incomplete_uri_escape"],
23
+ [
24
+ "invalid_yaml_version",
25
+ "invalid_syntax",
26
+ "invalid_yaml_version",
27
+ "yaml_version",
28
+ ],
29
+ [
30
+ "unfinished_yaml_version",
31
+ "incomplete_syntax",
32
+ "incomplete_yaml_version",
33
+ "yaml_version",
34
+ ],
35
+ [
36
+ "unexpected_directive_parameter",
37
+ "invalid_syntax",
38
+ "unexpected_directive_parameter",
39
+ "directive_parameter",
40
+ ],
41
+ [
42
+ "unexpected_document_end_content",
43
+ "invalid_syntax",
44
+ "unexpected_document_end_content",
45
+ ],
46
+ [
47
+ "invalid_header_indentation",
48
+ "invalid_syntax",
49
+ "invalid_block_header",
50
+ "indentation_indicator",
51
+ ],
52
+ [
53
+ "invalid_header_chomping",
54
+ "invalid_syntax",
55
+ "invalid_block_header",
56
+ "chomping_indicator",
57
+ ],
58
+ ["missing_document_end", "invalid_syntax", "missing_document_end"],
59
+ ...[
60
+ "quote_close",
61
+ "flow_sequence_close",
62
+ "flow_mapping_close",
63
+ "value_indicator",
64
+ "anchor_name",
65
+ "alias_name",
66
+ "tag_uri",
67
+ "tag_suffix",
68
+ "verbatim_tag_close",
69
+ "directive_name",
70
+ "yaml_version",
71
+ "tag_handle",
72
+ "tag_handle_close",
73
+ "tag_prefix",
74
+ "document_start",
75
+ ].flatMap((name) => [
76
+ [`missing_${name}`, "invalid_syntax", `missing_${name}`],
77
+ [`incomplete_${name}`, "incomplete_syntax", `missing_${name}`],
78
+ ]),
79
+ ];
80
+ const issue = ($, name) =>
81
+ field("issue", alias($[`_${name}_issue`], $.syntax_issue));
82
+ const missing = ($, name) =>
83
+ choice(issue($, `missing_${name}`), issue($, `incomplete_${name}`));
84
+ const invalid = ($) =>
85
+ choice(issue($, "invalid_encoding"), issue($, "invalid_character"));
86
+ const problemRules = Object.fromEntries(
87
+ problems.flatMap(([name, outcome, reason, leaf]) => [
88
+ ...(leaf
89
+ ? [[`_${name}_reason`, ($) => alias($[`_${name}`], $[leaf])]]
90
+ : []),
91
+ [
92
+ `_${name}_outcome`,
93
+ ($) => alias($[leaf ? `_${name}_reason` : `_${name}`], $[reason]),
94
+ ],
95
+ [`_${name}_issue`, ($) => alias($[`_${name}_outcome`], $[outcome])],
96
+ ]),
97
+ );
98
+ const structuredProblems = [
99
+ [
100
+ "unexpected_document_content",
101
+ "unexpected_document_content",
102
+ ($) =>
103
+ seq(
104
+ $._unexpected_content_start,
105
+ field("content", $._node),
106
+ $._document_content_end,
107
+ ),
108
+ ],
109
+ [
110
+ "invalid_document_collection",
111
+ "invalid_compact_collection",
112
+ ($) => seq($._document_compact_start, field("content", $._node)),
113
+ ],
114
+ [
115
+ "duplicate_anchor",
116
+ "duplicate_anchor",
117
+ ($) => seq($._duplicate_anchor_start, field("property", $.anchor)),
118
+ ],
119
+ [
120
+ "duplicate_tag",
121
+ "duplicate_tag",
122
+ ($) => seq($._duplicate_tag_start, field("property", $._tag)),
123
+ ],
124
+ [
125
+ "properties_on_alias",
126
+ "properties_on_alias",
127
+ ($) => seq($._property_alias_start, field("content", $.alias)),
128
+ ],
129
+ [
130
+ "invalid_property_collection",
131
+ "invalid_compact_collection",
132
+ ($) => seq($._property_compact_start, field("content", $._node_content)),
133
+ ],
134
+ [
135
+ "invalid_compact_collection",
136
+ "invalid_compact_collection",
137
+ ($) => seq($._invalid_compact_start, field("value", $._node)),
138
+ ],
139
+ [
140
+ "invalid_implicit_key",
141
+ "invalid_implicit_key",
142
+ ($) =>
143
+ seq(
144
+ $._implicit_key_start,
145
+ field("key", $._flow_node),
146
+ $._invalid_key_end,
147
+ ),
148
+ ],
149
+ ];
150
+ for (const [name, reason, body] of structuredProblems) {
151
+ problemRules[`_${name}_reason`] = body;
152
+ problemRules[`_${name}_outcome`] = ($) =>
153
+ alias($[`_${name}_reason`], $[reason]);
154
+ problemRules[`_${name}_issue`] = ($) =>
155
+ alias($[`_${name}_outcome`], $.invalid_syntax);
156
+ }
157
+ export default grammar({
158
+ name: "yaml",
159
+ externals: ($) => [
160
+ $.line_break,
161
+ $._eof,
162
+ $._document_open,
163
+ $._document_close,
164
+ $.document_start,
165
+ $.document_end,
166
+ $.byte_order_mark,
167
+ $._indent,
168
+ $._dedent,
169
+ $._outdent,
170
+ $._restore_indent,
171
+ $._mapping_start,
172
+ $._mapping_end,
173
+ $._pair_start,
174
+ $._sequence_start,
175
+ $._sequence_end,
176
+ $._entry_start,
177
+ $._value_start,
178
+ $._sequence_value_start,
179
+ $._empty_block_node,
180
+ $._explicit_value_start,
181
+ $._invalid_compact_start,
182
+ $.sequence_indicator,
183
+ $.value_indicator,
184
+ $.key_indicator,
185
+ $._single_start,
186
+ $._double_start,
187
+ $._flow_sequence_start,
188
+ $._flow_mapping_start,
189
+ $._flow_map_pair_start,
190
+ $._flow_seq_pair_start,
191
+ $._implicit_key_start,
192
+ $._key_end,
193
+ $._invalid_key_end,
194
+ $._flow_node_end,
195
+ $._plain_start,
196
+ $._plain_end,
197
+ $._plain_continue,
198
+ $.scalar_text,
199
+ $._single_open,
200
+ $._double_open,
201
+ $.quote_close,
202
+ $.quoted_escape,
203
+ $.escaped_quote,
204
+ $.scalar_line_break,
205
+ $.scalar_line_prefix,
206
+ $.scalar_line_suffix,
207
+ $.escape_indicator,
208
+ $.flow_sequence_open,
209
+ $.flow_sequence_close,
210
+ $.flow_mapping_open,
211
+ $.flow_mapping_close,
212
+ $.flow_separator,
213
+ $._comment_start,
214
+ $.comment_marker,
215
+ $.comment_text,
216
+ $._comment_end,
217
+ $._line_prefix_start,
218
+ $._line_prefix_end,
219
+ $.indentation,
220
+ $.separation,
221
+ $._line_context,
222
+ $._literal_start,
223
+ $._folded_start,
224
+ $.literal_indicator,
225
+ $.folded_indicator,
226
+ $.indentation_indicator,
227
+ $.chomping_indicator,
228
+ $.block_header_break,
229
+ $._block_header_end,
230
+ $._block_body_start,
231
+ $._block_scalar_end,
232
+ $._block_text_line_start,
233
+ $._block_spaced_line_start,
234
+ $._block_empty_line_start,
235
+ $._block_line_end,
236
+ $._boundary_check,
237
+ $._document_content_end,
238
+ $._document_compact_start,
239
+ $._unexpected_content_start,
240
+ $._properties_start,
241
+ $._properties_end,
242
+ $._property_content_start,
243
+ $._block_property_content_start,
244
+ $._block_key_content_start,
245
+ $._duplicate_anchor_start,
246
+ $._duplicate_tag_start,
247
+ $._property_alias_start,
248
+ $._property_compact_start,
249
+ $.anchor_indicator,
250
+ $._alias_start,
251
+ $.alias_indicator,
252
+ $.anchor_name,
253
+ $.alias_name,
254
+ $._name_end,
255
+ $._verbatim_tag_start,
256
+ $.verbatim_tag_open,
257
+ $.verbatim_tag_close,
258
+ $._shorthand_tag_start,
259
+ $.non_specific_tag,
260
+ $._tag_handle_start,
261
+ $.primary_tag_handle,
262
+ $.secondary_tag_handle,
263
+ $.tag_handle_open,
264
+ $.tag_handle_name,
265
+ $.tag_handle_close,
266
+ $._tag_suffix_start,
267
+ $._tag_end,
268
+ $._tag_uri_start,
269
+ $._tag_uri_end,
270
+ $.uri_text,
271
+ $.tag_suffix_text,
272
+ $.uri_escape,
273
+ $._yaml_directive_start,
274
+ $._tag_directive_start,
275
+ $._reserved_directive_start,
276
+ $.directive_indicator,
277
+ $.directive_name,
278
+ $._directive_name_end,
279
+ $._directive_end,
280
+ $.yaml_version,
281
+ $._tag_prefix_start,
282
+ $._tag_prefix_end,
283
+ $.directive_parameter,
284
+ ...problems.map(([name]) => $[`_${name}`]),
285
+ $._error_sentinel,
286
+ ],
287
+ extras: ($) => [
288
+ $.line_break,
289
+ $.separation,
290
+ $.comment,
291
+ $.line_prefix,
292
+ $._line_context,
293
+ $._boundary_check,
294
+ $._unmatchable,
295
+ ],
296
+ rules: {
297
+ stream: ($) =>
298
+ seq(
299
+ repeat(
300
+ choice(
301
+ $.document,
302
+ $.document_end,
303
+ $.byte_order_mark,
304
+ invalid($),
305
+ issue($, "unexpected_document_end_content"),
306
+ ),
307
+ ),
308
+ $._eof,
309
+ ),
310
+ document: ($) =>
311
+ seq(
312
+ $._document_open,
313
+ optional(issue($, "missing_document_end")),
314
+ choice(
315
+ seq(
316
+ repeat1(
317
+ choice($.yaml_directive, $.tag_directive, $.reserved_directive),
318
+ ),
319
+ choice($.document_start, missing($, "document_start")),
320
+ ),
321
+ optional(choice($.document_start, missing($, "document_start"))),
322
+ ),
323
+ optional(
324
+ seq(
325
+ choice(
326
+ field("content", $._node),
327
+ issue($, "invalid_document_collection"),
328
+ ),
329
+ $._document_content_end,
330
+ ),
331
+ ),
332
+ repeat(issue($, "unexpected_document_content")),
333
+ $._document_close,
334
+ ),
335
+ yaml_directive: ($) =>
336
+ seq(
337
+ directiveHead($, $._yaml_directive_start),
338
+ repeat(invalid($)),
339
+ choice(
340
+ field("version", $.yaml_version),
341
+ missing($, "yaml_version"),
342
+ issue($, "invalid_yaml_version"),
343
+ issue($, "unfinished_yaml_version"),
344
+ ),
345
+ directiveTail($),
346
+ ),
347
+ tag_directive: ($) =>
348
+ seq(
349
+ directiveHead($, $._tag_directive_start),
350
+ repeat(invalid($)),
351
+ choice(
352
+ seq(
353
+ $._tag_handle_start,
354
+ field(
355
+ "handle",
356
+ choice(
357
+ $.primary_tag_handle,
358
+ $.secondary_tag_handle,
359
+ alias($._directive_named_handle, $.named_tag_handle),
360
+ ),
361
+ ),
362
+ ),
363
+ missing($, "tag_handle"),
364
+ issue($, "invalid_tag_handle"),
365
+ ),
366
+ optional(issue($, "missing_separation")),
367
+ choice(field("prefix", $.tag_prefix), missing($, "tag_prefix")),
368
+ directiveTail($),
369
+ ),
370
+ reserved_directive: ($) =>
371
+ seq(
372
+ directiveHead($, $._reserved_directive_start),
373
+ repeat(choice(field("parameter", $.directive_parameter), invalid($))),
374
+ $._directive_end,
375
+ ),
376
+ _directive_named_handle: ($) =>
377
+ seq(
378
+ field("opening", $.tag_handle_open),
379
+ repeat1(
380
+ choice(
381
+ field("name", $.tag_handle_name),
382
+ issue($, "invalid_tag_handle"),
383
+ invalid($),
384
+ ),
385
+ ),
386
+ choice(
387
+ field("closing", $.tag_handle_close),
388
+ missing($, "tag_handle_close"),
389
+ ),
390
+ ),
391
+ tag_prefix: ($) =>
392
+ seq(
393
+ $._tag_prefix_start,
394
+ repeat1(uriPart($, $.uri_text)),
395
+ $._tag_prefix_end,
396
+ ),
397
+ _node: ($) => choice($._node_content, $.alias, $.node_with_properties),
398
+ _node_content: ($) =>
399
+ choice(
400
+ $._flow_content,
401
+ $._indented_node,
402
+ $._dedented_node,
403
+ $.block_mapping,
404
+ $.block_sequence,
405
+ $.literal_scalar,
406
+ $.folded_scalar,
407
+ ),
408
+ _flow_node: ($) =>
409
+ choice(
410
+ $._flow_content,
411
+ $.alias,
412
+ alias($._flow_properties, $.node_with_properties),
413
+ ),
414
+ _flow_content: ($) =>
415
+ choice(
416
+ $.plain_scalar,
417
+ $.single_quoted_scalar,
418
+ $.double_quoted_scalar,
419
+ $.flow_sequence,
420
+ $.flow_mapping,
421
+ ),
422
+ node_with_properties: ($) =>
423
+ propertyNode(
424
+ $,
425
+ seq($._block_property_content_start, field("content", $._node_content)),
426
+ ),
427
+ _flow_properties: ($) =>
428
+ propertyNode(
429
+ $,
430
+ choice(
431
+ seq($._property_content_start, field("content", $._flow_content)),
432
+ seq($._block_key_content_start, field("content", $._node_content)),
433
+ ),
434
+ ),
435
+ _property: ($) => choice($.anchor, $._tag),
436
+ _tag: ($) => choice($.non_specific_tag, $.shorthand_tag, $.verbatim_tag),
437
+ anchor: ($) =>
438
+ seq(
439
+ field("indicator", $.anchor_indicator),
440
+ choice(
441
+ repeat1(choice(field("name", $.anchor_name), invalid($))),
442
+ missing($, "anchor_name"),
443
+ ),
444
+ $._name_end,
445
+ ),
446
+ alias: ($) =>
447
+ seq(
448
+ $._alias_start,
449
+ field("indicator", $.alias_indicator),
450
+ choice(
451
+ repeat1(choice(field("name", $.alias_name), invalid($))),
452
+ missing($, "alias_name"),
453
+ ),
454
+ $._name_end,
455
+ ),
456
+ shorthand_tag: ($) =>
457
+ seq(
458
+ $._shorthand_tag_start,
459
+ $._tag_handle_start,
460
+ field(
461
+ "handle",
462
+ choice(
463
+ $.primary_tag_handle,
464
+ $.secondary_tag_handle,
465
+ $.named_tag_handle,
466
+ ),
467
+ ),
468
+ choice(field("suffix", $.tag_suffix), missing($, "tag_suffix")),
469
+ $._tag_end,
470
+ ),
471
+ named_tag_handle: ($) =>
472
+ seq(
473
+ field("opening", $.tag_handle_open),
474
+ repeat1(
475
+ choice(
476
+ field("name", $.tag_handle_name),
477
+ issue($, "invalid_tag_handle"),
478
+ invalid($),
479
+ ),
480
+ ),
481
+ field("closing", $.tag_handle_close),
482
+ ),
483
+ verbatim_tag: ($) =>
484
+ seq(
485
+ $._verbatim_tag_start,
486
+ field("opening", $.verbatim_tag_open),
487
+ choice(field("uri", $.tag_uri), missing($, "tag_uri")),
488
+ choice(
489
+ field("closing", $.verbatim_tag_close),
490
+ missing($, "verbatim_tag_close"),
491
+ ),
492
+ ),
493
+ tag_uri: ($) =>
494
+ seq($._tag_uri_start, repeat1(uriPart($, $.uri_text)), $._tag_uri_end),
495
+ tag_suffix: ($) =>
496
+ seq($._tag_suffix_start, repeat1(uriPart($, $.tag_suffix_text))),
497
+ _indented_node: ($) =>
498
+ seq(
499
+ $._indent,
500
+ choice($._indented_node, $.block_mapping, $.block_sequence),
501
+ $._dedent,
502
+ ),
503
+ _dedented_node: ($) =>
504
+ seq(
505
+ $._outdent,
506
+ choice($._dedented_node, $.block_mapping, $.block_sequence),
507
+ $._restore_indent,
508
+ ),
509
+ block_mapping: ($) =>
510
+ seq($._mapping_start, repeat1($.block_mapping_pair), $._mapping_end),
511
+ block_mapping_pair: ($) =>
512
+ seq(
513
+ $._pair_start,
514
+ choice(
515
+ seq(
516
+ field("key_indicator", $.key_indicator),
517
+ choice(
518
+ seq($._value_start, field("key", $._node)),
519
+ $._empty_block_node,
520
+ ),
521
+ choice(
522
+ seq(
523
+ $._explicit_value_start,
524
+ field("indicator", $.value_indicator),
525
+ choice(
526
+ seq($._value_start, field("value", $._node)),
527
+ $._empty_block_node,
528
+ ),
529
+ ),
530
+ $._empty_block_node,
531
+ ),
532
+ ),
533
+ seq(
534
+ optional($._implicit_key),
535
+ choice(
536
+ seq(
537
+ field("indicator", $.value_indicator),
538
+ choice(
539
+ seq($._value_start, field("value", $._node)),
540
+ issue($, "invalid_compact_collection"),
541
+ $._empty_block_node,
542
+ ),
543
+ ),
544
+ missing($, "value_indicator"),
545
+ ),
546
+ ),
547
+ ),
548
+ ),
549
+ block_sequence: ($) =>
550
+ seq($._sequence_start, repeat1($.block_sequence_entry), $._sequence_end),
551
+ block_sequence_entry: ($) =>
552
+ seq(
553
+ $._entry_start,
554
+ field("indicator", $.sequence_indicator),
555
+ choice(
556
+ seq($._sequence_value_start, field("value", $._node)),
557
+ $._empty_block_node,
558
+ ),
559
+ ),
560
+ literal_scalar: ($) => blockScalar($, $._literal_start),
561
+ folded_scalar: ($) => blockScalar($, $._folded_start),
562
+ block_scalar_header: ($) =>
563
+ seq(
564
+ field("style", choice($.literal_indicator, $.folded_indicator)),
565
+ repeat(
566
+ choice(
567
+ field("indentation", $.indentation_indicator),
568
+ field("chomping", $.chomping_indicator),
569
+ issue($, "invalid_block_header"),
570
+ issue($, "invalid_header_indentation"),
571
+ issue($, "invalid_header_chomping"),
572
+ invalid($),
573
+ ),
574
+ ),
575
+ optional($.block_header_break),
576
+ $._block_header_end,
577
+ ),
578
+ block_scalar_line: ($) => blockLine($, $._block_text_line_start),
579
+ block_scalar_spaced_line: ($) => blockLine($, $._block_spaced_line_start),
580
+ block_scalar_empty_line: ($) => blockLine($, $._block_empty_line_start),
581
+ plain_scalar: ($) =>
582
+ seq(
583
+ $._plain_start,
584
+ repeat1(
585
+ choice(
586
+ $.scalar_text,
587
+ $._plain_continue,
588
+ $.scalar_line_break,
589
+ $.scalar_line_prefix,
590
+ $.scalar_line_suffix,
591
+ issue($, "invalid_indentation"),
592
+ issue($, "missing_indentation"),
593
+ invalid($),
594
+ issue($, "invalid_scalar_start"),
595
+ ),
596
+ ),
597
+ $._plain_end,
598
+ ),
599
+ single_quoted_scalar: ($) =>
600
+ quotedScalar($, $._single_start, $._single_open, [$.escaped_quote]),
601
+ double_quoted_scalar: ($) =>
602
+ quotedScalar($, $._double_start, $._double_open, [
603
+ $.quoted_escape,
604
+ $.line_continuation,
605
+ issue($, "invalid_escape"),
606
+ issue($, "incomplete_escape"),
607
+ ]),
608
+ line_continuation: ($) =>
609
+ prec.right(
610
+ seq(
611
+ choice($.escape_indicator, issue($, "invalid_line_continuation")),
612
+ $.scalar_line_break,
613
+ optional($.scalar_line_prefix),
614
+ ),
615
+ ),
616
+ flow_sequence: ($) =>
617
+ seq(
618
+ $._flow_sequence_start,
619
+ field("opening", $.flow_sequence_open),
620
+ flowContent(
621
+ $,
622
+ choice(
623
+ seq($._implicit_key_start, $._flow_node, $._flow_node_end),
624
+ alias($._flow_sequence_pair, $.flow_mapping_pair),
625
+ ),
626
+ ),
627
+ choice(
628
+ field("closing", $.flow_sequence_close),
629
+ missing($, "flow_sequence_close"),
630
+ ),
631
+ ),
632
+ flow_mapping: ($) =>
633
+ seq(
634
+ $._flow_mapping_start,
635
+ field("opening", $.flow_mapping_open),
636
+ flowContent($, $.flow_mapping_pair),
637
+ choice(
638
+ field("closing", $.flow_mapping_close),
639
+ missing($, "flow_mapping_close"),
640
+ ),
641
+ ),
642
+ flow_mapping_pair: ($) => seq($._flow_map_pair_start, $._flow_pair_body),
643
+ _flow_sequence_pair: ($) =>
644
+ choice(
645
+ seq($._flow_seq_pair_start, choice(explicitFlowPair($), flowValue($))),
646
+ seq($._implicit_key, flowValue($)),
647
+ ),
648
+ _implicit_key: ($) =>
649
+ choice(
650
+ seq($._implicit_key_start, field("key", $._flow_node), $._key_end),
651
+ issue($, "invalid_implicit_key"),
652
+ ),
653
+ _flow_pair_body: ($) =>
654
+ choice(
655
+ explicitFlowPair($),
656
+ seq(field("key", $._flow_node), optional(flowValue($))),
657
+ flowValue($),
658
+ ),
659
+ comment: ($) =>
660
+ seq(
661
+ $._comment_start,
662
+ optional(issue($, "missing_separation")),
663
+ $.comment_marker,
664
+ repeat(choice($.comment_text, invalid($))),
665
+ $._comment_end,
666
+ ),
667
+ line_prefix: ($) =>
668
+ seq(
669
+ $._line_prefix_start,
670
+ repeat1(
671
+ choice(
672
+ $.indentation,
673
+ $.separation,
674
+ issue($, "invalid_indentation"),
675
+ issue($, "missing_indentation"),
676
+ ),
677
+ ),
678
+ $._line_prefix_end,
679
+ ),
680
+ // A nonmatching internal token keeps lexer fallback from accepting EOF mid-input.
681
+ _unmatchable: () => token(seq(/[\s\S]/, /[^\s\S]/)),
682
+ ...problemRules,
683
+ },
684
+ });
685
+
686
+ function flowContent($, entry) {
687
+ const extra = () => repeat(issue($, "unexpected_flow_separator"));
688
+ return seq(
689
+ extra(),
690
+ optional(
691
+ seq(
692
+ entry,
693
+ repeat(
694
+ seq(
695
+ choice($.flow_separator, issue($, "missing_flow_separator")),
696
+ extra(),
697
+ entry,
698
+ ),
699
+ ),
700
+ optional(seq($.flow_separator, extra())),
701
+ ),
702
+ ),
703
+ );
704
+ }
705
+
706
+ function blockScalar($, start) {
707
+ return seq(
708
+ start,
709
+ field("header", $.block_scalar_header),
710
+ $._block_body_start,
711
+ repeat(
712
+ choice(
713
+ $.block_scalar_line,
714
+ $.block_scalar_spaced_line,
715
+ $.block_scalar_empty_line,
716
+ ),
717
+ ),
718
+ $._block_scalar_end,
719
+ );
720
+ }
721
+ function blockLine($, start) {
722
+ return seq(
723
+ start,
724
+ optional(field("prefix", $.scalar_line_prefix)),
725
+ repeat(
726
+ choice(
727
+ $.scalar_text,
728
+ issue($, "missing_indentation"),
729
+ issue($, "invalid_indentation"),
730
+ invalid($),
731
+ ),
732
+ ),
733
+ optional($.scalar_line_break),
734
+ $._block_line_end,
735
+ );
736
+ }
737
+
738
+ function propertyNode($, content) {
739
+ return seq(
740
+ $._properties_start,
741
+ repeat1(
742
+ choice(
743
+ field("property", $._property),
744
+ issue($, "duplicate_anchor"),
745
+ issue($, "duplicate_tag"),
746
+ issue($, "missing_separation"),
747
+ ),
748
+ ),
749
+ $._properties_end,
750
+ optional(issue($, "missing_separation")),
751
+ optional(
752
+ choice(
753
+ content,
754
+ issue($, "properties_on_alias"),
755
+ issue($, "invalid_property_collection"),
756
+ ),
757
+ ),
758
+ );
759
+ }
760
+ function directiveHead($, start) {
761
+ return seq(
762
+ start,
763
+ field("indicator", $.directive_indicator),
764
+ choice(
765
+ repeat1(choice(field("name", $.directive_name), invalid($))),
766
+ missing($, "directive_name"),
767
+ ),
768
+ $._directive_name_end,
769
+ );
770
+ }
771
+ function directiveTail($) {
772
+ return seq(
773
+ repeat(choice(issue($, "unexpected_directive_parameter"), invalid($))),
774
+ $._directive_end,
775
+ );
776
+ }
777
+ function uriPart($, text) {
778
+ return choice(
779
+ text,
780
+ $.uri_escape,
781
+ issue($, "invalid_uri_escape"),
782
+ issue($, "incomplete_uri_escape"),
783
+ issue($, "invalid_tag_character"),
784
+ invalid($),
785
+ );
786
+ }
787
+
788
+ function explicitFlowPair($) {
789
+ return seq(
790
+ field("key_indicator", $.key_indicator),
791
+ optional(field("key", $._flow_node)),
792
+ optional(flowValue($)),
793
+ );
794
+ }
795
+ function flowValue($) {
796
+ return seq(
797
+ field("indicator", $.value_indicator),
798
+ optional(issue($, "missing_separation")),
799
+ optional(field("value", $._flow_node)),
800
+ );
801
+ }
802
+ function quotedScalar($, start, opening, escapes) {
803
+ return seq(
804
+ start,
805
+ field("opening", alias(opening, $.quote_open)),
806
+ repeat(
807
+ choice(
808
+ $.scalar_text,
809
+ $.scalar_line_break,
810
+ $.scalar_line_prefix,
811
+ $.scalar_line_suffix,
812
+ issue($, "invalid_indentation"),
813
+ issue($, "missing_indentation"),
814
+ invalid($),
815
+ ...escapes,
816
+ ),
817
+ ),
818
+ choice(field("closing", $.quote_close), missing($, "quote_close")),
819
+ );
820
+ }