blib/lib/YAML/Parser.pm

filter: Statementstmt 33.3% 11 / 33 Branchbran n/a Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 38.4% 5 / 13 Podpod n/a totaltotal 28.5% 16 / 56 CC 3 SCAR 9.9
CC
3
Cov
28%
new
6.0
new
6.0
__ANON__
2.0
CRAP 2.7
↑ Summary
1 1 ▶use v5.12;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package YAML::Parser;
3  
4 our $VERSION = '0.0.1';
5  
6 sub new {
7 0 ▶ my ($class, %self) = @_;
Subroutine new: not called CC=2 SCAR=17.9
8 0 my $self = bless {
9 %self,
10 events => [],
11 }, $class;
12 $self->{receiver} //= sub {
13 0 ▶ my ($event) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
14 0 push @{$self->{events}}, $event;
15 0 ▶ };
Condition0%0/3
$self->{"receiver"} //= sub { my($event) = @_; push @{$$self{"events"};}, $event; }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"receiver"} //= sub { my($event) = @_; push @{$$self{"events"};}, $event; }
$self->{"receiver"} sub { my($event) = @_; push @{$$self{"events"};}, $event; }
Truth table0%0/3
A //= B
A= $self->{"receiver"}B= sub { my($event) = @_; push @{$$self{"events"};}, $event; }
ABresult
1X1
011
000
16  
17 0 return $self;
18 }
19  
20 sub parse {
21 0 ▶ my ($self, $yaml_string) = @_;
Subroutine parse: not called CC=1 SCAR=6.9
22 my $receiver = PerlYamlReferenceParserReceiver->new(
23 callback => $self->{receiver},
24 0 );
25 0 my $parser = PerlYamlReferenceParserParser->new($receiver);
26 0 $parser->parse($yaml_string);
27 0 return $self;
28 }
29  
30 sub events {
31 0 ▶ my ($self) = @_;
Subroutine events: not called CC=1 SCAR=6.9
32 0 return @{$self->{events}};
33 }
34  
35 BEGIN {
36 1 ▶ $INC{'PerlYamlReferenceParserParser.pm'} = __FILE__;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 1 $INC{'PerlYamlReferenceParserGrammar.pm'} = __FILE__;
38 1 $INC{'PerlYamlReferenceParserPrelude.pm'} = __FILE__;
39 };
40  
41 1;
42  
43 ### INCLUDE code from yaml-reference-parser/perl/lib/
44  
45 BEGIN {
46 1 ▶use v5.12;
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 package PerlYamlReferenceParserFunc;
49 use overload
50 0 ▶ eq => sub { 0 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
51 1 ▶ bool => sub { 1 };
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine __ANON__: not called CC=1 SCAR=0.2
52 sub new {
53 0 ▶ my ($class, $func, $name, $trace, $num) = @_;
Subroutine new: not called CC=2 SCAR=17.9
54 0 ▶ bless {
Condition0%0/3
$trace || $name
l!l&&r!l&&!r
000
MC/DC0%0/2
$trace || $name
$trace $name
Truth table0%0/3
A || B
A= $traceB= $name
ABresult
1X1
011
000
55 func => $func,
56 name => $name,
57 trace => $trace || $name,
58 num => $num,
59 receivers => undef,
60 }, $class;
61 }
62 0 ▶sub TO_JSON { $_[0]->{func} }
Subroutine TO_JSON: not called CC=1 SCAR=6.9
63  
64 package PerlYamlReferenceParserPrelude;
65  
66 1 ▶use boolean;
Subroutine BEGIN: called CC=1 SCAR=2.6
67 use Carp;
68 use Exporter 'import';
69 use JSON::PP;
70 use Time::HiRes qw< gettimeofday tv_interval >;
71 use YAML::PP::Perl;
72 use XXX;
73  
74 use constant DEBUG => $ENV{DEBUG};
75  
76 our @EXPORT;
77 sub export { push @EXPORT, @_ }
78  
79 export qw< true false >;
80  
81 export 'rule';
82 sub rule {
83 my ($num, $name, $func) = @_;
84 my ($pkg) = caller;
85 {
86 no strict 'refs';
87 *{"${pkg}::$name"} = $func;
88 }
89 $func = name($name, $func);
90 $func->{num} = $num;
91 return $func;
92 }
93  
94 export 'name';
95 sub name {
96 my ($name, $func, $trace) = (@_, '');
97 my $f = $func;
98 if (DEBUG) {
99 $f = sub {
100 my ($n, @args) = @_;
101 my $args = join ',', map stringify($_), @args;
102 debug("$name($args)");
103 goto $func;
104 }
105 }
106 return PerlYamlReferenceParserFunc->new($f, $name, $trace);
107 }
108  
109 export qw<isNull isBoolean isNumber isString isFunction isArray isObject>;
110 sub isNull { not defined $_[0] }
111 sub isBoolean { ref($_[0]) eq 'boolean' }
112 sub isNumber { not(ref $_[0]) and $_[0] =~ /^-?\d+$/ }
113 sub isString { not(ref $_[0]) and $_[0] !~ /^-?\d+$/ }
114 sub isFunction { ref($_[0]) eq 'PerlYamlReferenceParserFunc' }
115 sub isArray { ref($_[0]) eq 'ARRAY' }
116 sub isObject { ref($_[0]) eq 'HASH' }
117  
118 export 'typeof';
119 sub typeof {
120 my ($value) = @_;
121 return 'null' if isNull $value;
122 return 'boolean' if isBoolean $value;
123 return 'number' if isNumber $value;
124 return 'string' if isString $value;
125 return 'function' if isFunction $value;
126 return 'array' if isArray $value;
127 return 'object' if isObject $value;
128 XXX [$value, ref($value)];
129 }
130  
131 my $json = JSON::PP->new->canonical->allow_unknown->allow_nonref->convert_blessed;
132 sub json_stringify {
133 my $string;
134 eval {
135 $string = $json->encode($_[0]);
136 };
137 confess $@ if $@;
138 return $string;
139 }
140  
141 export 'stringify';
142 sub stringify;
143 sub stringify {
144 my ($o) = @_;
145 if ($o eq "\x{feff}") {
146 return "\\uFEFF";
147 }
148 if (isFunction $o) {
149 return "\@$o->{trace}";
150 }
151 if (isObject $o) {
152 return json_stringify [ sort keys %$o ];
153 }
154 if (isArray $o) {
155 return "[${\ join ',', map stringify($_), @$o}]";
156 }
157 if (isString $o) {
158 $_ = json_stringify $o;
159 s/^"(.*)"$/$1/;
160 return $_;
161 }
162 return json_stringify $o;
163 }
164  
165 export 'hex_char';
166 sub hex_char {
167 my ($chr) = @_;
168 return sprintf "x%x", ord $chr;
169 }
170  
171 export 'func';
172 sub func {
173 my ($self, $name) = @_;
174 my $func = $self->can($name) or
175 die "Can't find parser function '$name'";
176 PerlYamlReferenceParserFunc->new($func, $name);
177 }
178  
179 export 'file_read';
180 sub file_read {
181 do { local $/; <> };
182 }
183  
184 export 'debug';
185 sub debug {
186 my ($msg) = @_;
187 warn ">>> $msg\n";
188 }
189  
190 export 'debug_rule';
191 sub debug_rule {
192 my ($name, @args) = @_;
193 my $args = join ',', map stringify($_), @args;
194 debug "$name($args)";
195 }
196  
197 export qw< WWW XXX YYY ZZZ www xxx yyy zzz >;
198 *www = \&www;
199 *xxx = \&xxx;
200 *yyy = \&yyy;
201 *zzz = \&zzz;
202  
203 export 'dump';
204 sub dump {
205 YAML::PP::Perl->new->dump(@_);
206 }
207  
208 export 'FAIL';
209 sub FAIL {
210 WWW [@_];
211 confess "FAIL '${\ $_[0] // '???'}'";
212 }
213  
214 export 'timer';
215 sub timer {
216 if (@_) {
217 tv_interval(shift);
218 }
219 else {
220 [gettimeofday];
221 }
222 }
223  
224 1;
225  
226 # vim: sw=2:
227 }
228  
229  
230 ###
231 # This grammar class was generated from https://yaml.org/spec/1.2/spec.html
232 ###
233  
234 use v5.12;
235 package PerlYamlReferenceParserGrammar;
236 use PerlYamlReferenceParserPrelude;
237  
238 use constant DEBUG => $ENV{DEBUG};
239  
240 rule '000', TOP => sub {
241 my ($self) = @_;
242 $self->func('l_yaml_stream');
243 };
244  
245  
246 # [001]
247 # c-printable ::=
248 # x:9 | x:A | x:D | [x:20-x:7E]
249 # | x:85 | [x:A0-x:D7FF] | [x:E000-x:FFFD]
250 # | [x:10000-x:10FFFF]
251  
252 rule '001', c_printable => sub {
253 my ($self) = @_;
254 debug_rule("c_printable") if DEBUG;
255 $self->any(
256 $self->chr("\x{09}"),
257 $self->chr("\x{0A}"),
258 $self->chr("\x{0D}"),
259 $self->rng("\x{20}", "\x{7E}"),
260 $self->chr("\x{85}"),
261 $self->rng("\x{A0}", "\x{D7FF}"),
262 $self->rng("\x{E000}", "\x{FFFD}"),
263 $self->rng("\x{010000}", "\x{10FFFF}")
264 );
265 };
266  
267  
268  
269 # [002]
270 # nb-json ::=
271 # x:9 | [x:20-x:10FFFF]
272  
273 rule '002', nb_json => sub {
274 my ($self) = @_;
275 debug_rule("nb_json") if DEBUG;
276 $self->any(
277 $self->chr("\x{09}"),
278 $self->rng("\x{20}", "\x{10FFFF}")
279 );
280 };
281  
282  
283  
284 # [003]
285 # c-byte-order-mark ::=
286 # x:FEFF
287  
288 rule '003', c_byte_order_mark => sub {
289 my ($self) = @_;
290 debug_rule("c_byte_order_mark") if DEBUG;
291 $self->chr("\x{FEFF}");
292 };
293  
294  
295  
296 # [004]
297 # c-sequence-entry ::=
298 # '-'
299  
300 rule '004', c_sequence_entry => sub {
301 my ($self) = @_;
302 debug_rule("c_sequence_entry") if DEBUG;
303 $self->chr('-');
304 };
305  
306  
307  
308 # [005]
309 # c-mapping-key ::=
310 # '?'
311  
312 rule '005', c_mapping_key => sub {
313 my ($self) = @_;
314 debug_rule("c_mapping_key") if DEBUG;
315 $self->chr('?');
316 };
317  
318  
319  
320 # [006]
321 # c-mapping-value ::=
322 # ':'
323  
324 rule '006', c_mapping_value => sub {
325 my ($self) = @_;
326 debug_rule("c_mapping_value") if DEBUG;
327 $self->chr(':');
328 };
329  
330  
331  
332 # [007]
333 # c-collect-entry ::=
334 # ','
335  
336 rule '007', c_collect_entry => sub {
337 my ($self) = @_;
338 debug_rule("c_collect_entry") if DEBUG;
339 $self->chr(',');
340 };
341  
342  
343  
344 # [008]
345 # c-sequence-start ::=
346 # '['
347  
348 rule '008', c_sequence_start => sub {
349 my ($self) = @_;
350 debug_rule("c_sequence_start") if DEBUG;
351 $self->chr('[');
352 };
353  
354  
355  
356 # [009]
357 # c-sequence-end ::=
358 # ']'
359  
360 rule '009', c_sequence_end => sub {
361 my ($self) = @_;
362 debug_rule("c_sequence_end") if DEBUG;
363 $self->chr(']');
364 };
365  
366  
367  
368 # [010]
369 # c-mapping-start ::=
370 # '{'
371  
372 rule '010', c_mapping_start => sub {
373 my ($self) = @_;
374 debug_rule("c_mapping_start") if DEBUG;
375 $self->chr('{');
376 };
377  
378  
379  
380 # [011]
381 # c-mapping-end ::=
382 # '}'
383  
384 rule '011', c_mapping_end => sub {
385 my ($self) = @_;
386 debug_rule("c_mapping_end") if DEBUG;
387 $self->chr('}');
388 };
389  
390  
391  
392 # [012]
393 # c-comment ::=
394 # '#'
395  
396 rule '012', c_comment => sub {
397 my ($self) = @_;
398 debug_rule("c_comment") if DEBUG;
399 $self->chr('#');
400 };
401  
402  
403  
404 # [013]
405 # c-anchor ::=
406 # '&'
407  
408 rule '013', c_anchor => sub {
409 my ($self) = @_;
410 debug_rule("c_anchor") if DEBUG;
411 $self->chr('&');
412 };
413  
414  
415  
416 # [014]
417 # c-alias ::=
418 # '*'
419  
420 rule '014', c_alias => sub {
421 my ($self) = @_;
422 debug_rule("c_alias") if DEBUG;
423 $self->chr('*');
424 };
425  
426  
427  
428 # [015]
429 # c-tag ::=
430 # '!'
431  
432 rule '015', c_tag => sub {
433 my ($self) = @_;
434 debug_rule("c_tag") if DEBUG;
435 $self->chr('!');
436 };
437  
438  
439  
440 # [016]
441 # c-literal ::=
442 # '|'
443  
444 rule '016', c_literal => sub {
445 my ($self) = @_;
446 debug_rule("c_literal") if DEBUG;
447 $self->chr('|');
448 };
449  
450  
451  
452 # [017]
453 # c-folded ::=
454 # '>'
455  
456 rule '017', c_folded => sub {
457 my ($self) = @_;
458 debug_rule("c_folded") if DEBUG;
459 $self->chr('>');
460 };
461  
462  
463  
464 # [018]
465 # c-single-quote ::=
466 # '''
467  
468 rule '018', c_single_quote => sub {
469 my ($self) = @_;
470 debug_rule("c_single_quote") if DEBUG;
471 $self->chr("'");
472 };
473  
474  
475  
476 # [019]
477 # c-double-quote ::=
478 # '"'
479  
480 rule '019', c_double_quote => sub {
481 my ($self) = @_;
482 debug_rule("c_double_quote") if DEBUG;
483 $self->chr('"');
484 };
485  
486  
487  
488 # [020]
489 # c-directive ::=
490 # '%'
491  
492 rule '020', c_directive => sub {
493 my ($self) = @_;
494 debug_rule("c_directive") if DEBUG;
495 $self->chr('%');
496 };
497  
498  
499  
500 # [021]
501 # c-reserved ::=
502 # '@' | '`'
503  
504 rule '021', c_reserved => sub {
505 my ($self) = @_;
506 debug_rule("c_reserved") if DEBUG;
507 $self->any(
508 $self->chr('@'),
509 $self->chr('`')
510 );
511 };
512  
513  
514  
515 # [022]
516 # c-indicator ::=
517 # '-' | '?' | ':' | ',' | '[' | ']' | '{' | '}'
518 # | '#' | '&' | '*' | '!' | '|' | '>' | ''' | '"'
519 # | '%' | '@' | '`'
520  
521 rule '022', c_indicator => sub {
522 my ($self) = @_;
523 debug_rule("c_indicator") if DEBUG;
524 $self->any(
525 $self->chr('-'),
526 $self->chr('?'),
527 $self->chr(':'),
528 $self->chr(','),
529 $self->chr('['),
530 $self->chr(']'),
531 $self->chr('{'),
532 $self->chr('}'),
533 $self->chr('#'),
534 $self->chr('&'),
535 $self->chr('*'),
536 $self->chr('!'),
537 $self->chr('|'),
538 $self->chr('>'),
539 $self->chr("'"),
540 $self->chr('"'),
541 $self->chr('%'),
542 $self->chr('@'),
543 $self->chr('`')
544 );
545 };
546  
547  
548  
549 # [023]
550 # c-flow-indicator ::=
551 # ',' | '[' | ']' | '{' | '}'
552  
553 rule '023', c_flow_indicator => sub {
554 my ($self) = @_;
555 debug_rule("c_flow_indicator") if DEBUG;
556 $self->any(
557 $self->chr(','),
558 $self->chr('['),
559 $self->chr(']'),
560 $self->chr('{'),
561 $self->chr('}')
562 );
563 };
564  
565  
566  
567 # [024]
568 # b-line-feed ::=
569 # x:A
570  
571 rule '024', b_line_feed => sub {
572 my ($self) = @_;
573 debug_rule("b_line_feed") if DEBUG;
574 $self->chr("\x{0A}");
575 };
576  
577  
578  
579 # [025]
580 # b-carriage-return ::=
581 # x:D
582  
583 rule '025', b_carriage_return => sub {
584 my ($self) = @_;
585 debug_rule("b_carriage_return") if DEBUG;
586 $self->chr("\x{0D}");
587 };
588  
589  
590  
591 # [026]
592 # b-char ::=
593 # b-line-feed | b-carriage-return
594  
595 rule '026', b_char => sub {
596 my ($self) = @_;
597 debug_rule("b_char") if DEBUG;
598 $self->any(
599 $self->func('b_line_feed'),
600 $self->func('b_carriage_return')
601 );
602 };
603  
604  
605  
606 # [027]
607 # nb-char ::=
608 # c-printable - b-char - c-byte-order-mark
609  
610 rule '027', nb_char => sub {
611 my ($self) = @_;
612 debug_rule("nb_char") if DEBUG;
613 $self->but(
614 $self->func('c_printable'),
615 $self->func('b_char'),
616 $self->func('c_byte_order_mark')
617 );
618 };
619  
620  
621  
622 # [028]
623 # b-break ::=
624 # ( b-carriage-return b-line-feed )
625 # | b-carriage-return
626 # | b-line-feed
627  
628 rule '028', b_break => sub {
629 my ($self) = @_;
630 debug_rule("b_break") if DEBUG;
631 $self->any(
632 $self->all(
633 $self->func('b_carriage_return'),
634 $self->func('b_line_feed')
635 ),
636 $self->func('b_carriage_return'),
637 $self->func('b_line_feed')
638 );
639 };
640  
641  
642  
643 # [029]
644 # b-as-line-feed ::=
645 # b-break
646  
647 rule '029', b_as_line_feed => sub {
648 my ($self) = @_;
649 debug_rule("b_as_line_feed") if DEBUG;
650 $self->func('b_break');
651 };
652  
653  
654  
655 # [030]
656 # b-non-content ::=
657 # b-break
658  
659 rule '030', b_non_content => sub {
660 my ($self) = @_;
661 debug_rule("b_non_content") if DEBUG;
662 $self->func('b_break');
663 };
664  
665  
666  
667 # [031]
668 # s-space ::=
669 # x:20
670  
671 rule '031', s_space => sub {
672 my ($self) = @_;
673 debug_rule("s_space") if DEBUG;
674 $self->chr("\x{20}");
675 };
676  
677  
678  
679 # [032]
680 # s-tab ::=
681 # x:9
682  
683 rule '032', s_tab => sub {
684 my ($self) = @_;
685 debug_rule("s_tab") if DEBUG;
686 $self->chr("\x{09}");
687 };
688  
689  
690  
691 # [033]
692 # s-white ::=
693 # s-space | s-tab
694  
695 rule '033', s_white => sub {
696 my ($self) = @_;
697 debug_rule("s_white") if DEBUG;
698 $self->any(
699 $self->func('s_space'),
700 $self->func('s_tab')
701 );
702 };
703  
704  
705  
706 # [034]
707 # ns-char ::=
708 # nb-char - s-white
709  
710 rule '034', ns_char => sub {
711 my ($self) = @_;
712 debug_rule("ns_char") if DEBUG;
713 $self->but(
714 $self->func('nb_char'),
715 $self->func('s_white')
716 );
717 };
718  
719  
720  
721 # [035]
722 # ns-dec-digit ::=
723 # [x:30-x:39]
724  
725 rule '035', ns_dec_digit => sub {
726 my ($self) = @_;
727 debug_rule("ns_dec_digit") if DEBUG;
728 $self->rng("\x{30}", "\x{39}");
729 };
730  
731  
732  
733 # [036]
734 # ns-hex-digit ::=
735 # ns-dec-digit
736 # | [x:41-x:46] | [x:61-x:66]
737  
738 rule '036', ns_hex_digit => sub {
739 my ($self) = @_;
740 debug_rule("ns_hex_digit") if DEBUG;
741 $self->any(
742 $self->func('ns_dec_digit'),
743 $self->rng("\x{41}", "\x{46}"),
744 $self->rng("\x{61}", "\x{66}")
745 );
746 };
747  
748  
749  
750 # [037]
751 # ns-ascii-letter ::=
752 # [x:41-x:5A] | [x:61-x:7A]
753  
754 rule '037', ns_ascii_letter => sub {
755 my ($self) = @_;
756 debug_rule("ns_ascii_letter") if DEBUG;
757 $self->any(
758 $self->rng("\x{41}", "\x{5A}"),
759 $self->rng("\x{61}", "\x{7A}")
760 );
761 };
762  
763  
764  
765 # [038]
766 # ns-word-char ::=
767 # ns-dec-digit | ns-ascii-letter | '-'
768  
769 rule '038', ns_word_char => sub {
770 my ($self) = @_;
771 debug_rule("ns_word_char") if DEBUG;
772 $self->any(
773 $self->func('ns_dec_digit'),
774 $self->func('ns_ascii_letter'),
775 $self->chr('-')
776 );
777 };
778  
779  
780  
781 # [039]
782 # ns-uri-char ::=
783 # '%' ns-hex-digit ns-hex-digit | ns-word-char | '#'
784 # | ';' | '/' | '?' | ':' | '@' | '&' | '=' | '+' | '$' | ','
785 # | '_' | '.' | '!' | '~' | '*' | ''' | '(' | ')' | '[' | ']'
786  
787 rule '039', ns_uri_char => sub {
788 my ($self) = @_;
789 debug_rule("ns_uri_char") if DEBUG;
790 $self->any(
791 $self->all(
792 $self->chr('%'),
793 $self->func('ns_hex_digit'),
794 $self->func('ns_hex_digit')
795 ),
796 $self->func('ns_word_char'),
797 $self->chr('#'),
798 $self->chr(';'),
799 $self->chr('/'),
800 $self->chr('?'),
801 $self->chr(':'),
802 $self->chr('@'),
803 $self->chr('&'),
804 $self->chr('='),
805 $self->chr('+'),
806 $self->chr('$'),
807 $self->chr(','),
808 $self->chr('_'),
809 $self->chr('.'),
810 $self->chr('!'),
811 $self->chr('~'),
812 $self->chr('*'),
813 $self->chr("'"),
814 $self->chr('('),
815 $self->chr(')'),
816 $self->chr('['),
817 $self->chr(']')
818 );
819 };
820  
821  
822  
823 # [040]
824 # ns-tag-char ::=
825 # ns-uri-char - '!' - c-flow-indicator
826  
827 rule '040', ns_tag_char => sub {
828 my ($self) = @_;
829 debug_rule("ns_tag_char") if DEBUG;
830 $self->but(
831 $self->func('ns_uri_char'),
832 $self->chr('!'),
833 $self->func('c_flow_indicator')
834 );
835 };
836  
837  
838  
839 # [041]
840 # c-escape ::=
841 # '\'
842  
843 rule '041', c_escape => sub {
844 my ($self) = @_;
845 debug_rule("c_escape") if DEBUG;
846 $self->chr("\\");
847 };
848  
849  
850  
851 # [042]
852 # ns-esc-null ::=
853 # '0'
854  
855 rule '042', ns_esc_null => sub {
856 my ($self) = @_;
857 debug_rule("ns_esc_null") if DEBUG;
858 $self->chr('0');
859 };
860  
861  
862  
863 # [043]
864 # ns-esc-bell ::=
865 # 'a'
866  
867 rule '043', ns_esc_bell => sub {
868 my ($self) = @_;
869 debug_rule("ns_esc_bell") if DEBUG;
870 $self->chr('a');
871 };
872  
873  
874  
875 # [044]
876 # ns-esc-backspace ::=
877 # 'b'
878  
879 rule '044', ns_esc_backspace => sub {
880 my ($self) = @_;
881 debug_rule("ns_esc_backspace") if DEBUG;
882 $self->chr('b');
883 };
884  
885  
886  
887 # [045]
888 # ns-esc-horizontal-tab ::=
889 # 't' | x:9
890  
891 rule '045', ns_esc_horizontal_tab => sub {
892 my ($self) = @_;
893 debug_rule("ns_esc_horizontal_tab") if DEBUG;
894 $self->any(
895 $self->chr('t'),
896 $self->chr("\x{09}")
897 );
898 };
899  
900  
901  
902 # [046]
903 # ns-esc-line-feed ::=
904 # 'n'
905  
906 rule '046', ns_esc_line_feed => sub {
907 my ($self) = @_;
908 debug_rule("ns_esc_line_feed") if DEBUG;
909 $self->chr('n');
910 };
911  
912  
913  
914 # [047]
915 # ns-esc-vertical-tab ::=
916 # 'v'
917  
918 rule '047', ns_esc_vertical_tab => sub {
919 my ($self) = @_;
920 debug_rule("ns_esc_vertical_tab") if DEBUG;
921 $self->chr('v');
922 };
923  
924  
925  
926 # [048]
927 # ns-esc-form-feed ::=
928 # 'f'
929  
930 rule '048', ns_esc_form_feed => sub {
931 my ($self) = @_;
932 debug_rule("ns_esc_form_feed") if DEBUG;
933 $self->chr('f');
934 };
935  
936  
937  
938 # [049]
939 # ns-esc-carriage-return ::=
940 # 'r'
941  
942 rule '049', ns_esc_carriage_return => sub {
943 my ($self) = @_;
944 debug_rule("ns_esc_carriage_return") if DEBUG;
945 $self->chr('r');
946 };
947  
948  
949  
950 # [050]
951 # ns-esc-escape ::=
952 # 'e'
953  
954 rule '050', ns_esc_escape => sub {
955 my ($self) = @_;
956 debug_rule("ns_esc_escape") if DEBUG;
957 $self->chr('e');
958 };
959  
960  
961  
962 # [051]
963 # ns-esc-space ::=
964 # x:20
965  
966 rule '051', ns_esc_space => sub {
967 my ($self) = @_;
968 debug_rule("ns_esc_space") if DEBUG;
969 $self->chr("\x{20}");
970 };
971  
972  
973  
974 # [052]
975 # ns-esc-double-quote ::=
976 # '"'
977  
978 rule '052', ns_esc_double_quote => sub {
979 my ($self) = @_;
980 debug_rule("ns_esc_double_quote") if DEBUG;
981 $self->chr('"');
982 };
983  
984  
985  
986 # [053]
987 # ns-esc-slash ::=
988 # '/'
989  
990 rule '053', ns_esc_slash => sub {
991 my ($self) = @_;
992 debug_rule("ns_esc_slash") if DEBUG;
993 $self->chr('/');
994 };
995  
996  
997  
998 # [054]
999 # ns-esc-backslash ::=
1000 # '\'
1001  
1002 rule '054', ns_esc_backslash => sub {
1003 my ($self) = @_;
1004 debug_rule("ns_esc_backslash") if DEBUG;
1005 $self->chr("\\");
1006 };
1007  
1008  
1009  
1010 # [055]
1011 # ns-esc-next-line ::=
1012 # 'N'
1013  
1014 rule '055', ns_esc_next_line => sub {
1015 my ($self) = @_;
1016 debug_rule("ns_esc_next_line") if DEBUG;
1017 $self->chr('N');
1018 };
1019  
1020  
1021  
1022 # [056]
1023 # ns-esc-non-breaking-space ::=
1024 # '_'
1025  
1026 rule '056', ns_esc_non_breaking_space => sub {
1027 my ($self) = @_;
1028 debug_rule("ns_esc_non_breaking_space") if DEBUG;
1029 $self->chr('_');
1030 };
1031  
1032  
1033  
1034 # [057]
1035 # ns-esc-line-separator ::=
1036 # 'L'
1037  
1038 rule '057', ns_esc_line_separator => sub {
1039 my ($self) = @_;
1040 debug_rule("ns_esc_line_separator") if DEBUG;
1041 $self->chr('L');
1042 };
1043  
1044  
1045  
1046 # [058]
1047 # ns-esc-paragraph-separator ::=
1048 # 'P'
1049  
1050 rule '058', ns_esc_paragraph_separator => sub {
1051 my ($self) = @_;
1052 debug_rule("ns_esc_paragraph_separator") if DEBUG;
1053 $self->chr('P');
1054 };
1055  
1056  
1057  
1058 # [059]
1059 # ns-esc-8-bit ::=
1060 # 'x'
1061 # ( ns-hex-digit{2} )
1062  
1063 rule '059', ns_esc_8_bit => sub {
1064 my ($self) = @_;
1065 debug_rule("ns_esc_8_bit") if DEBUG;
1066 $self->all(
1067 $self->chr('x'),
1068 $self->rep($2, $2, $self->func('ns_hex_digit'))
1069 );
1070 };
1071  
1072  
1073  
1074 # [060]
1075 # ns-esc-16-bit ::=
1076 # 'u'
1077 # ( ns-hex-digit{4} )
1078  
1079 rule '060', ns_esc_16_bit => sub {
1080 my ($self) = @_;
1081 debug_rule("ns_esc_16_bit") if DEBUG;
1082 $self->all(
1083 $self->chr('u'),
1084 $self->rep($4, $4, $self->func('ns_hex_digit'))
1085 );
1086 };
1087  
1088  
1089  
1090 # [061]
1091 # ns-esc-32-bit ::=
1092 # 'U'
1093 # ( ns-hex-digit{8} )
1094  
1095 rule '061', ns_esc_32_bit => sub {
1096 my ($self) = @_;
1097 debug_rule("ns_esc_32_bit") if DEBUG;
1098 $self->all(
1099 $self->chr('U'),
1100 $self->rep($8, $8, $self->func('ns_hex_digit'))
1101 );
1102 };
1103  
1104  
1105  
1106 # [062]
1107 # c-ns-esc-char ::=
1108 # '\'
1109 # ( ns-esc-null | ns-esc-bell | ns-esc-backspace
1110 # | ns-esc-horizontal-tab | ns-esc-line-feed
1111 # | ns-esc-vertical-tab | ns-esc-form-feed
1112 # | ns-esc-carriage-return | ns-esc-escape | ns-esc-space
1113 # | ns-esc-double-quote | ns-esc-slash | ns-esc-backslash
1114 # | ns-esc-next-line | ns-esc-non-breaking-space
1115 # | ns-esc-line-separator | ns-esc-paragraph-separator
1116 # | ns-esc-8-bit | ns-esc-16-bit | ns-esc-32-bit )
1117  
1118 rule '062', c_ns_esc_char => sub {
1119 my ($self) = @_;
1120 debug_rule("c_ns_esc_char") if DEBUG;
1121 $self->all(
1122 $self->chr("\\"),
1123 $self->any(
1124 $self->func('ns_esc_null'),
1125 $self->func('ns_esc_bell'),
1126 $self->func('ns_esc_backspace'),
1127 $self->func('ns_esc_horizontal_tab'),
1128 $self->func('ns_esc_line_feed'),
1129 $self->func('ns_esc_vertical_tab'),
1130 $self->func('ns_esc_form_feed'),
1131 $self->func('ns_esc_carriage_return'),
1132 $self->func('ns_esc_escape'),
1133 $self->func('ns_esc_space'),
1134 $self->func('ns_esc_double_quote'),
1135 $self->func('ns_esc_slash'),
1136 $self->func('ns_esc_backslash'),
1137 $self->func('ns_esc_next_line'),
1138 $self->func('ns_esc_non_breaking_space'),
1139 $self->func('ns_esc_line_separator'),
1140 $self->func('ns_esc_paragraph_separator'),
1141 $self->func('ns_esc_8_bit'),
1142 $self->func('ns_esc_16_bit'),
1143 $self->func('ns_esc_32_bit')
1144 )
1145 );
1146 };
1147  
1148  
1149  
1150 # [063]
1151 # s-indent(n) ::=
1152 # s-space{n}
1153  
1154 rule '063', s_indent => sub {
1155 my ($self, $n) = @_;
1156 debug_rule("s_indent",$n) if DEBUG;
1157 $self->rep($n, $n, $self->func('s_space'));
1158 };
1159  
1160  
1161  
1162 # [064]
1163 # s-indent(<n) ::=
1164 # s-space{m} <where_m_<_n>
1165  
1166 rule '064', s_indent_lt => sub {
1167 my ($self, $n) = @_;
1168 debug_rule("s_indent_lt",$n) if DEBUG;
1169 $self->may(
1170 $self->all(
1171 $self->rep(0, undef, $self->func('s_space')),
1172 $self->lt($self->len($self->func('match')), $n)
1173 )
1174 );
1175 };
1176  
1177  
1178  
1179 # [065]
1180 # s-indent(<=n) ::=
1181 # s-space{m} <where_m_<=_n>
1182  
1183 rule '065', s_indent_le => sub {
1184 my ($self, $n) = @_;
1185 debug_rule("s_indent_le",$n) if DEBUG;
1186 $self->may(
1187 $self->all(
1188 $self->rep(0, undef, $self->func('s_space')),
1189 $self->le($self->len($self->func('match')), $n)
1190 )
1191 );
1192 };
1193  
1194  
1195  
1196 # [066]
1197 # s-separate-in-line ::=
1198 # s-white+ | <start_of_line>
1199  
1200 rule '066', s_separate_in_line => sub {
1201 my ($self) = @_;
1202 debug_rule("s_separate_in_line") if DEBUG;
1203 $self->any(
1204 $self->rep(1, undef, $self->func('s_white')),
1205 $self->func('start_of_line')
1206 );
1207 };
1208  
1209  
1210  
1211 # [067]
1212 # s-line-prefix(n,c) ::=
1213 # ( c = block-out => s-block-line-prefix(n) )
1214 # ( c = block-in => s-block-line-prefix(n) )
1215 # ( c = flow-out => s-flow-line-prefix(n) )
1216 # ( c = flow-in => s-flow-line-prefix(n) )
1217  
1218 rule '067', s_line_prefix => sub {
1219 my ($self, $n, $c) = @_;
1220 debug_rule("s_line_prefix",$n,$c) if DEBUG;
1221 $self->case(
1222 $c,
1223 {
1224 'block-in' => [ $self->func('s_block_line_prefix'), $n ],
1225 'block-out' => [ $self->func('s_block_line_prefix'), $n ],
1226 'flow-in' => [ $self->func('s_flow_line_prefix'), $n ],
1227 'flow-out' => [ $self->func('s_flow_line_prefix'), $n ],
1228 }
1229 );
1230 };
1231  
1232  
1233  
1234 # [068]
1235 # s-block-line-prefix(n) ::=
1236 # s-indent(n)
1237  
1238 rule '068', s_block_line_prefix => sub {
1239 my ($self, $n) = @_;
1240 debug_rule("s_block_line_prefix",$n) if DEBUG;
1241 [ $self->func('s_indent'), $n ];
1242 };
1243  
1244  
1245  
1246 # [069]
1247 # s-flow-line-prefix(n) ::=
1248 # s-indent(n)
1249 # s-separate-in-line?
1250  
1251 rule '069', s_flow_line_prefix => sub {
1252 my ($self, $n) = @_;
1253 debug_rule("s_flow_line_prefix",$n) if DEBUG;
1254 $self->all(
1255 [ $self->func('s_indent'), $n ],
1256 $self->rep(0, 1, $self->func('s_separate_in_line'))
1257 );
1258 };
1259  
1260  
1261  
1262 # [070]
1263 # l-empty(n,c) ::=
1264 # ( s-line-prefix(n,c) | s-indent(<n) )
1265 # b-as-line-feed
1266  
1267 rule '070', l_empty => sub {
1268 my ($self, $n, $c) = @_;
1269 debug_rule("l_empty",$n,$c) if DEBUG;
1270 $self->all(
1271 $self->any(
1272 [ $self->func('s_line_prefix'), $n, $c ],
1273 [ $self->func('s_indent_lt'), $n ]
1274 ),
1275 $self->func('b_as_line_feed')
1276 );
1277 };
1278  
1279  
1280  
1281 # [071]
1282 # b-l-trimmed(n,c) ::=
1283 # b-non-content l-empty(n,c)+
1284  
1285 rule '071', b_l_trimmed => sub {
1286 my ($self, $n, $c) = @_;
1287 debug_rule("b_l_trimmed",$n,$c) if DEBUG;
1288 $self->all(
1289 $self->func('b_non_content'),
1290 $self->rep(1, undef, [ $self->func('l_empty'), $n, $c ])
1291 );
1292 };
1293  
1294  
1295  
1296 # [072]
1297 # b-as-space ::=
1298 # b-break
1299  
1300 rule '072', b_as_space => sub {
1301 my ($self) = @_;
1302 debug_rule("b_as_space") if DEBUG;
1303 $self->func('b_break');
1304 };
1305  
1306  
1307  
1308 # [073]
1309 # b-l-folded(n,c) ::=
1310 # b-l-trimmed(n,c) | b-as-space
1311  
1312 rule '073', b_l_folded => sub {
1313 my ($self, $n, $c) = @_;
1314 debug_rule("b_l_folded",$n,$c) if DEBUG;
1315 $self->any(
1316 [ $self->func('b_l_trimmed'), $n, $c ],
1317 $self->func('b_as_space')
1318 );
1319 };
1320  
1321  
1322  
1323 # [074]
1324 # s-flow-folded(n) ::=
1325 # s-separate-in-line?
1326 # b-l-folded(n,flow-in)
1327 # s-flow-line-prefix(n)
1328  
1329 rule '074', s_flow_folded => sub {
1330 my ($self, $n) = @_;
1331 debug_rule("s_flow_folded",$n) if DEBUG;
1332 $self->all(
1333 $self->rep(0, 1, $self->func('s_separate_in_line')),
1334 [ $self->func('b_l_folded'), $n, "flow-in" ],
1335 [ $self->func('s_flow_line_prefix'), $n ]
1336 );
1337 };
1338  
1339  
1340  
1341 # [075]
1342 # c-nb-comment-text ::=
1343 # '#' nb-char*
1344  
1345 rule '075', c_nb_comment_text => sub {
1346 my ($self) = @_;
1347 debug_rule("c_nb_comment_text") if DEBUG;
1348 $self->all(
1349 $self->chr('#'),
1350 $self->rep(0, undef, $self->func('nb_char'))
1351 );
1352 };
1353  
1354  
1355  
1356 # [076]
1357 # b-comment ::=
1358 # b-non-content | <end_of_file>
1359  
1360 rule '076', b_comment => sub {
1361 my ($self) = @_;
1362 debug_rule("b_comment") if DEBUG;
1363 $self->any(
1364 $self->func('b_non_content'),
1365 $self->func('end_of_stream')
1366 );
1367 };
1368  
1369  
1370  
1371 # [077]
1372 # s-b-comment ::=
1373 # ( s-separate-in-line
1374 # c-nb-comment-text? )?
1375 # b-comment
1376  
1377 rule '077', s_b_comment => sub {
1378 my ($self) = @_;
1379 debug_rule("s_b_comment") if DEBUG;
1380 $self->all(
1381 $self->rep(0, 1,
1382 $self->all(
1383 $self->func('s_separate_in_line'),
1384 $self->rep(0, 1, $self->func('c_nb_comment_text'))
1385 )),
1386 $self->func('b_comment')
1387 );
1388 };
1389  
1390  
1391  
1392 # [078]
1393 # l-comment ::=
1394 # s-separate-in-line c-nb-comment-text?
1395 # b-comment
1396  
1397 rule '078', l_comment => sub {
1398 my ($self) = @_;
1399 debug_rule("l_comment") if DEBUG;
1400 $self->all(
1401 $self->func('s_separate_in_line'),
1402 $self->rep(0, 1, $self->func('c_nb_comment_text')),
1403 $self->func('b_comment')
1404 );
1405 };
1406  
1407  
1408  
1409 # [079]
1410 # s-l-comments ::=
1411 # ( s-b-comment | <start_of_line> )
1412 # l-comment*
1413  
1414 rule '079', s_l_comments => sub {
1415 my ($self) = @_;
1416 debug_rule("s_l_comments") if DEBUG;
1417 $self->all(
1418 $self->any(
1419 $self->func('s_b_comment'),
1420 $self->func('start_of_line')
1421 ),
1422 $self->rep(0, undef, $self->func('l_comment'))
1423 );
1424 };
1425  
1426  
1427  
1428 # [080]
1429 # s-separate(n,c) ::=
1430 # ( c = block-out => s-separate-lines(n) )
1431 # ( c = block-in => s-separate-lines(n) )
1432 # ( c = flow-out => s-separate-lines(n) )
1433 # ( c = flow-in => s-separate-lines(n) )
1434 # ( c = block-key => s-separate-in-line )
1435 # ( c = flow-key => s-separate-in-line )
1436  
1437 rule '080', s_separate => sub {
1438 my ($self, $n, $c) = @_;
1439 debug_rule("s_separate",$n,$c) if DEBUG;
1440 $self->case(
1441 $c,
1442 {
1443 'block-in' => [ $self->func('s_separate_lines'), $n ],
1444 'block-key' => $self->func('s_separate_in_line'),
1445 'block-out' => [ $self->func('s_separate_lines'), $n ],
1446 'flow-in' => [ $self->func('s_separate_lines'), $n ],
1447 'flow-key' => $self->func('s_separate_in_line'),
1448 'flow-out' => [ $self->func('s_separate_lines'), $n ],
1449 }
1450 );
1451 };
1452  
1453  
1454  
1455 # [081]
1456 # s-separate-lines(n) ::=
1457 # ( s-l-comments
1458 # s-flow-line-prefix(n) )
1459 # | s-separate-in-line
1460  
1461 rule '081', s_separate_lines => sub {
1462 my ($self, $n) = @_;
1463 debug_rule("s_separate_lines",$n) if DEBUG;
1464 $self->any(
1465 $self->all(
1466 $self->func('s_l_comments'),
1467 [ $self->func('s_flow_line_prefix'), $n ]
1468 ),
1469 $self->func('s_separate_in_line')
1470 );
1471 };
1472  
1473  
1474  
1475 # [082]
1476 # l-directive ::=
1477 # '%'
1478 # ( ns-yaml-directive
1479 # | ns-tag-directive
1480 # | ns-reserved-directive )
1481 # s-l-comments
1482  
1483 rule '082', l_directive => sub {
1484 my ($self) = @_;
1485 debug_rule("l_directive") if DEBUG;
1486 $self->all(
1487 $self->chr('%'),
1488 $self->any(
1489 $self->func('ns_yaml_directive'),
1490 $self->func('ns_tag_directive'),
1491 $self->func('ns_reserved_directive')
1492 ),
1493 $self->func('s_l_comments')
1494 );
1495 };
1496  
1497  
1498  
1499 # [083]
1500 # ns-reserved-directive ::=
1501 # ns-directive-name
1502 # ( s-separate-in-line ns-directive-parameter )*
1503  
1504 rule '083', ns_reserved_directive => sub {
1505 my ($self) = @_;
1506 debug_rule("ns_reserved_directive") if DEBUG;
1507 $self->all(
1508 $self->func('ns_directive_name'),
1509 $self->rep(0, undef,
1510 $self->all(
1511 $self->func('s_separate_in_line'),
1512 $self->func('ns_directive_parameter')
1513 ))
1514 );
1515 };
1516  
1517  
1518  
1519 # [084]
1520 # ns-directive-name ::=
1521 # ns-char+
1522  
1523 rule '084', ns_directive_name => sub {
1524 my ($self) = @_;
1525 debug_rule("ns_directive_name") if DEBUG;
1526 $self->rep(1, undef, $self->func('ns_char'));
1527 };
1528  
1529  
1530  
1531 # [085]
1532 # ns-directive-parameter ::=
1533 # ns-char+
1534  
1535 rule '085', ns_directive_parameter => sub {
1536 my ($self) = @_;
1537 debug_rule("ns_directive_parameter") if DEBUG;
1538 $self->rep(1, undef, $self->func('ns_char'));
1539 };
1540  
1541  
1542  
1543 # [086]
1544 # ns-yaml-directive ::=
1545 # 'Y' 'A' 'M' 'L'
1546 # s-separate-in-line ns-yaml-version
1547  
1548 rule '086', ns_yaml_directive => sub {
1549 my ($self) = @_;
1550 debug_rule("ns_yaml_directive") if DEBUG;
1551 $self->all(
1552 $self->chr('Y'),
1553 $self->chr('A'),
1554 $self->chr('M'),
1555 $self->chr('L'),
1556 $self->func('s_separate_in_line'),
1557 $self->func('ns_yaml_version')
1558 );
1559 };
1560  
1561  
1562  
1563 # [087]
1564 # ns-yaml-version ::=
1565 # ns-dec-digit+ '.' ns-dec-digit+
1566  
1567 rule '087', ns_yaml_version => sub {
1568 my ($self) = @_;
1569 debug_rule("ns_yaml_version") if DEBUG;
1570 $self->all(
1571 $self->rep(1, undef, $self->func('ns_dec_digit')),
1572 $self->chr('.'),
1573 $self->rep2(1, undef, $self->func('ns_dec_digit'))
1574 );
1575 };
1576  
1577  
1578  
1579 # [088]
1580 # ns-tag-directive ::=
1581 # 'T' 'A' 'G'
1582 # s-separate-in-line c-tag-handle
1583 # s-separate-in-line ns-tag-prefix
1584  
1585 rule '088', ns_tag_directive => sub {
1586 my ($self) = @_;
1587 debug_rule("ns_tag_directive") if DEBUG;
1588 $self->all(
1589 $self->chr('T'),
1590 $self->chr('A'),
1591 $self->chr('G'),
1592 $self->func('s_separate_in_line'),
1593 $self->func('c_tag_handle'),
1594 $self->func('s_separate_in_line'),
1595 $self->func('ns_tag_prefix')
1596 );
1597 };
1598  
1599  
1600  
1601 # [089]
1602 # c-tag-handle ::=
1603 # c-named-tag-handle
1604 # | c-secondary-tag-handle
1605 # | c-primary-tag-handle
1606  
1607 rule '089', c_tag_handle => sub {
1608 my ($self) = @_;
1609 debug_rule("c_tag_handle") if DEBUG;
1610 $self->any(
1611 $self->func('c_named_tag_handle'),
1612 $self->func('c_secondary_tag_handle'),
1613 $self->func('c_primary_tag_handle')
1614 );
1615 };
1616  
1617  
1618  
1619 # [090]
1620 # c-primary-tag-handle ::=
1621 # '!'
1622  
1623 rule '090', c_primary_tag_handle => sub {
1624 my ($self) = @_;
1625 debug_rule("c_primary_tag_handle") if DEBUG;
1626 $self->chr('!');
1627 };
1628  
1629  
1630  
1631 # [091]
1632 # c-secondary-tag-handle ::=
1633 # '!' '!'
1634  
1635 rule '091', c_secondary_tag_handle => sub {
1636 my ($self) = @_;
1637 debug_rule("c_secondary_tag_handle") if DEBUG;
1638 $self->all(
1639 $self->chr('!'),
1640 $self->chr('!')
1641 );
1642 };
1643  
1644  
1645  
1646 # [092]
1647 # c-named-tag-handle ::=
1648 # '!' ns-word-char+ '!'
1649  
1650 rule '092', c_named_tag_handle => sub {
1651 my ($self) = @_;
1652 debug_rule("c_named_tag_handle") if DEBUG;
1653 $self->all(
1654 $self->chr('!'),
1655 $self->rep(1, undef, $self->func('ns_word_char')),
1656 $self->chr('!')
1657 );
1658 };
1659  
1660  
1661  
1662 # [093]
1663 # ns-tag-prefix ::=
1664 # c-ns-local-tag-prefix | ns-global-tag-prefix
1665  
1666 rule '093', ns_tag_prefix => sub {
1667 my ($self) = @_;
1668 debug_rule("ns_tag_prefix") if DEBUG;
1669 $self->any(
1670 $self->func('c_ns_local_tag_prefix'),
1671 $self->func('ns_global_tag_prefix')
1672 );
1673 };
1674  
1675  
1676  
1677 # [094]
1678 # c-ns-local-tag-prefix ::=
1679 # '!' ns-uri-char*
1680  
1681 rule '094', c_ns_local_tag_prefix => sub {
1682 my ($self) = @_;
1683 debug_rule("c_ns_local_tag_prefix") if DEBUG;
1684 $self->all(
1685 $self->chr('!'),
1686 $self->rep(0, undef, $self->func('ns_uri_char'))
1687 );
1688 };
1689  
1690  
1691  
1692 # [095]
1693 # ns-global-tag-prefix ::=
1694 # ns-tag-char ns-uri-char*
1695  
1696 rule '095', ns_global_tag_prefix => sub {
1697 my ($self) = @_;
1698 debug_rule("ns_global_tag_prefix") if DEBUG;
1699 $self->all(
1700 $self->func('ns_tag_char'),
1701 $self->rep(0, undef, $self->func('ns_uri_char'))
1702 );
1703 };
1704  
1705  
1706  
1707 # [096]
1708 # c-ns-properties(n,c) ::=
1709 # ( c-ns-tag-property
1710 # ( s-separate(n,c) c-ns-anchor-property )? )
1711 # | ( c-ns-anchor-property
1712 # ( s-separate(n,c) c-ns-tag-property )? )
1713  
1714 rule '096', c_ns_properties => sub {
1715 my ($self, $n, $c) = @_;
1716 debug_rule("c_ns_properties",$n,$c) if DEBUG;
1717 $self->any(
1718 $self->all(
1719 $self->func('c_ns_tag_property'),
1720 $self->rep(0, 1,
1721 $self->all(
1722 [ $self->func('s_separate'), $n, $c ],
1723 $self->func('c_ns_anchor_property')
1724 ))
1725 ),
1726 $self->all(
1727 $self->func('c_ns_anchor_property'),
1728 $self->rep(0, 1,
1729 $self->all(
1730 [ $self->func('s_separate'), $n, $c ],
1731 $self->func('c_ns_tag_property')
1732 ))
1733 )
1734 );
1735 };
1736  
1737  
1738  
1739 # [097]
1740 # c-ns-tag-property ::=
1741 # c-verbatim-tag
1742 # | c-ns-shorthand-tag
1743 # | c-non-specific-tag
1744  
1745 rule '097', c_ns_tag_property => sub {
1746 my ($self) = @_;
1747 debug_rule("c_ns_tag_property") if DEBUG;
1748 $self->any(
1749 $self->func('c_verbatim_tag'),
1750 $self->func('c_ns_shorthand_tag'),
1751 $self->func('c_non_specific_tag')
1752 );
1753 };
1754  
1755  
1756  
1757 # [098]
1758 # c-verbatim-tag ::=
1759 # '!' '<' ns-uri-char+ '>'
1760  
1761 rule '098', c_verbatim_tag => sub {
1762 my ($self) = @_;
1763 debug_rule("c_verbatim_tag") if DEBUG;
1764 $self->all(
1765 $self->chr('!'),
1766 $self->chr('<'),
1767 $self->rep(1, undef, $self->func('ns_uri_char')),
1768 $self->chr('>')
1769 );
1770 };
1771  
1772  
1773  
1774 # [099]
1775 # c-ns-shorthand-tag ::=
1776 # c-tag-handle ns-tag-char+
1777  
1778 rule '099', c_ns_shorthand_tag => sub {
1779 my ($self) = @_;
1780 debug_rule("c_ns_shorthand_tag") if DEBUG;
1781 $self->all(
1782 $self->func('c_tag_handle'),
1783 $self->rep(1, undef, $self->func('ns_tag_char'))
1784 );
1785 };
1786  
1787  
1788  
1789 # [100]
1790 # c-non-specific-tag ::=
1791 # '!'
1792  
1793 rule '100', c_non_specific_tag => sub {
1794 my ($self) = @_;
1795 debug_rule("c_non_specific_tag") if DEBUG;
1796 $self->chr('!');
1797 };
1798  
1799  
1800  
1801 # [101]
1802 # c-ns-anchor-property ::=
1803 # '&' ns-anchor-name
1804  
1805 rule '101', c_ns_anchor_property => sub {
1806 my ($self) = @_;
1807 debug_rule("c_ns_anchor_property") if DEBUG;
1808 $self->all(
1809 $self->chr('&'),
1810 $self->func('ns_anchor_name')
1811 );
1812 };
1813  
1814  
1815  
1816 # [102]
1817 # ns-anchor-char ::=
1818 # ns-char - c-flow-indicator
1819  
1820 rule '102', ns_anchor_char => sub {
1821 my ($self) = @_;
1822 debug_rule("ns_anchor_char") if DEBUG;
1823 $self->but(
1824 $self->func('ns_char'),
1825 $self->func('c_flow_indicator')
1826 );
1827 };
1828  
1829  
1830  
1831 # [103]
1832 # ns-anchor-name ::=
1833 # ns-anchor-char+
1834  
1835 rule '103', ns_anchor_name => sub {
1836 my ($self) = @_;
1837 debug_rule("ns_anchor_name") if DEBUG;
1838 $self->rep(1, undef, $self->func('ns_anchor_char'));
1839 };
1840  
1841  
1842  
1843 # [104]
1844 # c-ns-alias-node ::=
1845 # '*' ns-anchor-name
1846  
1847 rule '104', c_ns_alias_node => sub {
1848 my ($self) = @_;
1849 debug_rule("c_ns_alias_node") if DEBUG;
1850 $self->all(
1851 $self->chr('*'),
1852 $self->func('ns_anchor_name')
1853 );
1854 };
1855  
1856  
1857  
1858 # [105]
1859 # e-scalar ::=
1860 # <empty>
1861  
1862 rule '105', e_scalar => sub {
1863 my ($self) = @_;
1864 debug_rule("e_scalar") if DEBUG;
1865 $self->func('empty');
1866 };
1867  
1868  
1869  
1870 # [106]
1871 # e-node ::=
1872 # e-scalar
1873  
1874 rule '106', e_node => sub {
1875 my ($self) = @_;
1876 debug_rule("e_node") if DEBUG;
1877 $self->func('e_scalar');
1878 };
1879  
1880  
1881  
1882 # [107]
1883 # nb-double-char ::=
1884 # c-ns-esc-char | ( nb-json - '\' - '"' )
1885  
1886 rule '107', nb_double_char => sub {
1887 my ($self) = @_;
1888 debug_rule("nb_double_char") if DEBUG;
1889 $self->any(
1890 $self->func('c_ns_esc_char'),
1891 $self->but(
1892 $self->func('nb_json'),
1893 $self->chr("\\"),
1894 $self->chr('"')
1895 )
1896 );
1897 };
1898  
1899  
1900  
1901 # [108]
1902 # ns-double-char ::=
1903 # nb-double-char - s-white
1904  
1905 rule '108', ns_double_char => sub {
1906 my ($self) = @_;
1907 debug_rule("ns_double_char") if DEBUG;
1908 $self->but(
1909 $self->func('nb_double_char'),
1910 $self->func('s_white')
1911 );
1912 };
1913  
1914  
1915  
1916 # [109]
1917 # c-double-quoted(n,c) ::=
1918 # '"' nb-double-text(n,c)
1919 # '"'
1920  
1921 rule '109', c_double_quoted => sub {
1922 my ($self, $n, $c) = @_;
1923 debug_rule("c_double_quoted",$n,$c) if DEBUG;
1924 $self->all(
1925 $self->chr('"'),
1926 [ $self->func('nb_double_text'), $n, $c ],
1927 $self->chr('"')
1928 );
1929 };
1930  
1931  
1932  
1933 # [110]
1934 # nb-double-text(n,c) ::=
1935 # ( c = flow-out => nb-double-multi-line(n) )
1936 # ( c = flow-in => nb-double-multi-line(n) )
1937 # ( c = block-key => nb-double-one-line )
1938 # ( c = flow-key => nb-double-one-line )
1939  
1940 rule '110', nb_double_text => sub {
1941 my ($self, $n, $c) = @_;
1942 debug_rule("nb_double_text",$n,$c) if DEBUG;
1943 $self->case(
1944 $c,
1945 {
1946 'block-key' => $self->func('nb_double_one_line'),
1947 'flow-in' => [ $self->func('nb_double_multi_line'), $n ],
1948 'flow-key' => $self->func('nb_double_one_line'),
1949 'flow-out' => [ $self->func('nb_double_multi_line'), $n ],
1950 }
1951 );
1952 };
1953  
1954  
1955  
1956 # [111]
1957 # nb-double-one-line ::=
1958 # nb-double-char*
1959  
1960 rule '111', nb_double_one_line => sub {
1961 my ($self) = @_;
1962 debug_rule("nb_double_one_line") if DEBUG;
1963 $self->rep(0, undef, $self->func('nb_double_char'));
1964 };
1965  
1966  
1967  
1968 # [112]
1969 # s-double-escaped(n) ::=
1970 # s-white* '\'
1971 # b-non-content
1972 # l-empty(n,flow-in)* s-flow-line-prefix(n)
1973  
1974 rule '112', s_double_escaped => sub {
1975 my ($self, $n) = @_;
1976 debug_rule("s_double_escaped",$n) if DEBUG;
1977 $self->all(
1978 $self->rep(0, undef, $self->func('s_white')),
1979 $self->chr("\\"),
1980 $self->func('b_non_content'),
1981 $self->rep2(0, undef, [ $self->func('l_empty'), $n, "flow-in" ]),
1982 [ $self->func('s_flow_line_prefix'), $n ]
1983 );
1984 };
1985  
1986  
1987  
1988 # [113]
1989 # s-double-break(n) ::=
1990 # s-double-escaped(n) | s-flow-folded(n)
1991  
1992 rule '113', s_double_break => sub {
1993 my ($self, $n) = @_;
1994 debug_rule("s_double_break",$n) if DEBUG;
1995 $self->any(
1996 [ $self->func('s_double_escaped'), $n ],
1997 [ $self->func('s_flow_folded'), $n ]
1998 );
1999 };
2000  
2001  
2002  
2003 # [114]
2004 # nb-ns-double-in-line ::=
2005 # ( s-white* ns-double-char )*
2006  
2007 rule '114', nb_ns_double_in_line => sub {
2008 my ($self) = @_;
2009 debug_rule("nb_ns_double_in_line") if DEBUG;
2010 $self->rep(0, undef,
2011 $self->all(
2012 $self->rep(0, undef, $self->func('s_white')),
2013 $self->func('ns_double_char')
2014 ));
2015 };
2016  
2017  
2018  
2019 # [115]
2020 # s-double-next-line(n) ::=
2021 # s-double-break(n)
2022 # ( ns-double-char nb-ns-double-in-line
2023 # ( s-double-next-line(n) | s-white* ) )?
2024  
2025 rule '115', s_double_next_line => sub {
2026 my ($self, $n) = @_;
2027 debug_rule("s_double_next_line",$n) if DEBUG;
2028 $self->all(
2029 [ $self->func('s_double_break'), $n ],
2030 $self->rep(0, 1,
2031 $self->all(
2032 $self->func('ns_double_char'),
2033 $self->func('nb_ns_double_in_line'),
2034 $self->any(
2035 [ $self->func('s_double_next_line'), $n ],
2036 $self->rep(0, undef, $self->func('s_white'))
2037 )
2038 ))
2039 );
2040 };
2041  
2042  
2043  
2044 # [116]
2045 # nb-double-multi-line(n) ::=
2046 # nb-ns-double-in-line
2047 # ( s-double-next-line(n) | s-white* )
2048  
2049 rule '116', nb_double_multi_line => sub {
2050 my ($self, $n) = @_;
2051 debug_rule("nb_double_multi_line",$n) if DEBUG;
2052 $self->all(
2053 $self->func('nb_ns_double_in_line'),
2054 $self->any(
2055 [ $self->func('s_double_next_line'), $n ],
2056 $self->rep(0, undef, $self->func('s_white'))
2057 )
2058 );
2059 };
2060  
2061  
2062  
2063 # [117]
2064 # c-quoted-quote ::=
2065 # ''' '''
2066  
2067 rule '117', c_quoted_quote => sub {
2068 my ($self) = @_;
2069 debug_rule("c_quoted_quote") if DEBUG;
2070 $self->all(
2071 $self->chr("'"),
2072 $self->chr("'")
2073 );
2074 };
2075  
2076  
2077  
2078 # [118]
2079 # nb-single-char ::=
2080 # c-quoted-quote | ( nb-json - ''' )
2081  
2082 rule '118', nb_single_char => sub {
2083 my ($self) = @_;
2084 debug_rule("nb_single_char") if DEBUG;
2085 $self->any(
2086 $self->func('c_quoted_quote'),
2087 $self->but(
2088 $self->func('nb_json'),
2089 $self->chr("'")
2090 )
2091 );
2092 };
2093  
2094  
2095  
2096 # [119]
2097 # ns-single-char ::=
2098 # nb-single-char - s-white
2099  
2100 rule '119', ns_single_char => sub {
2101 my ($self) = @_;
2102 debug_rule("ns_single_char") if DEBUG;
2103 $self->but(
2104 $self->func('nb_single_char'),
2105 $self->func('s_white')
2106 );
2107 };
2108  
2109  
2110  
2111 # [120]
2112 # c-single-quoted(n,c) ::=
2113 # ''' nb-single-text(n,c)
2114 # '''
2115  
2116 rule '120', c_single_quoted => sub {
2117 my ($self, $n, $c) = @_;
2118 debug_rule("c_single_quoted",$n,$c) if DEBUG;
2119 $self->all(
2120 $self->chr("'"),
2121 [ $self->func('nb_single_text'), $n, $c ],
2122 $self->chr("'")
2123 );
2124 };
2125  
2126  
2127  
2128 # [121]
2129 # nb-single-text(n,c) ::=
2130 # ( c = flow-out => nb-single-multi-line(n) )
2131 # ( c = flow-in => nb-single-multi-line(n) )
2132 # ( c = block-key => nb-single-one-line )
2133 # ( c = flow-key => nb-single-one-line )
2134  
2135 rule '121', nb_single_text => sub {
2136 my ($self, $n, $c) = @_;
2137 debug_rule("nb_single_text",$n,$c) if DEBUG;
2138 $self->case(
2139 $c,
2140 {
2141 'block-key' => $self->func('nb_single_one_line'),
2142 'flow-in' => [ $self->func('nb_single_multi_line'), $n ],
2143 'flow-key' => $self->func('nb_single_one_line'),
2144 'flow-out' => [ $self->func('nb_single_multi_line'), $n ],
2145 }
2146 );
2147 };
2148  
2149  
2150  
2151 # [122]
2152 # nb-single-one-line ::=
2153 # nb-single-char*
2154  
2155 rule '122', nb_single_one_line => sub {
2156 my ($self) = @_;
2157 debug_rule("nb_single_one_line") if DEBUG;
2158 $self->rep(0, undef, $self->func('nb_single_char'));
2159 };
2160  
2161  
2162  
2163 # [123]
2164 # nb-ns-single-in-line ::=
2165 # ( s-white* ns-single-char )*
2166  
2167 rule '123', nb_ns_single_in_line => sub {
2168 my ($self) = @_;
2169 debug_rule("nb_ns_single_in_line") if DEBUG;
2170 $self->rep(0, undef,
2171 $self->all(
2172 $self->rep(0, undef, $self->func('s_white')),
2173 $self->func('ns_single_char')
2174 ));
2175 };
2176  
2177  
2178  
2179 # [124]
2180 # s-single-next-line(n) ::=
2181 # s-flow-folded(n)
2182 # ( ns-single-char nb-ns-single-in-line
2183 # ( s-single-next-line(n) | s-white* ) )?
2184  
2185 rule '124', s_single_next_line => sub {
2186 my ($self, $n) = @_;
2187 debug_rule("s_single_next_line",$n) if DEBUG;
2188 $self->all(
2189 [ $self->func('s_flow_folded'), $n ],
2190 $self->rep(0, 1,
2191 $self->all(
2192 $self->func('ns_single_char'),
2193 $self->func('nb_ns_single_in_line'),
2194 $self->any(
2195 [ $self->func('s_single_next_line'), $n ],
2196 $self->rep(0, undef, $self->func('s_white'))
2197 )
2198 ))
2199 );
2200 };
2201  
2202  
2203  
2204 # [125]
2205 # nb-single-multi-line(n) ::=
2206 # nb-ns-single-in-line
2207 # ( s-single-next-line(n) | s-white* )
2208  
2209 rule '125', nb_single_multi_line => sub {
2210 my ($self, $n) = @_;
2211 debug_rule("nb_single_multi_line",$n) if DEBUG;
2212 $self->all(
2213 $self->func('nb_ns_single_in_line'),
2214 $self->any(
2215 [ $self->func('s_single_next_line'), $n ],
2216 $self->rep(0, undef, $self->func('s_white'))
2217 )
2218 );
2219 };
2220  
2221  
2222  
2223 # [126]
2224 # ns-plain-first(c) ::=
2225 # ( ns-char - c-indicator )
2226 # | ( ( '?' | ':' | '-' )
2227 # <followed_by_an_ns-plain-safe(c)> )
2228  
2229 rule '126', ns_plain_first => sub {
2230 my ($self, $c) = @_;
2231 debug_rule("ns_plain_first",$c) if DEBUG;
2232 $self->any(
2233 $self->but(
2234 $self->func('ns_char'),
2235 $self->func('c_indicator')
2236 ),
2237 $self->all(
2238 $self->any(
2239 $self->chr('?'),
2240 $self->chr(':'),
2241 $self->chr('-')
2242 ),
2243 $self->chk('=', [ $self->func('ns_plain_safe'), $c ])
2244 )
2245 );
2246 };
2247  
2248  
2249  
2250 # [127]
2251 # ns-plain-safe(c) ::=
2252 # ( c = flow-out => ns-plain-safe-out )
2253 # ( c = flow-in => ns-plain-safe-in )
2254 # ( c = block-key => ns-plain-safe-out )
2255 # ( c = flow-key => ns-plain-safe-in )
2256  
2257 rule '127', ns_plain_safe => sub {
2258 my ($self, $c) = @_;
2259 debug_rule("ns_plain_safe",$c) if DEBUG;
2260 $self->case(
2261 $c,
2262 {
2263 'block-key' => $self->func('ns_plain_safe_out'),
2264 'flow-in' => $self->func('ns_plain_safe_in'),
2265 'flow-key' => $self->func('ns_plain_safe_in'),
2266 'flow-out' => $self->func('ns_plain_safe_out'),
2267 }
2268 );
2269 };
2270  
2271  
2272  
2273 # [128]
2274 # ns-plain-safe-out ::=
2275 # ns-char
2276  
2277 rule '128', ns_plain_safe_out => sub {
2278 my ($self) = @_;
2279 debug_rule("ns_plain_safe_out") if DEBUG;
2280 $self->func('ns_char');
2281 };
2282  
2283  
2284  
2285 # [129]
2286 # ns-plain-safe-in ::=
2287 # ns-char - c-flow-indicator
2288  
2289 rule '129', ns_plain_safe_in => sub {
2290 my ($self) = @_;
2291 debug_rule("ns_plain_safe_in") if DEBUG;
2292 $self->but(
2293 $self->func('ns_char'),
2294 $self->func('c_flow_indicator')
2295 );
2296 };
2297  
2298  
2299  
2300 # [130]
2301 # ns-plain-char(c) ::=
2302 # ( ns-plain-safe(c) - ':' - '#' )
2303 # | ( <an_ns-char_preceding> '#' )
2304 # | ( ':' <followed_by_an_ns-plain-safe(c)> )
2305  
2306 rule '130', ns_plain_char => sub {
2307 my ($self, $c) = @_;
2308 debug_rule("ns_plain_char",$c) if DEBUG;
2309 $self->any(
2310 $self->but(
2311 [ $self->func('ns_plain_safe'), $c ],
2312 $self->chr(':'),
2313 $self->chr('#')
2314 ),
2315 $self->all(
2316 $self->chk('<=', $self->func('ns_char')),
2317 $self->chr('#')
2318 ),
2319 $self->all(
2320 $self->chr(':'),
2321 $self->chk('=', [ $self->func('ns_plain_safe'), $c ])
2322 )
2323 );
2324 };
2325  
2326  
2327  
2328 # [131]
2329 # ns-plain(n,c) ::=
2330 # ( c = flow-out => ns-plain-multi-line(n,c) )
2331 # ( c = flow-in => ns-plain-multi-line(n,c) )
2332 # ( c = block-key => ns-plain-one-line(c) )
2333 # ( c = flow-key => ns-plain-one-line(c) )
2334  
2335 rule '131', ns_plain => sub {
2336 my ($self, $n, $c) = @_;
2337 debug_rule("ns_plain",$n,$c) if DEBUG;
2338 $self->case(
2339 $c,
2340 {
2341 'block-key' => [ $self->func('ns_plain_one_line'), $c ],
2342 'flow-in' => [ $self->func('ns_plain_multi_line'), $n, $c ],
2343 'flow-key' => [ $self->func('ns_plain_one_line'), $c ],
2344 'flow-out' => [ $self->func('ns_plain_multi_line'), $n, $c ],
2345 }
2346 );
2347 };
2348  
2349  
2350  
2351 # [132]
2352 # nb-ns-plain-in-line(c) ::=
2353 # ( s-white*
2354 # ns-plain-char(c) )*
2355  
2356 rule '132', nb_ns_plain_in_line => sub {
2357 my ($self, $c) = @_;
2358 debug_rule("nb_ns_plain_in_line",$c) if DEBUG;
2359 $self->rep(0, undef,
2360 $self->all(
2361 $self->rep(0, undef, $self->func('s_white')),
2362 [ $self->func('ns_plain_char'), $c ]
2363 ));
2364 };
2365  
2366  
2367  
2368 # [133]
2369 # ns-plain-one-line(c) ::=
2370 # ns-plain-first(c)
2371 # nb-ns-plain-in-line(c)
2372  
2373 rule '133', ns_plain_one_line => sub {
2374 my ($self, $c) = @_;
2375 debug_rule("ns_plain_one_line",$c) if DEBUG;
2376 $self->all(
2377 [ $self->func('ns_plain_first'), $c ],
2378 [ $self->func('nb_ns_plain_in_line'), $c ]
2379 );
2380 };
2381  
2382  
2383  
2384 # [134]
2385 # s-ns-plain-next-line(n,c) ::=
2386 # s-flow-folded(n)
2387 # ns-plain-char(c) nb-ns-plain-in-line(c)
2388  
2389 rule '134', s_ns_plain_next_line => sub {
2390 my ($self, $n, $c) = @_;
2391 debug_rule("s_ns_plain_next_line",$n,$c) if DEBUG;
2392 $self->all(
2393 [ $self->func('s_flow_folded'), $n ],
2394 [ $self->func('ns_plain_char'), $c ],
2395 [ $self->func('nb_ns_plain_in_line'), $c ]
2396 );
2397 };
2398  
2399  
2400  
2401 # [135]
2402 # ns-plain-multi-line(n,c) ::=
2403 # ns-plain-one-line(c)
2404 # s-ns-plain-next-line(n,c)*
2405  
2406 rule '135', ns_plain_multi_line => sub {
2407 my ($self, $n, $c) = @_;
2408 debug_rule("ns_plain_multi_line",$n,$c) if DEBUG;
2409 $self->all(
2410 [ $self->func('ns_plain_one_line'), $c ],
2411 $self->rep(0, undef, [ $self->func('s_ns_plain_next_line'), $n, $c ])
2412 );
2413 };
2414  
2415  
2416  
2417 # [136]
2418 # in-flow(c) ::=
2419 # ( c = flow-out => flow-in )
2420 # ( c = flow-in => flow-in )
2421 # ( c = block-key => flow-key )
2422 # ( c = flow-key => flow-key )
2423  
2424 rule '136', in_flow => sub {
2425 my ($self, $c) = @_;
2426 debug_rule("in_flow",$c) if DEBUG;
2427 $self->flip(
2428 $c,
2429 {
2430 'block-key' => "flow-key",
2431 'flow-in' => "flow-in",
2432 'flow-key' => "flow-key",
2433 'flow-out' => "flow-in",
2434 }
2435 );
2436 };
2437  
2438  
2439  
2440 # [137]
2441 # c-flow-sequence(n,c) ::=
2442 # '[' s-separate(n,c)?
2443 # ns-s-flow-seq-entries(n,in-flow(c))? ']'
2444  
2445 rule '137', c_flow_sequence => sub {
2446 my ($self, $n, $c) = @_;
2447 debug_rule("c_flow_sequence",$n,$c) if DEBUG;
2448 $self->all(
2449 $self->chr('['),
2450 $self->rep(0, 1, [ $self->func('s_separate'), $n, $c ]),
2451 $self->rep2(0, 1, [ $self->func('ns_s_flow_seq_entries'), $n, [ $self->func('in_flow'), $c ] ]),
2452 $self->chr(']')
2453 );
2454 };
2455  
2456  
2457  
2458 # [138]
2459 # ns-s-flow-seq-entries(n,c) ::=
2460 # ns-flow-seq-entry(n,c)
2461 # s-separate(n,c)?
2462 # ( ',' s-separate(n,c)?
2463 # ns-s-flow-seq-entries(n,c)? )?
2464  
2465 rule '138', ns_s_flow_seq_entries => sub {
2466 my ($self, $n, $c) = @_;
2467 debug_rule("ns_s_flow_seq_entries",$n,$c) if DEBUG;
2468 $self->all(
2469 [ $self->func('ns_flow_seq_entry'), $n, $c ],
2470 $self->rep(0, 1, [ $self->func('s_separate'), $n, $c ]),
2471 $self->rep2(0, 1,
2472 $self->all(
2473 $self->chr(','),
2474 $self->rep(0, 1, [ $self->func('s_separate'), $n, $c ]),
2475 $self->rep2(0, 1, [ $self->func('ns_s_flow_seq_entries'), $n, $c ])
2476 ))
2477 );
2478 };
2479  
2480  
2481  
2482 # [139]
2483 # ns-flow-seq-entry(n,c) ::=
2484 # ns-flow-pair(n,c) | ns-flow-node(n,c)
2485  
2486 rule '139', ns_flow_seq_entry => sub {
2487 my ($self, $n, $c) = @_;
2488 debug_rule("ns_flow_seq_entry",$n,$c) if DEBUG;
2489 $self->any(
2490 [ $self->func('ns_flow_pair'), $n, $c ],
2491 [ $self->func('ns_flow_node'), $n, $c ]
2492 );
2493 };
2494  
2495  
2496  
2497 # [140]
2498 # c-flow-mapping(n,c) ::=
2499 # '{' s-separate(n,c)?
2500 # ns-s-flow-map-entries(n,in-flow(c))? '}'
2501  
2502 rule '140', c_flow_mapping => sub {
2503 my ($self, $n, $c) = @_;
2504 debug_rule("c_flow_mapping",$n,$c) if DEBUG;
2505 $self->all(
2506 $self->chr('{'),
2507 $self->rep(0, 1, [ $self->func('s_separate'), $n, $c ]),
2508 $self->rep2(0, 1, [ $self->func('ns_s_flow_map_entries'), $n, [ $self->func('in_flow'), $c ] ]),
2509 $self->chr('}')
2510 );
2511 };
2512  
2513  
2514  
2515 # [141]
2516 # ns-s-flow-map-entries(n,c) ::=
2517 # ns-flow-map-entry(n,c)
2518 # s-separate(n,c)?
2519 # ( ',' s-separate(n,c)?
2520 # ns-s-flow-map-entries(n,c)? )?
2521  
2522 rule '141', ns_s_flow_map_entries => sub {
2523 my ($self, $n, $c) = @_;
2524 debug_rule("ns_s_flow_map_entries",$n,$c) if DEBUG;
2525 $self->all(
2526 [ $self->func('ns_flow_map_entry'), $n, $c ],
2527 $self->rep(0, 1, [ $self->func('s_separate'), $n, $c ]),
2528 $self->rep2(0, 1,
2529 $self->all(
2530 $self->chr(','),
2531 $self->rep(0, 1, [ $self->func('s_separate'), $n, $c ]),
2532 $self->rep2(0, 1, [ $self->func('ns_s_flow_map_entries'), $n, $c ])
2533 ))
2534 );
2535 };
2536  
2537  
2538  
2539 # [142]
2540 # ns-flow-map-entry(n,c) ::=
2541 # ( '?' s-separate(n,c)
2542 # ns-flow-map-explicit-entry(n,c) )
2543 # | ns-flow-map-implicit-entry(n,c)
2544  
2545 rule '142', ns_flow_map_entry => sub {
2546 my ($self, $n, $c) = @_;
2547 debug_rule("ns_flow_map_entry",$n,$c) if DEBUG;
2548 $self->any(
2549 $self->all(
2550 $self->chr('?'),
2551 $self->chk(
2552 '=',
2553 $self->any(
2554 $self->func('end_of_stream'),
2555 $self->func('s_white'),
2556 $self->func('b_break')
2557 )
2558 ),
2559 [ $self->func('s_separate'), $n, $c ],
2560 [ $self->func('ns_flow_map_explicit_entry'), $n, $c ]
2561 ),
2562 [ $self->func('ns_flow_map_implicit_entry'), $n, $c ]
2563 );
2564 };
2565  
2566  
2567  
2568 # [143]
2569 # ns-flow-map-explicit-entry(n,c) ::=
2570 # ns-flow-map-implicit-entry(n,c)
2571 # | ( e-node
2572 # e-node )
2573  
2574 rule '143', ns_flow_map_explicit_entry => sub {
2575 my ($self, $n, $c) = @_;
2576 debug_rule("ns_flow_map_explicit_entry",$n,$c) if DEBUG;
2577 $self->any(
2578 [ $self->func('ns_flow_map_implicit_entry'), $n, $c ],
2579 $self->all(
2580 $self->func('e_node'),
2581 $self->func('e_node')
2582 )
2583 );
2584 };
2585  
2586  
2587  
2588 # [144]
2589 # ns-flow-map-implicit-entry(n,c) ::=
2590 # ns-flow-map-yaml-key-entry(n,c)
2591 # | c-ns-flow-map-empty-key-entry(n,c)
2592 # | c-ns-flow-map-json-key-entry(n,c)
2593  
2594 rule '144', ns_flow_map_implicit_entry => sub {
2595 my ($self, $n, $c) = @_;
2596 debug_rule("ns_flow_map_implicit_entry",$n,$c) if DEBUG;
2597 $self->any(
2598 [ $self->func('ns_flow_map_yaml_key_entry'), $n, $c ],
2599 [ $self->func('c_ns_flow_map_empty_key_entry'), $n, $c ],
2600 [ $self->func('c_ns_flow_map_json_key_entry'), $n, $c ]
2601 );
2602 };
2603  
2604  
2605  
2606 # [145]
2607 # ns-flow-map-yaml-key-entry(n,c) ::=
2608 # ns-flow-yaml-node(n,c)
2609 # ( ( s-separate(n,c)?
2610 # c-ns-flow-map-separate-value(n,c) )
2611 # | e-node )
2612  
2613 rule '145', ns_flow_map_yaml_key_entry => sub {
2614 my ($self, $n, $c) = @_;
2615 debug_rule("ns_flow_map_yaml_key_entry",$n,$c) if DEBUG;
2616 $self->all(
2617 [ $self->func('ns_flow_yaml_node'), $n, $c ],
2618 $self->any(
2619 $self->all(
2620 $self->rep(0, 1, [ $self->func('s_separate'), $n, $c ]),
2621 [ $self->func('c_ns_flow_map_separate_value'), $n, $c ]
2622 ),
2623 $self->func('e_node')
2624 )
2625 );
2626 };
2627  
2628  
2629  
2630 # [146]
2631 # c-ns-flow-map-empty-key-entry(n,c) ::=
2632 # e-node
2633 # c-ns-flow-map-separate-value(n,c)
2634  
2635 rule '146', c_ns_flow_map_empty_key_entry => sub {
2636 my ($self, $n, $c) = @_;
2637 debug_rule("c_ns_flow_map_empty_key_entry",$n,$c) if DEBUG;
2638 $self->all(
2639 $self->func('e_node'),
2640 [ $self->func('c_ns_flow_map_separate_value'), $n, $c ]
2641 );
2642 };
2643  
2644  
2645  
2646 # [147]
2647 # c-ns-flow-map-separate-value(n,c) ::=
2648 # ':' <not_followed_by_an_ns-plain-safe(c)>
2649 # ( ( s-separate(n,c) ns-flow-node(n,c) )
2650 # | e-node )
2651  
2652 rule '147', c_ns_flow_map_separate_value => sub {
2653 my ($self, $n, $c) = @_;
2654 debug_rule("c_ns_flow_map_separate_value",$n,$c) if DEBUG;
2655 $self->all(
2656 $self->chr(':'),
2657 $self->chk('!', [ $self->func('ns_plain_safe'), $c ]),
2658 $self->any(
2659 $self->all(
2660 [ $self->func('s_separate'), $n, $c ],
2661 [ $self->func('ns_flow_node'), $n, $c ]
2662 ),
2663 $self->func('e_node')
2664 )
2665 );
2666 };
2667  
2668  
2669  
2670 # [148]
2671 # c-ns-flow-map-json-key-entry(n,c) ::=
2672 # c-flow-json-node(n,c)
2673 # ( ( s-separate(n,c)?
2674 # c-ns-flow-map-adjacent-value(n,c) )
2675 # | e-node )
2676  
2677 rule '148', c_ns_flow_map_json_key_entry => sub {
2678 my ($self, $n, $c) = @_;
2679 debug_rule("c_ns_flow_map_json_key_entry",$n,$c) if DEBUG;
2680 $self->all(
2681 [ $self->func('c_flow_json_node'), $n, $c ],
2682 $self->any(
2683 $self->all(
2684 $self->rep(0, 1, [ $self->func('s_separate'), $n, $c ]),
2685 [ $self->func('c_ns_flow_map_adjacent_value'), $n, $c ]
2686 ),
2687 $self->func('e_node')
2688 )
2689 );
2690 };
2691  
2692  
2693  
2694 # [149]
2695 # c-ns-flow-map-adjacent-value(n,c) ::=
2696 # ':' ( (
2697 # s-separate(n,c)?
2698 # ns-flow-node(n,c) )
2699 # | e-node )
2700  
2701 rule '149', c_ns_flow_map_adjacent_value => sub {
2702 my ($self, $n, $c) = @_;
2703 debug_rule("c_ns_flow_map_adjacent_value",$n,$c) if DEBUG;
2704 $self->all(
2705 $self->chr(':'),
2706 $self->any(
2707 $self->all(
2708 $self->rep(0, 1, [ $self->func('s_separate'), $n, $c ]),
2709 [ $self->func('ns_flow_node'), $n, $c ]
2710 ),
2711 $self->func('e_node')
2712 )
2713 );
2714 };
2715  
2716  
2717  
2718 # [150]
2719 # ns-flow-pair(n,c) ::=
2720 # ( '?' s-separate(n,c)
2721 # ns-flow-map-explicit-entry(n,c) )
2722 # | ns-flow-pair-entry(n,c)
2723  
2724 rule '150', ns_flow_pair => sub {
2725 my ($self, $n, $c) = @_;
2726 debug_rule("ns_flow_pair",$n,$c) if DEBUG;
2727 $self->any(
2728 $self->all(
2729 $self->chr('?'),
2730 $self->chk(
2731 '=',
2732 $self->any(
2733 $self->func('end_of_stream'),
2734 $self->func('s_white'),
2735 $self->func('b_break')
2736 )
2737 ),
2738 [ $self->func('s_separate'), $n, $c ],
2739 [ $self->func('ns_flow_map_explicit_entry'), $n, $c ]
2740 ),
2741 [ $self->func('ns_flow_pair_entry'), $n, $c ]
2742 );
2743 };
2744  
2745  
2746  
2747 # [151]
2748 # ns-flow-pair-entry(n,c) ::=
2749 # ns-flow-pair-yaml-key-entry(n,c)
2750 # | c-ns-flow-map-empty-key-entry(n,c)
2751 # | c-ns-flow-pair-json-key-entry(n,c)
2752  
2753 rule '151', ns_flow_pair_entry => sub {
2754 my ($self, $n, $c) = @_;
2755 debug_rule("ns_flow_pair_entry",$n,$c) if DEBUG;
2756 $self->any(
2757 [ $self->func('ns_flow_pair_yaml_key_entry'), $n, $c ],
2758 [ $self->func('c_ns_flow_map_empty_key_entry'), $n, $c ],
2759 [ $self->func('c_ns_flow_pair_json_key_entry'), $n, $c ]
2760 );
2761 };
2762  
2763  
2764  
2765 # [152]
2766 # ns-flow-pair-yaml-key-entry(n,c) ::=
2767 # ns-s-implicit-yaml-key(flow-key)
2768 # c-ns-flow-map-separate-value(n,c)
2769  
2770 rule '152', ns_flow_pair_yaml_key_entry => sub {
2771 my ($self, $n, $c) = @_;
2772 debug_rule("ns_flow_pair_yaml_key_entry",$n,$c) if DEBUG;
2773 $self->all(
2774 [ $self->func('ns_s_implicit_yaml_key'), "flow-key" ],
2775 [ $self->func('c_ns_flow_map_separate_value'), $n, $c ]
2776 );
2777 };
2778  
2779  
2780  
2781 # [153]
2782 # c-ns-flow-pair-json-key-entry(n,c) ::=
2783 # c-s-implicit-json-key(flow-key)
2784 # c-ns-flow-map-adjacent-value(n,c)
2785  
2786 rule '153', c_ns_flow_pair_json_key_entry => sub {
2787 my ($self, $n, $c) = @_;
2788 debug_rule("c_ns_flow_pair_json_key_entry",$n,$c) if DEBUG;
2789 $self->all(
2790 [ $self->func('c_s_implicit_json_key'), "flow-key" ],
2791 [ $self->func('c_ns_flow_map_adjacent_value'), $n, $c ]
2792 );
2793 };
2794  
2795  
2796  
2797 # [154]
2798 # ns-s-implicit-yaml-key(c) ::=
2799 # ns-flow-yaml-node(n/a,c)
2800 # s-separate-in-line?
2801 # <at_most_1024_characters_altogether>
2802  
2803 rule '154', ns_s_implicit_yaml_key => sub {
2804 my ($self, $c) = @_;
2805 debug_rule("ns_s_implicit_yaml_key",$c) if DEBUG;
2806 $self->all(
2807 $self->max(1024),
2808 [ $self->func('ns_flow_yaml_node'), undef, $c ],
2809 $self->rep(0, 1, $self->func('s_separate_in_line'))
2810 );
2811 };
2812  
2813  
2814  
2815 # [155]
2816 # c-s-implicit-json-key(c) ::=
2817 # c-flow-json-node(n/a,c)
2818 # s-separate-in-line?
2819 # <at_most_1024_characters_altogether>
2820  
2821 rule '155', c_s_implicit_json_key => sub {
2822 my ($self, $c) = @_;
2823 debug_rule("c_s_implicit_json_key",$c) if DEBUG;
2824 $self->all(
2825 $self->max(1024),
2826 [ $self->func('c_flow_json_node'), undef, $c ],
2827 $self->rep(0, 1, $self->func('s_separate_in_line'))
2828 );
2829 };
2830  
2831  
2832  
2833 # [156]
2834 # ns-flow-yaml-content(n,c) ::=
2835 # ns-plain(n,c)
2836  
2837 rule '156', ns_flow_yaml_content => sub {
2838 my ($self, $n, $c) = @_;
2839 debug_rule("ns_flow_yaml_content",$n,$c) if DEBUG;
2840 [ $self->func('ns_plain'), $n, $c ];
2841 };
2842  
2843  
2844  
2845 # [157]
2846 # c-flow-json-content(n,c) ::=
2847 # c-flow-sequence(n,c) | c-flow-mapping(n,c)
2848 # | c-single-quoted(n,c) | c-double-quoted(n,c)
2849  
2850 rule '157', c_flow_json_content => sub {
2851 my ($self, $n, $c) = @_;
2852 debug_rule("c_flow_json_content",$n,$c) if DEBUG;
2853 $self->any(
2854 [ $self->func('c_flow_sequence'), $n, $c ],
2855 [ $self->func('c_flow_mapping'), $n, $c ],
2856 [ $self->func('c_single_quoted'), $n, $c ],
2857 [ $self->func('c_double_quoted'), $n, $c ]
2858 );
2859 };
2860  
2861  
2862  
2863 # [158]
2864 # ns-flow-content(n,c) ::=
2865 # ns-flow-yaml-content(n,c) | c-flow-json-content(n,c)
2866  
2867 rule '158', ns_flow_content => sub {
2868 my ($self, $n, $c) = @_;
2869 debug_rule("ns_flow_content",$n,$c) if DEBUG;
2870 $self->any(
2871 [ $self->func('ns_flow_yaml_content'), $n, $c ],
2872 [ $self->func('c_flow_json_content'), $n, $c ]
2873 );
2874 };
2875  
2876  
2877  
2878 # [159]
2879 # ns-flow-yaml-node(n,c) ::=
2880 # c-ns-alias-node
2881 # | ns-flow-yaml-content(n,c)
2882 # | ( c-ns-properties(n,c)
2883 # ( ( s-separate(n,c)
2884 # ns-flow-yaml-content(n,c) )
2885 # | e-scalar ) )
2886  
2887 rule '159', ns_flow_yaml_node => sub {
2888 my ($self, $n, $c) = @_;
2889 debug_rule("ns_flow_yaml_node",$n,$c) if DEBUG;
2890 $self->any(
2891 $self->func('c_ns_alias_node'),
2892 [ $self->func('ns_flow_yaml_content'), $n, $c ],
2893 $self->all(
2894 [ $self->func('c_ns_properties'), $n, $c ],
2895 $self->any(
2896 $self->all(
2897 [ $self->func('s_separate'), $n, $c ],
2898 [ $self->func('ns_flow_content'), $n, $c ]
2899 ),
2900 $self->func('e_scalar')
2901 )
2902 )
2903 );
2904 };
2905  
2906  
2907  
2908 # [160]
2909 # c-flow-json-node(n,c) ::=
2910 # ( c-ns-properties(n,c)
2911 # s-separate(n,c) )?
2912 # c-flow-json-content(n,c)
2913  
2914 rule '160', c_flow_json_node => sub {
2915 my ($self, $n, $c) = @_;
2916 debug_rule("c_flow_json_node",$n,$c) if DEBUG;
2917 $self->all(
2918 $self->rep(0, 1,
2919 $self->all(
2920 [ $self->func('c_ns_properties'), $n, $c ],
2921 [ $self->func('s_separate'), $n, $c ]
2922 )),
2923 [ $self->func('c_flow_json_content'), $n, $c ]
2924 );
2925 };
2926  
2927  
2928  
2929 # [161]
2930 # ns-flow-node(n,c) ::=
2931 # c-ns-alias-node
2932 # | ns-flow-content(n,c)
2933 # | ( c-ns-properties(n,c)
2934 # ( ( s-separate(n,c)
2935 # ns-flow-content(n,c) )
2936 # | e-scalar ) )
2937  
2938 rule '161', ns_flow_node => sub {
2939 my ($self, $n, $c) = @_;
2940 debug_rule("ns_flow_node",$n,$c) if DEBUG;
2941 $self->any(
2942 $self->func('c_ns_alias_node'),
2943 [ $self->func('ns_flow_content'), $n, $c ],
2944 $self->all(
2945 [ $self->func('c_ns_properties'), $n, $c ],
2946 $self->any(
2947 $self->all(
2948 [ $self->func('s_separate'), $n, $c ],
2949 [ $self->func('ns_flow_content'), $n, $c ]
2950 ),
2951 $self->func('e_scalar')
2952 )
2953 )
2954 );
2955 };
2956  
2957  
2958  
2959 # [162]
2960 # c-b-block-header(m,t) ::=
2961 # ( ( c-indentation-indicator(m)
2962 # c-chomping-indicator(t) )
2963 # | ( c-chomping-indicator(t)
2964 # c-indentation-indicator(m) ) )
2965 # s-b-comment
2966  
2967 rule '162', c_b_block_header => sub {
2968 my ($self, $n) = @_;
2969 debug_rule("c_b_block_header",$n) if DEBUG;
2970 $self->all(
2971 $self->any(
2972 $self->all(
2973 [ $self->func('c_indentation_indicator'), $n ],
2974 $self->func('c_chomping_indicator'),
2975 $self->chk(
2976 '=',
2977 $self->any(
2978 $self->func('end_of_stream'),
2979 $self->func('s_white'),
2980 $self->func('b_break')
2981 )
2982 )
2983 ),
2984 $self->all(
2985 $self->func('c_chomping_indicator'),
2986 [ $self->func('c_indentation_indicator'), $n ],
2987 $self->chk(
2988 '=',
2989 $self->any(
2990 $self->func('end_of_stream'),
2991 $self->func('s_white'),
2992 $self->func('b_break')
2993 )
2994 )
2995 )
2996 ),
2997 $self->func('s_b_comment')
2998 );
2999 };
3000  
3001  
3002  
3003 # [163]
3004 # c-indentation-indicator(m) ::=
3005 # ( ns-dec-digit => m = ns-dec-digit - x:30 )
3006 # ( <empty> => m = auto-detect() )
3007  
3008 rule '163', c_indentation_indicator => sub {
3009 my ($self, $n) = @_;
3010 debug_rule("c_indentation_indicator",$n) if DEBUG;
3011 $self->any(
3012 $self->if($self->func('ns_dec_digit'), $self->set('m', $self->ord($self->func('match')))),
3013 $self->if($self->func('empty'), $self->set('m', [ $self->func('auto_detect'), $n ]))
3014 );
3015 };
3016  
3017  
3018  
3019 # [164]
3020 # c-chomping-indicator(t) ::=
3021 # ( '-' => t = strip )
3022 # ( '+' => t = keep )
3023 # ( <empty> => t = clip )
3024  
3025 rule '164', c_chomping_indicator => sub {
3026 my ($self) = @_;
3027 debug_rule("c_chomping_indicator") if DEBUG;
3028 $self->any(
3029 $self->if($self->chr('-'), $self->set('t', "strip")),
3030 $self->if($self->chr('+'), $self->set('t', "keep")),
3031 $self->if($self->func('empty'), $self->set('t', "clip"))
3032 );
3033 };
3034  
3035  
3036  
3037 # [165]
3038 # b-chomped-last(t) ::=
3039 # ( t = strip => b-non-content | <end_of_file> )
3040 # ( t = clip => b-as-line-feed | <end_of_file> )
3041 # ( t = keep => b-as-line-feed | <end_of_file> )
3042  
3043 rule '165', b_chomped_last => sub {
3044 my ($self, $t) = @_;
3045 debug_rule("b_chomped_last",$t) if DEBUG;
3046 $self->case(
3047 $t,
3048 {
3049 'clip' => $self->any( $self->func('b_as_line_feed'), $self->func('end_of_stream') ),
3050 'keep' => $self->any( $self->func('b_as_line_feed'), $self->func('end_of_stream') ),
3051 'strip' => $self->any( $self->func('b_non_content'), $self->func('end_of_stream') ),
3052 }
3053 );
3054 };
3055  
3056  
3057  
3058 # [166]
3059 # l-chomped-empty(n,t) ::=
3060 # ( t = strip => l-strip-empty(n) )
3061 # ( t = clip => l-strip-empty(n) )
3062 # ( t = keep => l-keep-empty(n) )
3063  
3064 rule '166', l_chomped_empty => sub {
3065 my ($self, $n, $t) = @_;
3066 debug_rule("l_chomped_empty",$n,$t) if DEBUG;
3067 $self->case(
3068 $t,
3069 {
3070 'clip' => [ $self->func('l_strip_empty'), $n ],
3071 'keep' => [ $self->func('l_keep_empty'), $n ],
3072 'strip' => [ $self->func('l_strip_empty'), $n ],
3073 }
3074 );
3075 };
3076  
3077  
3078  
3079 # [167]
3080 # l-strip-empty(n) ::=
3081 # ( s-indent(<=n) b-non-content )*
3082 # l-trail-comments(n)?
3083  
3084 rule '167', l_strip_empty => sub {
3085 my ($self, $n) = @_;
3086 debug_rule("l_strip_empty",$n) if DEBUG;
3087 $self->all(
3088 $self->rep(0, undef,
3089 $self->all(
3090 [ $self->func('s_indent_le'), $n ],
3091 $self->func('b_non_content')
3092 )),
3093 $self->rep2(0, 1, [ $self->func('l_trail_comments'), $n ])
3094 );
3095 };
3096  
3097  
3098  
3099 # [168]
3100 # l-keep-empty(n) ::=
3101 # l-empty(n,block-in)*
3102 # l-trail-comments(n)?
3103  
3104 rule '168', l_keep_empty => sub {
3105 my ($self, $n) = @_;
3106 debug_rule("l_keep_empty",$n) if DEBUG;
3107 $self->all(
3108 $self->rep(0, undef, [ $self->func('l_empty'), $n, "block-in" ]),
3109 $self->rep2(0, 1, [ $self->func('l_trail_comments'), $n ])
3110 );
3111 };
3112  
3113  
3114  
3115 # [169]
3116 # l-trail-comments(n) ::=
3117 # s-indent(<n)
3118 # c-nb-comment-text b-comment
3119 # l-comment*
3120  
3121 rule '169', l_trail_comments => sub {
3122 my ($self, $n) = @_;
3123 debug_rule("l_trail_comments",$n) if DEBUG;
3124 $self->all(
3125 [ $self->func('s_indent_lt'), $n ],
3126 $self->func('c_nb_comment_text'),
3127 $self->func('b_comment'),
3128 $self->rep(0, undef, $self->func('l_comment'))
3129 );
3130 };
3131  
3132  
3133  
3134 # [170]
3135 # c-l+literal(n) ::=
3136 # '|' c-b-block-header(m,t)
3137 # l-literal-content(n+m,t)
3138  
3139 rule '170', c_l_literal => sub {
3140 my ($self, $n) = @_;
3141 debug_rule("c_l_literal",$n) if DEBUG;
3142 $self->all(
3143 $self->chr('|'),
3144 [ $self->func('c_b_block_header'), $n ],
3145 [ $self->func('l_literal_content'), $self->add($n, $self->m()), $self->t() ]
3146 );
3147 };
3148  
3149  
3150  
3151 # [171]
3152 # l-nb-literal-text(n) ::=
3153 # l-empty(n,block-in)*
3154 # s-indent(n) nb-char+
3155  
3156 rule '171', l_nb_literal_text => sub {
3157 my ($self, $n) = @_;
3158 debug_rule("l_nb_literal_text",$n) if DEBUG;
3159 $self->all(
3160 $self->rep(0, undef, [ $self->func('l_empty'), $n, "block-in" ]),
3161 [ $self->func('s_indent'), $n ],
3162 $self->rep2(1, undef, $self->func('nb_char'))
3163 );
3164 };
3165  
3166  
3167  
3168 # [172]
3169 # b-nb-literal-next(n) ::=
3170 # b-as-line-feed
3171 # l-nb-literal-text(n)
3172  
3173 rule '172', b_nb_literal_next => sub {
3174 my ($self, $n) = @_;
3175 debug_rule("b_nb_literal_next",$n) if DEBUG;
3176 $self->all(
3177 $self->func('b_as_line_feed'),
3178 [ $self->func('l_nb_literal_text'), $n ]
3179 );
3180 };
3181  
3182  
3183  
3184 # [173]
3185 # l-literal-content(n,t) ::=
3186 # ( l-nb-literal-text(n)
3187 # b-nb-literal-next(n)*
3188 # b-chomped-last(t) )?
3189 # l-chomped-empty(n,t)
3190  
3191 rule '173', l_literal_content => sub {
3192 my ($self, $n, $t) = @_;
3193 debug_rule("l_literal_content",$n,$t) if DEBUG;
3194 $self->all(
3195 $self->rep(0, 1,
3196 $self->all(
3197 [ $self->func('l_nb_literal_text'), $n ],
3198 $self->rep(0, undef, [ $self->func('b_nb_literal_next'), $n ]),
3199 [ $self->func('b_chomped_last'), $t ]
3200 )),
3201 [ $self->func('l_chomped_empty'), $n, $t ]
3202 );
3203 };
3204  
3205  
3206  
3207 # [174]
3208 # c-l+folded(n) ::=
3209 # '>' c-b-block-header(m,t)
3210 # l-folded-content(n+m,t)
3211  
3212 rule '174', c_l_folded => sub {
3213 my ($self, $n) = @_;
3214 debug_rule("c_l_folded",$n) if DEBUG;
3215 $self->all(
3216 $self->chr('>'),
3217 [ $self->func('c_b_block_header'), $n ],
3218 [ $self->func('l_folded_content'), $self->add($n, $self->m()), $self->t() ]
3219 );
3220 };
3221  
3222  
3223  
3224 # [175]
3225 # s-nb-folded-text(n) ::=
3226 # s-indent(n) ns-char
3227 # nb-char*
3228  
3229 rule '175', s_nb_folded_text => sub {
3230 my ($self, $n) = @_;
3231 debug_rule("s_nb_folded_text",$n) if DEBUG;
3232 $self->all(
3233 [ $self->func('s_indent'), $n ],
3234 $self->func('ns_char'),
3235 $self->rep(0, undef, $self->func('nb_char'))
3236 );
3237 };
3238  
3239  
3240  
3241 # [176]
3242 # l-nb-folded-lines(n) ::=
3243 # s-nb-folded-text(n)
3244 # ( b-l-folded(n,block-in) s-nb-folded-text(n) )*
3245  
3246 rule '176', l_nb_folded_lines => sub {
3247 my ($self, $n) = @_;
3248 debug_rule("l_nb_folded_lines",$n) if DEBUG;
3249 $self->all(
3250 [ $self->func('s_nb_folded_text'), $n ],
3251 $self->rep(0, undef,
3252 $self->all(
3253 [ $self->func('b_l_folded'), $n, "block-in" ],
3254 [ $self->func('s_nb_folded_text'), $n ]
3255 ))
3256 );
3257 };
3258  
3259  
3260  
3261 # [177]
3262 # s-nb-spaced-text(n) ::=
3263 # s-indent(n) s-white
3264 # nb-char*
3265  
3266 rule '177', s_nb_spaced_text => sub {
3267 my ($self, $n) = @_;
3268 debug_rule("s_nb_spaced_text",$n) if DEBUG;
3269 $self->all(
3270 [ $self->func('s_indent'), $n ],
3271 $self->func('s_white'),
3272 $self->rep(0, undef, $self->func('nb_char'))
3273 );
3274 };
3275  
3276  
3277  
3278 # [178]
3279 # b-l-spaced(n) ::=
3280 # b-as-line-feed
3281 # l-empty(n,block-in)*
3282  
3283 rule '178', b_l_spaced => sub {
3284 my ($self, $n) = @_;
3285 debug_rule("b_l_spaced",$n) if DEBUG;
3286 $self->all(
3287 $self->func('b_as_line_feed'),
3288 $self->rep(0, undef, [ $self->func('l_empty'), $n, "block-in" ])
3289 );
3290 };
3291  
3292  
3293  
3294 # [179]
3295 # l-nb-spaced-lines(n) ::=
3296 # s-nb-spaced-text(n)
3297 # ( b-l-spaced(n) s-nb-spaced-text(n) )*
3298  
3299 rule '179', l_nb_spaced_lines => sub {
3300 my ($self, $n) = @_;
3301 debug_rule("l_nb_spaced_lines",$n) if DEBUG;
3302 $self->all(
3303 [ $self->func('s_nb_spaced_text'), $n ],
3304 $self->rep(0, undef,
3305 $self->all(
3306 [ $self->func('b_l_spaced'), $n ],
3307 [ $self->func('s_nb_spaced_text'), $n ]
3308 ))
3309 );
3310 };
3311  
3312  
3313  
3314 # [180]
3315 # l-nb-same-lines(n) ::=
3316 # l-empty(n,block-in)*
3317 # ( l-nb-folded-lines(n) | l-nb-spaced-lines(n) )
3318  
3319 rule '180', l_nb_same_lines => sub {
3320 my ($self, $n) = @_;
3321 debug_rule("l_nb_same_lines",$n) if DEBUG;
3322 $self->all(
3323 $self->rep(0, undef, [ $self->func('l_empty'), $n, "block-in" ]),
3324 $self->any(
3325 [ $self->func('l_nb_folded_lines'), $n ],
3326 [ $self->func('l_nb_spaced_lines'), $n ]
3327 )
3328 );
3329 };
3330  
3331  
3332  
3333 # [181]
3334 # l-nb-diff-lines(n) ::=
3335 # l-nb-same-lines(n)
3336 # ( b-as-line-feed l-nb-same-lines(n) )*
3337  
3338 rule '181', l_nb_diff_lines => sub {
3339 my ($self, $n) = @_;
3340 debug_rule("l_nb_diff_lines",$n) if DEBUG;
3341 $self->all(
3342 [ $self->func('l_nb_same_lines'), $n ],
3343 $self->rep(0, undef,
3344 $self->all(
3345 $self->func('b_as_line_feed'),
3346 [ $self->func('l_nb_same_lines'), $n ]
3347 ))
3348 );
3349 };
3350  
3351  
3352  
3353 # [182]
3354 # l-folded-content(n,t) ::=
3355 # ( l-nb-diff-lines(n)
3356 # b-chomped-last(t) )?
3357 # l-chomped-empty(n,t)
3358  
3359 rule '182', l_folded_content => sub {
3360 my ($self, $n, $t) = @_;
3361 debug_rule("l_folded_content",$n,$t) if DEBUG;
3362 $self->all(
3363 $self->rep(0, 1,
3364 $self->all(
3365 [ $self->func('l_nb_diff_lines'), $n ],
3366 [ $self->func('b_chomped_last'), $t ]
3367 )),
3368 [ $self->func('l_chomped_empty'), $n, $t ]
3369 );
3370 };
3371  
3372  
3373  
3374 # [183]
3375 # l+block-sequence(n) ::=
3376 # ( s-indent(n+m)
3377 # c-l-block-seq-entry(n+m) )+
3378 # <for_some_fixed_auto-detected_m_>_0>
3379  
3380 rule '183', l_block_sequence => sub {
3381 my ($self, $n) = @_;
3382 my $m = $self->call([$self->func('auto_detect_indent'), $n], 'number') or return false;
3383 debug_rule("l_block_sequence",$n) if DEBUG;
3384 $self->all(
3385 $self->rep(1, undef,
3386 $self->all(
3387 [ $self->func('s_indent'), $self->add($n, $m) ],
3388 [ $self->func('c_l_block_seq_entry'), $self->add($n, $m) ]
3389 ))
3390 );
3391 };
3392  
3393  
3394  
3395 # [184]
3396 # c-l-block-seq-entry(n) ::=
3397 # '-' <not_followed_by_an_ns-char>
3398 # s-l+block-indented(n,block-in)
3399  
3400 rule '184', c_l_block_seq_entry => sub {
3401 my ($self, $n) = @_;
3402 debug_rule("c_l_block_seq_entry",$n) if DEBUG;
3403 $self->all(
3404 $self->chr('-'),
3405 $self->chk('!', $self->func('ns_char')),
3406 [ $self->func('s_l_block_indented'), $n, "block-in" ]
3407 );
3408 };
3409  
3410  
3411  
3412 # [185]
3413 # s-l+block-indented(n,c) ::=
3414 # ( s-indent(m)
3415 # ( ns-l-compact-sequence(n+1+m)
3416 # | ns-l-compact-mapping(n+1+m) ) )
3417 # | s-l+block-node(n,c)
3418 # | ( e-node s-l-comments )
3419  
3420 rule '185', s_l_block_indented => sub {
3421 my ($self, $n, $c) = @_;
3422 my $m = $self->call([$self->func('auto_detect_indent'), $n], 'number');
3423 debug_rule("s_l_block_indented",$n,$c) if DEBUG;
3424 $self->any(
3425 $self->all(
3426 [ $self->func('s_indent'), $m ],
3427 $self->any(
3428 [ $self->func('ns_l_compact_sequence'), $self->add($n, $self->add(1, $m)) ],
3429 [ $self->func('ns_l_compact_mapping'), $self->add($n, $self->add(1, $m)) ]
3430 )
3431 ),
3432 [ $self->func('s_l_block_node'), $n, $c ],
3433 $self->all(
3434 $self->func('e_node'),
3435 $self->func('s_l_comments')
3436 )
3437 );
3438 };
3439  
3440  
3441  
3442 # [186]
3443 # ns-l-compact-sequence(n) ::=
3444 # c-l-block-seq-entry(n)
3445 # ( s-indent(n) c-l-block-seq-entry(n) )*
3446  
3447 rule '186', ns_l_compact_sequence => sub {
3448 my ($self, $n) = @_;
3449 debug_rule("ns_l_compact_sequence",$n) if DEBUG;
3450 $self->all(
3451 [ $self->func('c_l_block_seq_entry'), $n ],
3452 $self->rep(0, undef,
3453 $self->all(
3454 [ $self->func('s_indent'), $n ],
3455 [ $self->func('c_l_block_seq_entry'), $n ]
3456 ))
3457 );
3458 };
3459  
3460  
3461  
3462 # [187]
3463 # l+block-mapping(n) ::=
3464 # ( s-indent(n+m)
3465 # ns-l-block-map-entry(n+m) )+
3466 # <for_some_fixed_auto-detected_m_>_0>
3467  
3468 rule '187', l_block_mapping => sub {
3469 my ($self, $n) = @_;
3470 my $m = $self->call([$self->func('auto_detect_indent'), $n], 'number') or return false;
3471 debug_rule("l_block_mapping",$n) if DEBUG;
3472 $self->all(
3473 $self->rep(1, undef,
3474 $self->all(
3475 [ $self->func('s_indent'), $self->add($n, $m) ],
3476 [ $self->func('ns_l_block_map_entry'), $self->add($n, $m) ]
3477 ))
3478 );
3479 };
3480  
3481  
3482  
3483 # [188]
3484 # ns-l-block-map-entry(n) ::=
3485 # c-l-block-map-explicit-entry(n)
3486 # | ns-l-block-map-implicit-entry(n)
3487  
3488 rule '188', ns_l_block_map_entry => sub {
3489 my ($self, $n) = @_;
3490 debug_rule("ns_l_block_map_entry",$n) if DEBUG;
3491 $self->any(
3492 [ $self->func('c_l_block_map_explicit_entry'), $n ],
3493 [ $self->func('ns_l_block_map_implicit_entry'), $n ]
3494 );
3495 };
3496  
3497  
3498  
3499 # [189]
3500 # c-l-block-map-explicit-entry(n) ::=
3501 # c-l-block-map-explicit-key(n)
3502 # ( l-block-map-explicit-value(n)
3503 # | e-node )
3504  
3505 rule '189', c_l_block_map_explicit_entry => sub {
3506 my ($self, $n) = @_;
3507 debug_rule("c_l_block_map_explicit_entry",$n) if DEBUG;
3508 $self->all(
3509 [ $self->func('c_l_block_map_explicit_key'), $n ],
3510 $self->any(
3511 [ $self->func('l_block_map_explicit_value'), $n ],
3512 $self->func('e_node')
3513 )
3514 );
3515 };
3516  
3517  
3518  
3519 # [190]
3520 # c-l-block-map-explicit-key(n) ::=
3521 # '?'
3522 # s-l+block-indented(n,block-out)
3523  
3524 rule '190', c_l_block_map_explicit_key => sub {
3525 my ($self, $n) = @_;
3526 debug_rule("c_l_block_map_explicit_key",$n) if DEBUG;
3527 $self->all(
3528 $self->chr('?'),
3529 $self->chk(
3530 '=',
3531 $self->any(
3532 $self->func('end_of_stream'),
3533 $self->func('s_white'),
3534 $self->func('b_break')
3535 )
3536 ),
3537 [ $self->func('s_l_block_indented'), $n, "block-out" ]
3538 );
3539 };
3540  
3541  
3542  
3543 # [191]
3544 # l-block-map-explicit-value(n) ::=
3545 # s-indent(n)
3546 # ':' s-l+block-indented(n,block-out)
3547  
3548 rule '191', l_block_map_explicit_value => sub {
3549 my ($self, $n) = @_;
3550 debug_rule("l_block_map_explicit_value",$n) if DEBUG;
3551 $self->all(
3552 [ $self->func('s_indent'), $n ],
3553 $self->chr(':'),
3554 [ $self->func('s_l_block_indented'), $n, "block-out" ]
3555 );
3556 };
3557  
3558  
3559  
3560 # [192]
3561 # ns-l-block-map-implicit-entry(n) ::=
3562 # (
3563 # ns-s-block-map-implicit-key
3564 # | e-node )
3565 # c-l-block-map-implicit-value(n)
3566  
3567 rule '192', ns_l_block_map_implicit_entry => sub {
3568 my ($self, $n) = @_;
3569 debug_rule("ns_l_block_map_implicit_entry",$n) if DEBUG;
3570 $self->all(
3571 $self->any(
3572 $self->func('ns_s_block_map_implicit_key'),
3573 $self->func('e_node')
3574 ),
3575 [ $self->func('c_l_block_map_implicit_value'), $n ]
3576 );
3577 };
3578  
3579  
3580  
3581 # [193]
3582 # ns-s-block-map-implicit-key ::=
3583 # c-s-implicit-json-key(block-key)
3584 # | ns-s-implicit-yaml-key(block-key)
3585  
3586 rule '193', ns_s_block_map_implicit_key => sub {
3587 my ($self) = @_;
3588 debug_rule("ns_s_block_map_implicit_key") if DEBUG;
3589 $self->any(
3590 [ $self->func('c_s_implicit_json_key'), "block-key" ],
3591 [ $self->func('ns_s_implicit_yaml_key'), "block-key" ]
3592 );
3593 };
3594  
3595  
3596  
3597 # [194]
3598 # c-l-block-map-implicit-value(n) ::=
3599 # ':' (
3600 # s-l+block-node(n,block-out)
3601 # | ( e-node s-l-comments ) )
3602  
3603 rule '194', c_l_block_map_implicit_value => sub {
3604 my ($self, $n) = @_;
3605 debug_rule("c_l_block_map_implicit_value",$n) if DEBUG;
3606 $self->all(
3607 $self->chr(':'),
3608 $self->any(
3609 [ $self->func('s_l_block_node'), $n, "block-out" ],
3610 $self->all(
3611 $self->func('e_node'),
3612 $self->func('s_l_comments')
3613 )
3614 )
3615 );
3616 };
3617  
3618  
3619  
3620 # [195]
3621 # ns-l-compact-mapping(n) ::=
3622 # ns-l-block-map-entry(n)
3623 # ( s-indent(n) ns-l-block-map-entry(n) )*
3624  
3625 rule '195', ns_l_compact_mapping => sub {
3626 my ($self, $n) = @_;
3627 debug_rule("ns_l_compact_mapping",$n) if DEBUG;
3628 $self->all(
3629 [ $self->func('ns_l_block_map_entry'), $n ],
3630 $self->rep(0, undef,
3631 $self->all(
3632 [ $self->func('s_indent'), $n ],
3633 [ $self->func('ns_l_block_map_entry'), $n ]
3634 ))
3635 );
3636 };
3637  
3638  
3639  
3640 # [196]
3641 # s-l+block-node(n,c) ::=
3642 # s-l+block-in-block(n,c) | s-l+flow-in-block(n)
3643  
3644 rule '196', s_l_block_node => sub {
3645 my ($self, $n, $c) = @_;
3646 debug_rule("s_l_block_node",$n,$c) if DEBUG;
3647 $self->any(
3648 [ $self->func('s_l_block_in_block'), $n, $c ],
3649 [ $self->func('s_l_flow_in_block'), $n ]
3650 );
3651 };
3652  
3653  
3654  
3655 # [197]
3656 # s-l+flow-in-block(n) ::=
3657 # s-separate(n+1,flow-out)
3658 # ns-flow-node(n+1,flow-out) s-l-comments
3659  
3660 rule '197', s_l_flow_in_block => sub {
3661 my ($self, $n) = @_;
3662 debug_rule("s_l_flow_in_block",$n) if DEBUG;
3663 $self->all(
3664 [ $self->func('s_separate'), $self->add($n, 1), "flow-out" ],
3665 [ $self->func('ns_flow_node'), $self->add($n, 1), "flow-out" ],
3666 $self->func('s_l_comments')
3667 );
3668 };
3669  
3670  
3671  
3672 # [198]
3673 # s-l+block-in-block(n,c) ::=
3674 # s-l+block-scalar(n,c) | s-l+block-collection(n,c)
3675  
3676 rule '198', s_l_block_in_block => sub {
3677 my ($self, $n, $c) = @_;
3678 debug_rule("s_l_block_in_block",$n,$c) if DEBUG;
3679 $self->any(
3680 [ $self->func('s_l_block_scalar'), $n, $c ],
3681 [ $self->func('s_l_block_collection'), $n, $c ]
3682 );
3683 };
3684  
3685  
3686  
3687 # [199]
3688 # s-l+block-scalar(n,c) ::=
3689 # s-separate(n+1,c)
3690 # ( c-ns-properties(n+1,c) s-separate(n+1,c) )?
3691 # ( c-l+literal(n) | c-l+folded(n) )
3692  
3693 rule '199', s_l_block_scalar => sub {
3694 my ($self, $n, $c) = @_;
3695 debug_rule("s_l_block_scalar",$n,$c) if DEBUG;
3696 $self->all(
3697 [ $self->func('s_separate'), $self->add($n, 1), $c ],
3698 $self->rep(0, 1,
3699 $self->all(
3700 [ $self->func('c_ns_properties'), $self->add($n, 1), $c ],
3701 [ $self->func('s_separate'), $self->add($n, 1), $c ]
3702 )),
3703 $self->any(
3704 [ $self->func('c_l_literal'), $n ],
3705 [ $self->func('c_l_folded'), $n ]
3706 )
3707 );
3708 };
3709  
3710  
3711  
3712 # [200]
3713 # s-l+block-collection(n,c) ::=
3714 # ( s-separate(n+1,c)
3715 # c-ns-properties(n+1,c) )?
3716 # s-l-comments
3717 # ( l+block-sequence(seq-spaces(n,c))
3718 # | l+block-mapping(n) )
3719  
3720 rule '200', s_l_block_collection => sub {
3721 my ($self, $n, $c) = @_;
3722 debug_rule("s_l_block_collection",$n,$c) if DEBUG;
3723 $self->all(
3724 $self->rep(0, 1,
3725 $self->all(
3726 [ $self->func('s_separate'), $self->add($n, 1), $c ],
3727 $self->any(
3728 $self->all(
3729 [ $self->func('c_ns_properties'), $self->add($n, 1), $c ],
3730 $self->func('s_l_comments')
3731 ),
3732 $self->all(
3733 $self->func('c_ns_tag_property'),
3734 $self->func('s_l_comments')
3735 ),
3736 $self->all(
3737 $self->func('c_ns_anchor_property'),
3738 $self->func('s_l_comments')
3739 )
3740 )
3741 )),
3742 $self->func('s_l_comments'),
3743 $self->any(
3744 [ $self->func('l_block_sequence'), [ $self->func('seq_spaces'), $n, $c ] ],
3745 [ $self->func('l_block_mapping'), $n ]
3746 )
3747 );
3748 };
3749  
3750  
3751  
3752 # [201]
3753 # seq-spaces(n,c) ::=
3754 # ( c = block-out => n-1 )
3755 # ( c = block-in => n )
3756  
3757 rule '201', seq_spaces => sub {
3758 my ($self, $n, $c) = @_;
3759 debug_rule("seq_spaces",$n,$c) if DEBUG;
3760 $self->flip(
3761 $c,
3762 {
3763 'block-in' => $n,
3764 'block-out' => $self->sub($n, 1),
3765 }
3766 );
3767 };
3768  
3769  
3770  
3771 # [202]
3772 # l-document-prefix ::=
3773 # c-byte-order-mark? l-comment*
3774  
3775 rule '202', l_document_prefix => sub {
3776 my ($self) = @_;
3777 debug_rule("l_document_prefix") if DEBUG;
3778 $self->all(
3779 $self->rep(0, 1, $self->func('c_byte_order_mark')),
3780 $self->rep2(0, undef, $self->func('l_comment'))
3781 );
3782 };
3783  
3784  
3785  
3786 # [203]
3787 # c-directives-end ::=
3788 # '-' '-' '-'
3789  
3790 rule '203', c_directives_end => sub {
3791 my ($self) = @_;
3792 debug_rule("c_directives_end") if DEBUG;
3793 $self->all(
3794 $self->chr('-'),
3795 $self->chr('-'),
3796 $self->chr('-'),
3797 $self->chk(
3798 '=',
3799 $self->any(
3800 $self->func('end_of_stream'),
3801 $self->func('s_white'),
3802 $self->func('b_break')
3803 )
3804 )
3805 );
3806 };
3807  
3808  
3809  
3810 # [204]
3811 # c-document-end ::=
3812 # '.' '.' '.'
3813  
3814 rule '204', c_document_end => sub {
3815 my ($self) = @_;
3816 debug_rule("c_document_end") if DEBUG;
3817 $self->all(
3818 $self->chr('.'),
3819 $self->chr('.'),
3820 $self->chr('.')
3821 );
3822 };
3823  
3824  
3825  
3826 # [205]
3827 # l-document-suffix ::=
3828 # c-document-end s-l-comments
3829  
3830 rule '205', l_document_suffix => sub {
3831 my ($self) = @_;
3832 debug_rule("l_document_suffix") if DEBUG;
3833 $self->all(
3834 $self->func('c_document_end'),
3835 $self->func('s_l_comments')
3836 );
3837 };
3838  
3839  
3840  
3841 # [206]
3842 # c-forbidden ::=
3843 # <start_of_line>
3844 # ( c-directives-end | c-document-end )
3845 # ( b-char | s-white | <end_of_file> )
3846  
3847 rule '206', c_forbidden => sub {
3848 my ($self) = @_;
3849 debug_rule("c_forbidden") if DEBUG;
3850 $self->all(
3851 $self->func('start_of_line'),
3852 $self->any(
3853 $self->func('c_directives_end'),
3854 $self->func('c_document_end')
3855 ),
3856 $self->any(
3857 $self->func('b_char'),
3858 $self->func('s_white'),
3859 $self->func('end_of_stream')
3860 )
3861 );
3862 };
3863  
3864  
3865  
3866 # [207]
3867 # l-bare-document ::=
3868 # s-l+block-node(-1,block-in)
3869 # <excluding_c-forbidden_content>
3870  
3871 rule '207', l_bare_document => sub {
3872 my ($self) = @_;
3873 debug_rule("l_bare_document") if DEBUG;
3874 $self->all(
3875 $self->exclude($self->func('c_forbidden')),
3876 [ $self->func('s_l_block_node'), -1, "block-in" ]
3877 );
3878 };
3879  
3880  
3881  
3882 # [208]
3883 # l-explicit-document ::=
3884 # c-directives-end
3885 # ( l-bare-document
3886 # | ( e-node s-l-comments ) )
3887  
3888 rule '208', l_explicit_document => sub {
3889 my ($self) = @_;
3890 debug_rule("l_explicit_document") if DEBUG;
3891 $self->all(
3892 $self->func('c_directives_end'),
3893 $self->any(
3894 $self->func('l_bare_document'),
3895 $self->all(
3896 $self->func('e_node'),
3897 $self->func('s_l_comments')
3898 )
3899 )
3900 );
3901 };
3902  
3903  
3904  
3905 # [209]
3906 # l-directive-document ::=
3907 # l-directive+
3908 # l-explicit-document
3909  
3910 rule '209', l_directive_document => sub {
3911 my ($self) = @_;
3912 debug_rule("l_directive_document") if DEBUG;
3913 $self->all(
3914 $self->rep(1, undef, $self->func('l_directive')),
3915 $self->func('l_explicit_document')
3916 );
3917 };
3918  
3919  
3920  
3921 # [210]
3922 # l-any-document ::=
3923 # l-directive-document
3924 # | l-explicit-document
3925 # | l-bare-document
3926  
3927 rule '210', l_any_document => sub {
3928 my ($self) = @_;
3929 debug_rule("l_any_document") if DEBUG;
3930 $self->any(
3931 $self->func('l_directive_document'),
3932 $self->func('l_explicit_document'),
3933 $self->func('l_bare_document')
3934 );
3935 };
3936  
3937  
3938  
3939 # [211]
3940 # l-yaml-stream ::=
3941 # l-document-prefix* l-any-document?
3942 # ( ( l-document-suffix+ l-document-prefix*
3943 # l-any-document? )
3944 # | ( l-document-prefix* l-explicit-document? ) )*
3945  
3946 rule '211', l_yaml_stream => sub {
3947 my ($self) = @_;
3948 debug_rule("l_yaml_stream") if DEBUG;
3949 $self->all(
3950 $self->func('l_document_prefix'),
3951 $self->rep(0, 1, $self->func('l_any_document')),
3952 $self->rep2(0, undef,
3953 $self->any(
3954 $self->all(
3955 $self->func('l_document_suffix'),
3956 $self->rep(0, undef, $self->func('l_document_prefix')),
3957 $self->rep2(0, 1, $self->func('l_any_document'))
3958 ),
3959 $self->all(
3960 $self->func('l_document_prefix'),
3961 $self->rep(0, 1, $self->func('l_explicit_document'))
3962 )
3963 ))
3964 );
3965 };
3966  
3967  
3968  
3969 1;
3970  
3971 ###
3972 # This is a parser class. It has a parse() method and parsing primitives for
3973 # the grammar. It calls methods in the receiver class, when a rule matches:
3974 ###
3975  
3976 use v5.12;
3977  
3978 package PerlYamlReferenceParserParser;
3979  
3980 use PerlYamlReferenceParserPrelude;
3981 use PerlYamlReferenceParserGrammar;
3982  
3983 use base 'PerlYamlReferenceParserGrammar';
3984  
3985 use constant TRACE => $ENV{TRACE};
3986  
3987 sub new {
3988 my ($class, $receiver) = @_;
3989  
3990 my $self = bless {
3991 receiver => $receiver,
3992 pos => 0,
3993 end => 0,
3994 state => [],
3995 trace_num => 0,
3996 trace_line => 0,
3997 trace_on => true,
3998 trace_off => 0,
3999 trace_info => ['', '', ''],
4000 }, $class;
4001  
4002 $receiver->{parser} = $self;
4003  
4004 return $self;
4005 }
4006  
4007 sub parse {
4008 my ($self, $input) = @_;
4009 $self->{input} = $input;
4010  
4011 $self->{end} = length $self->{input};
4012  
4013 $self->{trace_on} = not $self->trace_start if TRACE;
4014  
4015 my $ok;
4016 eval {
4017 $ok = $self->call($self->func('TOP'));
4018 $self->trace_flush;
4019 };
4020 if ($@) {
4021 $self->trace_flush;
4022 die $@;
4023 }
4024  
4025 die "Parser failed" if not $ok;
4026 die "Parser finished before end of input"
4027 if $self->{pos} < $self->{end};
4028  
4029 return true;
4030 }
4031  
4032 sub state_curr {
4033 my ($self) = @_;
4034 $self->{state}[-1] || {
4035 name => undef,
4036 doc => false,
4037 lvl => 0,
4038 beg => 0,
4039 end => 0,
4040 m => undef,
4041 t => undef,
4042 };
4043 }
4044  
4045 sub state_prev {
4046 my ($self) = @_;
4047 $self->{state}[-2]
4048 }
4049  
4050 sub state_push {
4051 my ($self, $name) = @_;
4052  
4053 my $curr = $self->state_curr;
4054  
4055 push @{$self->{state}}, {
4056 name => $name,
4057 doc => $curr->{doc},
4058 lvl => $curr->{lvl} + 1,
4059 beg => $self->{pos},
4060 end => undef,
4061 m => $curr->{m},
4062 t => $curr->{t},
4063 };
4064 }
4065  
4066 sub state_pop {
4067 my ($self) = @_;
4068 my $child = pop @{$self->{state}};
4069 my $curr = $self->state_curr;
4070 return unless defined $curr;
4071 $curr->{beg} = $child->{beg};
4072 $curr->{end} = $self->{pos};
4073 }
4074  
4075 sub call {
4076 my ($self, $func, $type) = @_;
4077 $type //= 'boolean';
4078  
4079 my $args = [];
4080 ($func, @$args) = @$func if isArray $func;
4081  
4082 return $func if isNumber $func or isString $func;
4083  
4084 FAIL "Bad call type '${\ typeof $func}' for '$func'"
4085 unless isFunction $func;
4086  
4087 my $trace = $func->{trace} //= $func->{name};
4088  
4089 $self->state_push($trace);
4090  
4091 $self->{trace_num}++;
4092 $self->trace('?', $trace, $args) if TRACE;
4093  
4094 if ($func->{name} eq 'l_bare_document') {
4095 $self->state_curr->{doc} = true;
4096 }
4097  
4098 @$args = map {
4099 isArray($_) ? $self->call($_, 'any') :
4100 isFunction($_) ? $_->{func}->() :
4101 $_;
4102 } @$args;
4103  
4104 my $pos = $self->{pos};
4105 $self->receive($func, 'try', $pos);
4106  
4107 my $value = $func->{func}->($self, @$args);
4108 while (isFunction($value) or isArray($value)) {
4109 $value = $self->call($value);
4110 }
4111  
4112 FAIL "Calling '$trace' returned '${\ typeof($value)}' instead of '$type'"
4113 if $type ne 'any' and typeof($value) ne $type;
4114  
4115 $self->{trace_num}++;
4116 if ($type ne 'boolean') {
4117 $self->trace('>', $value) if TRACE;
4118 }
4119 else {
4120 if ($value) {
4121 $self->trace('+', $trace) if TRACE;
4122 $self->receive($func, 'got', $pos);
4123 }
4124 else {
4125 $self->trace('x', $trace) if TRACE;
4126 $self->receive($func, 'not', $pos);
4127 }
4128 }
4129  
4130 $self->state_pop;
4131 return $value;
4132 }
4133  
4134 sub receive {
4135 my ($self, $func, $type, $pos) = @_;
4136  
4137 $func->{receivers} //= $self->make_receivers;
4138 my $receiver = $func->{receivers}{$type};
4139 return unless $receiver;
4140  
4141 $receiver->($self->{receiver}, {
4142 text => substr($self->{input}, $pos, $self->{pos}-$pos),
4143 state => $self->state_curr,
4144 start => $pos,
4145 });
4146 }
4147  
4148 sub make_receivers {
4149 my ($self) = @_;
4150 my $i = @{$self->{state}};
4151 my $names = [];
4152 my $n;
4153 while ($i > 0 and not(($n = $self->{state}[--$i]{name}) =~ /_/)) {
4154 if ($n =~ /^chr\((.)\)$/) {
4155 $n = hex_char $1;
4156 }
4157 else {
4158 $n =~ s/\(.*//;
4159 }
4160 unshift @$names, $n;
4161 }
4162 my $name = join '__', $n, @$names;
4163  
4164 return {
4165 try => $self->{receiver}->can("try__$name"),
4166 got => $self->{receiver}->can("got__$name"),
4167 not => $self->{receiver}->can("not__$name"),
4168 };
4169 }
4170  
4171 # Match all subrule methods:
4172 sub all {
4173 my ($self, @funcs) = @_;
4174 name all => sub {
4175 my $pos = $self->{pos};
4176 for my $func (@funcs) {
4177 FAIL '*** Missing function in @all group:', \@funcs
4178 unless defined $func;
4179  
4180 if (not $self->call($func)) {
4181 $self->{pos} = $pos;
4182 return false;
4183 }
4184 }
4185  
4186 return true;
4187 };
4188 }
4189  
4190 # Match any subrule method. Rules are tried in order and stops on first match:
4191 sub any {
4192 my ($self, @funcs) = @_;
4193 name any => sub {
4194 for my $func (@funcs) {
4195 if ($self->call($func)) {
4196 return true;
4197 }
4198 }
4199  
4200 return false;
4201 };
4202 }
4203  
4204 sub may {
4205 my ($self, $func) = @_;
4206 name may => sub {
4207 $self->call($func);
4208 };
4209 }
4210  
4211 # Repeat a rule a certain number of times:
4212 sub rep {
4213 my ($self, $min, $max, $func) = @_;
4214 name rep => sub {
4215 return false if defined $max and $max < 0;
4216 my $count = 0;
4217 my $pos = $self->{pos};
4218 my $pos_start = $pos;
4219 while (not(defined $max) or $count < $max) {
4220 last unless $self->call($func);
4221 last if $self->{pos} == $pos;
4222 $count++;
4223 $pos = $self->{pos};
4224 }
4225 if ($count >= $min and (not(defined $max) or $count <= $max)) {
4226 return true;
4227 }
4228 $self->{pos} = $pos_start;
4229 return false;
4230 }, "rep($min,${\ ($max // 'null')})";
4231 }
4232 sub rep2 {
4233 my ($self, $min, $max, $func) = @_;
4234 name rep2 => sub {
4235 return false if defined $max and $max < 0;
4236 my $count = 0;
4237 my $pos = $self->{pos};
4238 my $pos_start = $pos;
4239 while (not(defined $max) or $count < $max) {
4240 last unless $self->call($func);
4241 last if $self->{pos} == $pos;
4242 $count++;
4243 $pos = $self->{pos};
4244 }
4245 if ($count >= $min and (not(defined $max) or $count <= $max)) {
4246 return true;
4247 }
4248 $self->{pos} = $pos_start;
4249 return false;
4250 }, "rep2($min,${\ ($max // 'null')})";
4251 }
4252  
4253 # Call a rule depending on state value:
4254 sub case {
4255 my ($self, $var, $map) = @_;
4256 name case => sub {
4257 my $rule = $map->{$var};
4258 defined $rule or
4259 FAIL "Can't find '$var' in:", $map;
4260 $self->call($rule);
4261 }, "case($var,${\ stringify $map})";
4262 }
4263  
4264 # Call a rule depending on state value:
4265 sub flip {
4266 my ($self, $var, $map) = @_;
4267 my $value = $map->{$var};
4268 defined $value or
4269 FAIL "Can't find '$var' in:", $map;
4270 return $value if not ref $value;
4271 return $self->call($value, 'number');
4272 }
4273 name flip => \&flip;
4274  
4275 sub the_end {
4276 my ($self) = @_;
4277 return (
4278 $self->{pos} >= $self->{end} or (
4279 $self->state_curr->{doc} and
4280 $self->start_of_line and
4281 substr($self->{input}, $self->{pos}) =~
4282 /^(?:---|\.\.\.)(?=\s|\z)/
4283 )
4284 );
4285 }
4286  
4287 # Match a single char:
4288 sub chr {
4289 my ($self, $char) = @_;
4290 name chr => sub {
4291 return false if $self->the_end;
4292 if (
4293 $self->{pos} >= $self->{end} or (
4294 $self->state_curr->{doc} and
4295 $self->start_of_line and
4296 substr($self->{input}, $self->{pos}) =~
4297 /^(?:---|\.\.\.)(?=\s|\z)/
4298 )
4299 ) {
4300 return false;
4301 }
4302 if (substr($self->{input}, $self->{pos}, 1) eq $char) {
4303 $self->{pos}++;
4304 return true;
4305 }
4306 return false;
4307 }, "chr(${\ stringify($char)})";
4308 }
4309  
4310 # Match a char in a range:
4311 sub rng {
4312 my ($self, $low, $high) = @_;
4313 name rng => sub {
4314 return false if $self->the_end;
4315 if (
4316 $low le substr($self->{input}, $self->{pos}, 1) and
4317 substr($self->{input}, $self->{pos}, 1) le $high
4318 ) {
4319 $self->{pos}++;
4320 return true;
4321 }
4322 return false;
4323 }, "rng(${\ stringify($low)},${\ stringify($high)})";
4324 }
4325  
4326 # Must match first rule but none of others:
4327 sub but {
4328 my ($self, @funcs) = @_;
4329 name but => sub {
4330 return false if $self->the_end;
4331 my $pos1 = $self->{pos};
4332 return false unless $self->call($funcs[0]);
4333 my $pos2 = $self->{pos};
4334 $self->{pos} = $pos1;
4335 for my $func (@funcs[1..$#funcs]) {
4336 if ($self->call($func)) {
4337 $self->{pos} = $pos1;
4338 return false;
4339 }
4340 }
4341 $self->{pos} = $pos2;
4342 return true;
4343 }
4344 }
4345  
4346 sub chk {
4347 my ($self, $type, $expr) = @_;
4348 name chk => sub {
4349 my $pos = $self->{pos};
4350 $self->{pos}-- if $type eq '<=';
4351 my $ok = $self->call($expr);
4352 $self->{pos} = $pos;
4353 return $type eq '!' ? not($ok) : $ok;
4354 }, "chk($type, ${\ stringify $expr})";
4355 }
4356  
4357 sub set {
4358 my ($self, $var, $expr) = @_;
4359 name set => sub {
4360 my $value = $self->call($expr, 'any');
4361 return false if $value == -1;
4362 $value = $self->auto_detect if $value eq 'auto-detect';
4363 my $state = $self->state_prev;
4364 $state->{$var} = $value;
4365 if ($state->{name} ne 'all') {
4366 my $size = @{$self->{state}};
4367 for (my $i = 3; $i < $size; $i++) {
4368 FAIL "failed to traverse state stack in 'set'"
4369 if $i > $size - 2;
4370 $state = $self->{state}[0 - $i];
4371 $state->{$var} = $value;
4372 last if $state->{name} eq 's_l_block_scalar';
4373 }
4374 }
4375 return true;
4376 }, "set('$var', ${\ stringify $expr})";
4377 }
4378  
4379 sub max {
4380 my ($self, $max) = @_;
4381 name max => sub {
4382 return true;
4383 };
4384 }
4385  
4386 sub exclude {
4387 my ($self, $rule) = @_;
4388 name exclude => sub {
4389 return true;
4390 };
4391 }
4392  
4393 sub add {
4394 my ($self, $x, $y) = @_;
4395 name add => sub {
4396 $y = $self->call($y, 'number') if isFunction $y;
4397 FAIL "y is '${\ stringify $y}', not number in 'add'"
4398 unless isNumber $y;
4399 return $x + $y;
4400 }, "add($x,${\ stringify $y})";
4401 }
4402  
4403 sub sub {
4404 my ($self, $x, $y) = @_;
4405 name sub => sub {
4406 return $x - $y;
4407 }, "sub($x,$y)";
4408 }
4409  
4410 # This method does not need to return a function since it is never
4411 # called in the grammar.
4412 sub match {
4413 my ($self) = @_;
4414 my $state = $self->{state};
4415 my $i = @$state - 1;
4416 while ($i > 0 && not defined $state->[$i]{end}) {
4417 FAIL "Can't find match" if $i == 1;
4418 $i--;
4419 }
4420  
4421 my ($beg, $end) = @{$self->{state}[$i]}{qw<beg end>};
4422 return substr($self->{input}, $beg, ($end - $beg));
4423 }
4424 name match => \&match;
4425  
4426 sub len {
4427 my ($self, $str) = @_;
4428 name len => sub {
4429 $str = $self->call($str, 'string') unless isString($str);
4430 return length $str;
4431 };
4432 }
4433  
4434 sub ord {
4435 my ($self, $str) = @_;
4436 name ord => sub {
4437 # Should be `$self->call($str, 'string')`, but... Perl
4438 $str = $self->call($str, 'number') unless isString($str);
4439 return ord($str) - 48;
4440 };
4441 }
4442  
4443 sub if {
4444 my ($self, $test, $do_if_true) = @_;
4445 name if => sub {
4446 $test = $self->call($test, 'boolean') unless isBoolean $test;
4447 if ($test) {
4448 $self->call($do_if_true);
4449 return true;
4450 }
4451 return false;
4452 };
4453 }
4454  
4455 sub lt {
4456 my ($self, $x, $y) = @_;
4457 name lt => sub {
4458 $x = $self->call($x, 'number') unless isNumber($x);
4459 $y = $self->call($y, 'number') unless isNumber($y);
4460 return $x < $y ? true : false;
4461 }, "lt(${\ stringify $x},${\ stringify $y})";
4462 }
4463  
4464 sub le {
4465 my ($self, $x, $y) = @_;
4466 name le => sub {
4467 $x = $self->call($x, 'number') unless isNumber($x);
4468 $y = $self->call($y, 'number') unless isNumber($y);
4469 return $x <= $y ? true : false;
4470 }, "le(${\ stringify $x},${\ stringify $y})";
4471 }
4472  
4473 sub m {
4474 my ($self) = @_;
4475 name m => sub {
4476 $self->state_curr->{m};
4477 };
4478 }
4479  
4480 sub t {
4481 my ($self) = @_;
4482 name t => sub {
4483 $self->state_curr->{t};
4484 };
4485 }
4486  
4487 #------------------------------------------------------------------------------
4488 # Special grammar rules
4489 #------------------------------------------------------------------------------
4490 sub start_of_line {
4491 my ($self) = @_;
4492 (
4493 $self->{pos} == 0 ||
4494 $self->{pos} >= $self->{end} ||
4495 substr($self->{input}, $self->{pos} - 1, 1) eq "\n"
4496 ) ? true : false;
4497 }
4498 name 'start_of_line', \&start_of_line;
4499  
4500 sub end_of_stream {
4501 my ($self) = @_;
4502 ($self->{pos} >= $self->{end}) ? true : false;
4503 }
4504 name 'end_of_stream', \&end_of_stream;
4505  
4506 sub empty { true }
4507 name 'empty', \&empty;
4508  
4509 sub auto_detect_indent {
4510 my ($self, $n) = @_;
4511 my $pos = $self->{pos};
4512 my $in_seq = ($pos > 0 && substr($self->{input}, $pos - 1, 1) =~ /^[\-\?\:]$/);
4513 substr($self->{input}, $pos) =~ /^
4514 (
4515 (?:
4516 \ *
4517 (?:\#.*)?
4518 \n
4519 )*
4520 )
4521 (\ *)
4522 /x or FAIL "auto_detect_indent";
4523 my $pre = $1;
4524 my $m = length($2);
4525 if ($in_seq and not length $pre) {
4526 $m++ if $n == -1;
4527 }
4528 else {
4529 $m -= $n;
4530 }
4531 $m = 0 if $m < 0;
4532 return $m;
4533 }
4534 name 'auto_detect_indent', \&auto_detect_indent;
4535  
4536 sub auto_detect {
4537 my ($self, $n) = @_;
4538 substr($self->{input}, $self->{pos}) =~ /^.*\n(?:\ *\n)*(\ *)/
4539 or return 1;
4540 my $m = length($1) - $n;
4541 $m = 1 if $m < 1;
4542 return $m;
4543 }
4544 name 'auto_detect', \&auto_detect;
4545  
4546 #------------------------------------------------------------------------------
4547 # Trace debugging
4548 #------------------------------------------------------------------------------
4549 sub trace_start {
4550 '' || "$ENV{TRACE_START}";
4551 }
4552  
4553 sub trace_quiet {
4554 return [] if $ENV{DEBUG};
4555  
4556 my @small = (
4557 'b_as_line_feed',
4558 's_indent',
4559 'nb_char',
4560 );
4561  
4562 my @noisy = (
4563 'c_directives_end',
4564 'c_l_folded',
4565 'c_l_literal',
4566 'c_ns_alias_node',
4567 'c_ns_anchor_property',
4568 'c_ns_tag_property',
4569 'l_directive_document',
4570 'l_document_prefix',
4571 'ns_flow_content',
4572 'ns_plain',
4573 's_l_comments',
4574 's_separate',
4575 );
4576  
4577 return [
4578 split(',', ($ENV{TRACE_QUIET} || '')),
4579 @noisy,
4580 ];
4581 }
4582  
4583 sub trace {
4584 my ($self, $type, $call, $args) = @_;
4585 $args //= [];
4586  
4587 $call = "'$call'" if $call =~ /^($| |.* $)/;
4588 return unless $self->{trace_on} or $call eq $self->trace_start;
4589  
4590 my $level = $self->state_curr->{lvl};
4591 my $indent = ' ' x $level;
4592 if ($level > 0) {
4593 my $l = length "$level";
4594 $indent = "$level" . substr($indent, $l);
4595 }
4596  
4597 my $input = substr($self->{input}, $self->{pos});
4598 $input = substr($input, 0, 30) . '…'
4599 if length($input) > 30;
4600 $input =~ s/\t/\\t/g;
4601 $input =~ s/\r/\\r/g;
4602 $input =~ s/\n/\\n/g;
4603  
4604 my $line = sprintf(
4605 "%s%s %-40s %4d '%s'\n",
4606 $indent,
4607 $type,
4608 $self->trace_format_call($call, $args),
4609 $self->{pos},
4610 $input,
4611 );
4612  
4613 if ($ENV{DEBUG}) {
4614 warn sprintf "%6d %s",
4615 $self->{trace_num}, $line;
4616 return;
4617 }
4618  
4619 my $trace_info = undef;
4620 $level = "${level}_$call";
4621 if ($type eq '?' and not $self->{trace_off}) {
4622 $trace_info = [$type, $level, $line, $self->{trace_num}];
4623 }
4624 if (grep $_ eq $call, @{$self->trace_quiet}) {
4625 $self->{trace_off} += $type eq '?' ? 1 : -1;
4626 }
4627 if ($type ne '?' and not $self->{trace_off}) {
4628 $trace_info = [$type, $level, $line, $self->{trace_num}];
4629 }
4630  
4631 if (defined $trace_info) {
4632 my ($prev_type, $prev_level, $prev_line, $trace_num) =
4633 @{$self->{trace_info}};
4634 if ($prev_type eq '?' and $prev_level eq $level) {
4635 $trace_info->[1] = '';
4636 if ($line =~ /^\d*\ *\+/) {
4637 $prev_line =~ s/\?/=/;
4638 }
4639 else {
4640 $prev_line =~ s/\?/!/;
4641 }
4642 }
4643 if ($prev_level) {
4644 warn sprintf "%5d %6d %s",
4645 ++$self->{trace_line}, $trace_num, $prev_line;
4646 }
4647  
4648 $self->{trace_info} = $trace_info;
4649 }
4650  
4651 if ($call eq $self->trace_start) {
4652 $self->{trace_on} = not $self->{trace_on};
4653 }
4654 }
4655  
4656 sub trace_format_call {
4657 my ($self, $call, $args) = @_;
4658 return $call unless @$args;
4659 my $list = join ',', map stringify($_), @$args;
4660 return "$call($list)";
4661 }
4662  
4663 sub trace_flush {
4664 my ($self) = @_;
4665 my ($type, $level, $line, $count) = @{$self->{trace_info}};
4666 if (my $line = $self->{trace_info}[2]) {
4667 warn sprintf "%5d %6d %s",
4668 ++$self->{trace_line}, $count, $line;
4669 }
4670 }
4671  
4672 1;
4673  
4674 # vim: sw=2:
4675  
4676  
4677 use v5.12;
4678 package PerlYamlReferenceParserReceiver;
4679 use PerlYamlReferenceParserPrelude;
4680  
4681 sub stream_start_event {
4682 { event => 'stream_start' };
4683 }
4684 sub stream_end_event {
4685 { event => 'stream_end' };
4686 }
4687 sub document_start_event {
4688 { event => 'document_start', explicit => (shift || false) };
4689 }
4690 sub document_end_event {
4691 { event => 'document_end', explicit => (shift || false) };
4692 }
4693 sub mapping_start_event {
4694 { event => 'mapping_start', flow => (shift || false) };
4695 }
4696 sub mapping_end_event {
4697 { event => 'mapping_end' };
4698 }
4699 sub sequence_start_event {
4700 { event => 'sequence_start', flow => (shift || false) };
4701 }
4702 sub sequence_end_event {
4703 { event => 'sequence_end' };
4704 }
4705 sub scalar_event {
4706 my ($style, $value) = @_;
4707 { event => 'scalar', style => $style, value => $value };
4708 }
4709 sub alias_event {
4710 { event => 'alias', name => (shift) };
4711 }
4712 sub cache {
4713 { text => (shift) };
4714 }
4715  
4716 sub new {
4717 my ($class, %self) = @_;
4718 bless {
4719 %self,
4720 event => [],
4721 cache => [],
4722 }, $class;
4723 }
4724  
4725 sub send {
4726 my ($self, $event) = @_;
4727 if (my $callback = $self->{callback}) {
4728 $callback->($event);
4729 }
4730 else {
4731 push @{$self->{event}}, $event;
4732 }
4733 }
4734  
4735 sub add {
4736 my ($self, $event) = @_;
4737 if (defined $event->{event}) {
4738 if (my $anchor = $self->{anchor}) {
4739 $event->{anchor} = delete $self->{anchor};
4740 }
4741 if (my $tag = $self->{tag}) {
4742 $event->{tag} = delete $self->{tag};
4743 }
4744 }
4745 $self->push($event);
4746 return $event;
4747 }
4748  
4749 sub push {
4750 my ($self, $event) = @_;
4751 if (@{$self->{cache}}) {
4752 push @{$self->{cache}[-1]}, $event;
4753 }
4754 else {
4755 if ($event->{event} =~ /(mapping_start|sequence_start|scalar)/) {
4756 $self->check_document_start;
4757 }
4758 $self->send($event);
4759 }
4760 }
4761  
4762 sub cache_up {
4763 my ($self, $event) = @_;
4764 CORE::push @{$self->{cache}}, [];
4765 $self->add($event) if $event;
4766 }
4767  
4768 sub cache_down {
4769 my ($self, $event) = @_;
4770 my $events = pop @{$self->{cache}} or FAIL 'cache_down';
4771 $self->push($_) for @$events;
4772 $self->add($event) if $event;
4773 }
4774  
4775 sub cache_drop {
4776 my ($self) = @_;
4777 my $events = pop @{$self->{cache}} or FAIL 'cache_drop';
4778 return $events;
4779 }
4780  
4781 sub cache_get {
4782 my ($self, $type) = @_;
4783 return
4784 $self->{cache}[-1] &&
4785 $self->{cache}[-1][0] &&
4786 $self->{cache}[-1][0]{event} eq $type &&
4787 $self->{cache}[-1][0];
4788 }
4789  
4790 sub check_document_start {
4791 my ($self) = @_;
4792 return unless $self->{document_start};
4793 $self->send($self->{document_start});
4794 delete $self->{document_start};
4795 $self->{document_end} = document_end_event;
4796 }
4797  
4798 sub check_document_end {
4799 my ($self) = @_;
4800 return unless $self->{document_end};
4801 $self->send($self->{document_end});
4802 delete $self->{document_end};
4803 $self->{document_start} = document_start_event;
4804 }
4805  
4806 #------------------------------------------------------------------------------
4807 sub try__l_yaml_stream {
4808 my ($self) = @_;
4809 $self->add(stream_start_event);
4810 $self->{tag_map} = {};
4811 $self->{document_start} = document_start_event;
4812 delete $self->{document_end};
4813 }
4814 sub got__l_yaml_stream {
4815 my ($self) = @_;
4816 $self->check_document_end;
4817 $self->add(stream_end_event);
4818 }
4819  
4820 sub got__c_tag_handle {
4821 my ($self, $o) = @_;
4822 $self->{tag_handle} = $o->{text};
4823 }
4824 sub got__ns_tag_prefix {
4825 my ($self, $o) = @_;
4826 $self->{tag_map}{$self->{tag_handle}} = $o->{text};
4827 }
4828  
4829 sub got__c_directives_end {
4830 my ($self) = @_;
4831 $self->check_document_end;
4832 $self->{document_start}{explicit} = true;
4833 }
4834 sub got__c_document_end {
4835 my ($self) = @_;
4836 $self->{document_end}{explicit} = true
4837 if defined $self->{document_end};
4838 $self->check_document_end;
4839 }
4840  
4841 sub got__c_flow_mapping__all__x7b { $_[0]->add(mapping_start_event(true)) }
4842 sub got__c_flow_mapping__all__x7d { $_[0]->add(mapping_end_event) }
4843  
4844 sub got__c_flow_sequence__all__x5b { $_[0]->add(sequence_start_event(true)) }
4845 sub got__c_flow_sequence__all__x5d { $_[0]->add(sequence_end_event) }
4846  
4847 sub try__l_block_mapping { $_[0]->cache_up(mapping_start_event) }
4848 sub got__l_block_mapping { $_[0]->cache_down(mapping_end_event) }
4849 sub not__l_block_mapping { $_[0]->cache_drop }
4850  
4851 sub try__l_block_sequence { $_[0]->cache_up(sequence_start_event) }
4852 sub got__l_block_sequence { $_[0]->cache_down(sequence_end_event) }
4853 sub not__l_block_sequence {
4854 my ($self) = @_;
4855 my $event = $_[0]->cache_drop->[0];
4856 $self->{anchor} = $event->{anchor};
4857 $self->{tag} = $event->{tag};
4858 }
4859  
4860 sub try__ns_l_compact_mapping { $_[0]->cache_up(mapping_start_event) }
4861 sub got__ns_l_compact_mapping { $_[0]->cache_down(mapping_end_event) }
4862 sub not__ns_l_compact_mapping { $_[0]->cache_drop }
4863  
4864 sub try__ns_l_compact_sequence { $_[0]->cache_up(sequence_start_event) }
4865 sub got__ns_l_compact_sequence { $_[0]->cache_down(sequence_end_event) }
4866 sub not__ns_l_compact_sequence { $_[0]->cache_drop }
4867  
4868 sub try__ns_flow_pair { $_[0]->cache_up(mapping_start_event(true)) }
4869 sub got__ns_flow_pair { $_[0]->cache_down(mapping_end_event) }
4870 sub not__ns_flow_pair { $_[0]->cache_drop }
4871  
4872 sub try__ns_l_block_map_implicit_entry { $_[0]->cache_up }
4873 sub got__ns_l_block_map_implicit_entry { $_[0]->cache_down }
4874 sub not__ns_l_block_map_implicit_entry { $_[0]->cache_drop }
4875  
4876 sub try__c_l_block_map_explicit_entry { $_[0]->cache_up }
4877 sub got__c_l_block_map_explicit_entry { $_[0]->cache_down }
4878 sub not__c_l_block_map_explicit_entry { $_[0]->cache_drop }
4879  
4880 sub try__c_ns_flow_map_empty_key_entry { $_[0]->cache_up }
4881 sub got__c_ns_flow_map_empty_key_entry { $_[0]->cache_down }
4882 sub not__c_ns_flow_map_empty_key_entry { $_[0]->cache_drop }
4883  
4884 sub got__ns_plain {
4885 my ($self, $o) = @_;
4886 my $text = $o->{text};
4887 $text =~ s/(?:[\ \t]*\r?\n[\ \t]*)/\n/g;
4888 $text =~ s/(\n)(\n*)/length($2) ? $2 : ' '/ge;
4889 $self->add(scalar_event(plain => $text));
4890 }
4891  
4892 sub got__c_single_quoted {
4893 my ($self, $o) = @_;
4894 my $text = substr($o->{text}, 1, -1);
4895 $text =~ s/(?:[\ \t]*\r?\n[\ \t]*)/\n/g;
4896 $text =~ s/(\n)(\n*)/length($2) ? $2 : ' '/ge;
4897 $text =~ s/''/'/g;
4898 $self->add(scalar_event(single => $text));
4899 }
4900  
4901 sub got__c_double_quoted {
4902 my ($self, $o) = @_;
4903 my $text = substr($o->{text}, 1, -1);
4904 $text =~ s/(?:[\ \t]*\r?\n[\ \t]*)/\n/g;
4905 $text =~ s/\\\n[\ \t]*//g;
4906 $text =~ s/(\n)(\n*)/length($2) ? $2 : ' '/ge;
4907 $text =~ s/\\(["\/])/$1/g;
4908 $text =~ s/\\ / /g;
4909 $text =~ s/\\b/\b/g;
4910 $text =~ s/\\t/\t/g;
4911 $text =~ s/\\n/\n/g;
4912 $text =~ s/\\r/\r/g;
4913 $text =~ s/\\x([0-9a-fA-F]{2})/chr(hex($1))/eg;
4914 $text =~ s/\\u([0-9a-fA-F]{4})/chr(hex($1))/eg;
4915 $text =~ s/\\U([0-9a-fA-F]{8})/chr(hex($1))/eg;
4916 $text =~ s/\\\\/\\/g;
4917 $self->add(scalar_event(double => $text));
4918 }
4919  
4920 sub got__l_empty {
4921 my ($self) = @_;
4922 $self->add(cache '') if $self->{in_scalar};
4923 }
4924 sub got__l_nb_literal_text__all__rep2 {
4925 my ($self, $o) = @_;
4926 $self->add(cache $o->{text});
4927 }
4928 sub try__c_l_literal {
4929 my ($self) = @_;
4930 $self->{in_scalar} = true;
4931 $self->cache_up;
4932 }
4933 sub got__c_l_literal {
4934 my ($self) = @_;
4935 delete $self->{in_scalar};
4936 my $lines = $self->cache_drop;
4937 pop @$lines if @$lines and $lines->[-1]{text} eq '';
4938 my $text = join '', map "$_->{text}\n", @$lines;
4939 my $t = $self->{parser}->state_curr->{t};
4940 if ($t eq 'clip') {
4941 $text =~ s/\n+\z/\n/;
4942 }
4943 elsif ($t eq 'strip') {
4944 $text =~ s/\n+\z//;
4945 }
4946 $self->add(scalar_event(literal => $text));
4947 }
4948 sub not__c_l_literal {
4949 my ($self) = @_;
4950 delete $self->{in_scalar};
4951 $_[0]->cache_drop;
4952 }
4953  
4954 sub got__ns_char {
4955 my ($self, $o) = @_;
4956 $self->{first} = $o->{text} if $self->{in_scalar};
4957 }
4958 sub got__s_white {
4959 my ($self, $o) = @_;
4960 $self->{first} = $o->{text} if $self->{in_scalar};
4961 }
4962 sub got__s_nb_folded_text__all__rep {
4963 my ($self, $o) = @_;
4964 $self->add(cache "$self->{first}$o->{text}");
4965 }
4966 sub got__s_nb_spaced_text__all__rep {
4967 my ($self, $o) = @_;
4968 $self->add(cache "$self->{first}$o->{text}");
4969 }
4970 sub try__c_l_folded {
4971 my ($self) = @_;
4972 $self->{in_scalar} = true;
4973 $self->{first} = '';
4974 $self->cache_up;
4975 }
4976 sub got__c_l_folded {
4977 my ($self) = @_;
4978 delete $self->{in_scalar};
4979  
4980 my @lines = map $_->{text}, @{$self->cache_drop};
4981 my $text = join "\n", @lines;
4982 $text =~ s/^(\S.*)\n(?=\S)/$1 /gm;
4983 $text =~ s/^(\S.*)\n(\n+)/$1$2/gm;
4984 $text =~ s/^([\ \t]+\S.*)\n(\n+)(?=\S)/$1$2/gm;
4985 $text .= "\n";
4986  
4987 my $t = $self->{parser}->state_curr->{t};
4988 if ($t eq 'clip') {
4989 $text =~ s/\n+\z/\n/;
4990 $text = '' if $text eq "\n";
4991 }
4992 elsif ($t eq 'strip') {
4993 $text =~ s/\n+\z//;
4994 }
4995 $self->add(scalar_event(folded => $text));
4996 }
4997 sub not__c_l_folded {
4998 my ($self) = @_;
4999 delete $self->{in_scalar};
5000 $_[0]->cache_drop;
5001 }
5002  
5003 sub got__e_scalar { $_[0]->add(scalar_event(plain => '')) }
5004  
5005 sub not__s_l_block_collection__all__rep__all__any__all {
5006 my ($self) = @_;
5007 delete $self->{anchor};
5008 delete $self->{tag};
5009 }
5010  
5011 sub got__c_ns_anchor_property {
5012 my ($self, $o) = @_;
5013 $self->{anchor} = substr($o->{text}, 1);
5014 }
5015  
5016 sub got__c_ns_tag_property {
5017 my ($self, $o) = @_;
5018 my $tag = $o->{text};
5019 my $prefix;
5020 if ($tag =~ /^!<(.*)>$/) {
5021 $self->{tag} = $1;
5022 }
5023 elsif ($tag =~ /^!!(.*)/) {
5024 if (defined($prefix = $self->{tag_map}{'!!'})) {
5025 $self->{tag} = $prefix . substr($tag, 2);
5026 }
5027 else {
5028 $self->{tag} = "tag:yaml.org,2002:$1";
5029 }
5030 }
5031 elsif (
5032 $tag =~ /^(!.*?!)/ and
5033 defined($prefix = $self->{tag_map}{$1})
5034 ) {
5035 $self->{tag} = $prefix . substr($tag, length($1));
5036 }
5037 elsif (defined($prefix = $self->{tag_map}{'!'})) {
5038 $self->{tag} = $prefix . substr($tag, 1);
5039 }
5040 else {
5041 $self->{tag} = $tag;
5042 }
5043 $self->{tag} =~ s/%([0-9a-fA-F]{2})/chr(hex($1))/eg;
5044 }
5045  
5046 sub got__c_ns_alias_node {
5047 my ($self, $o) = @_;
5048 my $name = $o->{text};
5049 $name =~ s/^\*//;
5050 $self->add(alias_event($name));
5051 }
5052  
5053 1;
5054  
5055 # vim: sw=2:
5056  
5057  
5058 use v5.12;
5059 package PerlYamlReferenceParserTestReceiver;
5060 use base 'PerlYamlReferenceParserReceiver';
5061  
5062 use PerlYamlReferenceParserPrelude;
5063  
5064 my $event_map = {
5065 stream_start => '+STR',
5066 stream_end => '-STR',
5067 document_start => '+DOC',
5068 document_end => '-DOC',
5069 mapping_start => '+MAP',
5070 mapping_end => '-MAP',
5071 sequence_start => '+SEQ',
5072 sequence_end => '-SEQ',
5073 scalar => '=VAL',
5074 alias => '=ALI',
5075 };
5076  
5077 my $style_map = {
5078 plain => ':',
5079 single => "'",
5080 double => '"',
5081 literal => '|',
5082 folded => '>',
5083 };
5084  
5085 sub output {
5086 my ($self) = @_;
5087 join '', map {
5088 my $type = $event_map->{$_->{event}};
5089 my @event = ($type);
5090 push @event, '---' if $type eq '+DOC' and $_->{explicit};
5091 push @event, '...' if $type eq '-DOC' and $_->{explicit};
5092 push @event, '{}' if $type eq '+MAP' and $_->{flow};
5093 push @event, '[]' if $type eq '+SEQ' and $_->{flow};
5094 push @event, "&$_->{anchor}" if $_->{anchor};
5095 push @event, "<$_->{tag}>" if $_->{tag};
5096 push @event, "*$_->{name}" if $_->{name};
5097 if (exists $_->{value}) {
5098 my $style = $style_map->{$_->{style}};
5099 my $value = $_->{value};
5100 $value =~ s/\\/\\\\/g;
5101 $value =~ s/\x08/\\b/g;
5102 $value =~ s/\t/\\t/g;
5103 $value =~ s/\n/\\n/g;
5104 $value =~ s/\r/\\r/g;
5105 $value =~ s/\x20\z/<SPC>/;
5106 push @event, "$style$value";
5107 }
5108 join(' ', @event) . "\n";
5109 } @{$self->{event}};
5110 }
5111  
5112 1;
5113  
5114 # vim: sw=2:
5115  
↑ Summary