blib/lib/YAML/PP/Lexer.pm

filter: Statementstmt 96.3% 573 / 595 Branchbran 94.1% 256 / 272 Conditioncond 95.4% 42 / 44 MC/DCmcdc 93.1% 27 / 29 Subroutinesub 97.2% 35 / 36 Podpod 0.0% 0 / 24 totaltotal 93.3% 933 / 1000 CC 152 SCAR 28.4
CC
152
Cov
96%
_fetch_next_tokens
28.3
fetch_plain
27.0
fetch_block
23.0
CRAP 17.1
« blib/lib/YAML/PP/Common.pm ↑ Summary blib/lib/YAML/PP/Highlight.pm »
1 52 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 52 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package YAML::PP::Lexer;
4  
5 52 our $VERSION = 'v0.43.0'; # VERSION
6  
7 52 ▶use constant TRACE => $ENV{YAML_PP_TRACE} ? 1 : 0;
Subroutine BEGIN: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'YAML_PP_TRACE'} ? : 0 52 52
8 52 ▶use constant DEBUG => ($ENV{YAML_PP_DEBUG} || $ENV{YAML_PP_TRACE}) ? 1 : 0;
Subroutine BEGIN: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'YAML_PP_DEBUG'} || $ENV{'YAML_PP_TRACE'} ? : 1 51 52
Condition66%2/3
$ENV{"YAML_PP_DEBUG"} or $ENV{"YAML_PP_TRACE"}
l!l&&r!l&&!r
1051
MC/DC50%1/2
$ENV{"YAML_PP_DEBUG"} or $ENV{"YAML_PP_TRACE"}
$ENV{"YAML_PP_DEBUG"} $ENV{"YAML_PP_TRACE"}
Truth table66%2/3
A or B
A= $ENV{"YAML_PP_DEBUG"}B= $ENV{"YAML_PP_TRACE"}
ABresult
1X1
011
000
9  
10 52 ▶use YAML::PP::Grammar qw/ $GRAMMAR /;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 52 ▶use Carp qw/ croak /;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 4776 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
14 4776 my ($class, %args) = @_;
15 my $self = bless {
16 reader => $args{reader},
17 4776 }, $class;
18 4776 $self->init;
19 4776 return $self;
20 }
21  
22 20156 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
23 20156 my ($self) = @_;
24 20156 $self->{next_tokens} = [];
25 20156 $self->{next_line} = undef;
26 20156 $self->{line} = 0;
27 20156 $self->{offset} = 0;
28 20156 $self->{flowcontext} = 0;
29 }
30  
31 113258 ▶sub next_line { return $_[0]->{next_line} }
Subroutine next_line: called CC=1 SCAR=0.0
Pod undocumented
32 90058 ▶sub set_next_line { $_[0]->{next_line} = $_[1] }
Subroutine set_next_line: called CC=1 SCAR=0.0
Pod undocumented
33 51058 ▶sub reader { return $_[0]->{reader} }
Subroutine reader: called CC=1 SCAR=0.0
Pod undocumented
34 7690 ▶sub set_reader { $_[0]->{reader} = $_[1] }
Subroutine set_reader: called CC=1 SCAR=0.0
Pod undocumented
35 189900 ▶sub next_tokens { return $_[0]->{next_tokens} }
Subroutine next_tokens: called CC=1 SCAR=0.0
Pod undocumented
36 400903 ▶sub line { return $_[0]->{line} }
Subroutine line: called CC=1 SCAR=0.0
Pod undocumented
37 0 ▶sub set_line { $_[0]->{line} = $_[1] }
Subroutine set_line: not called CC=1 SCAR=6.9
Pod undocumented
38 140273 ▶sub offset { return $_[0]->{offset} }
Subroutine offset: called CC=1 SCAR=0.0
Pod undocumented
39 140171 ▶sub set_offset { $_[0]->{offset} = $_[1] }
Subroutine set_offset: called CC=1 SCAR=0.0
Pod undocumented
40 39099 ▶sub inc_line { return $_[0]->{line}++ }
Subroutine inc_line: called CC=1 SCAR=0.0
Pod undocumented
41 97786 ▶sub context { return $_[0]->{context} }
Subroutine context: called CC=1 SCAR=0.0
Pod undocumented
42 3936 ▶sub set_context { $_[0]->{context} = $_[1] }
Subroutine set_context: called CC=1 SCAR=0.0
Pod undocumented
43 175511 ▶sub flowcontext { return $_[0]->{flowcontext} }
Subroutine flowcontext: called CC=1 SCAR=0.0
Pod undocumented
44 5291 ▶sub set_flowcontext { $_[0]->{flowcontext} = $_[1] }
Subroutine set_flowcontext: called CC=1 SCAR=0.0
Pod undocumented
45 27609 ▶sub block { return $_[0]->{block} }
Subroutine block: called CC=1 SCAR=0.0
Pod undocumented
46 39179 ▶sub set_block { $_[0]->{block} = $_[1] }
Subroutine set_block: called CC=1 SCAR=0.0
Pod undocumented
47  
48 52 my $RE_WS = '[\t ]';
49 52 my $RE_LB = '[\r\n]';
50 52 my $RE_DOC_END = qr/\A(\.\.\.)(?=$RE_WS|$)/m;
51 52 my $RE_DOC_START = qr/\A(---)(?=$RE_WS|$)/m;
52 52 my $RE_EOL = qr/\A($RE_WS+#.*|$RE_WS+)\z/;
53 #my $RE_COMMENT_EOL = qr/\A(#.*)?(?:$RE_LB|\z)/;
54  
55 #ns-word-char ::= ns-dec-digit | ns-ascii-letter | “-”
56 52 my $RE_NS_WORD_CHAR = '[0-9A-Za-z-]';
57 52 my $RE_URI_CHAR = '(?:' . '%[0-9a-fA-F]{2}' .'|'. q{[0-9A-Za-z#;/?:@&=+$,_.!*'\(\)\[\]-]} . ')';
58 52 my $RE_NS_TAG_CHAR = '(?:' . '%[0-9a-fA-F]{2}' .'|'. q{[0-9A-Za-z#;/?:@&=+$_.~*'\(\)-]} . ')';
59  
60 # [#x21-#x7E] /* 8 bit */
61 # | #x85 | [#xA0-#xD7FF] | [#xE000-#xFFFD] /* 16 bit */
62 # | [#x10000-#x10FFFF] /* 32 bit */
63  
64 #nb-char ::= c-printable - b-char - c-byte-order-mark
65 #my $RE_NB_CHAR = '[\x21-\x7E]';
66 52 my $RE_ANCHOR_CAR = '[\x21-\x2B\x2D-\x5A\x5C\x5E-\x7A\x7C\x7E\xA0-\xFF\x{100}-\x{10FFFF}]';
67  
68 52 my $RE_PLAIN_START = '[\x21\x22\x24-\x39\x3B-\x7E\xA0-\xFF\x{100}-\x{10FFFF}]';
69 52 my $RE_PLAIN_END = '[\x21-\x39\x3B-\x7E\x85\xA0-\x{D7FF}\x{E000}-\x{FEFE}\x{FF00}-\x{FFFD}\x{10000}-\x{10FFFF}]';
70 52 my $RE_PLAIN_FIRST = '[\x24\x28-\x29\x2B\x2E-\x39\x3B-\x3D\x41-\x5A\x5C\x5E-\x5F\x61-\x7A\x7E\xA0-\xFF\x{100}-\x{10FFFF}]';
71  
72 52 my $RE_PLAIN_START_FLOW = '[\x21\x22\x24-\x2B\x2D-\x39\x3B-\x5A\x5C\x5E-\x7A\x7C\x7E\xA0-\xFF\x{100}-\x{10FFFF}]';
73 52 my $RE_PLAIN_END_FLOW = '[\x21-\x2B\x2D-\x39\x3B-\x5A\x5C\x5E-\x7A\x7C\x7E\x85\xA0-\x{D7FF}\x{E000}-\x{FEFE}\x{FF00}-\x{FFFD}\x{10000}-\x{10FFFF}]';
74 52 my $RE_PLAIN_FIRST_FLOW = '[\x24\x28-\x29\x2B\x2E-\x39\x3B-\x3D\x41-\x5A\x5C\x5E-\x5F\x61-\x7A\x7C\x7E\xA0-\xFF\x{100}-\x{10FFFF}]';
75 # c-indicators
76 #! 21
77 #" 22
78 ## 23
79 #% 25
80 #& 26
81 #' 27
82 #* 2A
83 #, 2C FLOW
84 #- 2D XX
85 #: 3A XX
86 #> 3E
87 #? 3F XX
88 #@ 40
89 #[ 5B FLOW
90 #] 5D FLOW
91 #` 60
92 #{ 7B FLOW
93 #| 7C
94 #} 7D FLOW
95  
96  
97 52 my $RE_PLAIN_WORD = "(?::+$RE_PLAIN_END|$RE_PLAIN_START)(?::+$RE_PLAIN_END|$RE_PLAIN_END)*";
98 52 my $RE_PLAIN_FIRST_WORD = "(?:[:?-]+$RE_PLAIN_END|$RE_PLAIN_FIRST)(?::+$RE_PLAIN_END|$RE_PLAIN_END)*";
99 52 my $RE_PLAIN_WORDS = "(?:$RE_PLAIN_FIRST_WORD(?:$RE_WS+$RE_PLAIN_WORD)*)";
100 52 my $RE_PLAIN_WORDS2 = "(?:$RE_PLAIN_WORD(?:$RE_WS+$RE_PLAIN_WORD)*)";
101  
102 52 my $RE_PLAIN_WORD_FLOW = "(?::+$RE_PLAIN_END_FLOW|$RE_PLAIN_START_FLOW)(?::+$RE_PLAIN_END_FLOW|$RE_PLAIN_END_FLOW)*";
103 52 my $RE_PLAIN_FIRST_WORD_FLOW = "(?:[:?-]+$RE_PLAIN_END_FLOW|$RE_PLAIN_FIRST_FLOW)(?::+$RE_PLAIN_END_FLOW|$RE_PLAIN_END_FLOW)*";
104 52 my $RE_PLAIN_WORDS_FLOW = "(?:$RE_PLAIN_FIRST_WORD_FLOW(?:$RE_WS+$RE_PLAIN_WORD_FLOW)*)";
105 52 my $RE_PLAIN_WORDS_FLOW2 = "(?:$RE_PLAIN_WORD_FLOW(?:$RE_WS+$RE_PLAIN_WORD_FLOW)*)";
106  
107  
108 #c-secondary-tag-handle ::= “!” “!”
109 #c-named-tag-handle ::= “!” ns-word-char+ “!”
110 #ns-tag-char ::= ns-uri-char - “!” - c-flow-indicator
111 #ns-global-tag-prefix ::= ns-tag-char ns-uri-char*
112 #c-ns-local-tag-prefix ::= “!” ns-uri-char*
113 52 my $RE_TAG = "!(?:$RE_NS_WORD_CHAR*!$RE_NS_TAG_CHAR+|$RE_NS_TAG_CHAR+|<$RE_URI_CHAR+>|)";
114  
115 #c-ns-anchor-property ::= “&” ns-anchor-name
116 #ns-char ::= nb-char - s-white
117 #ns-anchor-char ::= ns-char - c-flow-indicator
118 #ns-anchor-name ::= ns-anchor-char+
119  
120 52 my $RE_SEQSTART = qr/\A(-)(?=$RE_WS|$)/m;
121 52 my $RE_COMPLEX = qr/(\?)(?=$RE_WS|$)/m;
122 52 my $RE_COMPLEXCOLON = qr/\A(:)(?=$RE_WS|$)/m;
123 52 my $RE_ANCHOR = "&$RE_ANCHOR_CAR+";
124 52 my $RE_ALIAS = "\\*$RE_ANCHOR_CAR+";
125  
126  
127 52 my %REGEXES = (
128 ANCHOR => qr{($RE_ANCHOR)},
129 TAG => qr{($RE_TAG)},
130 ALIAS => qr{($RE_ALIAS)},
131 SINGLEQUOTED => qr{(?:''|[^'\r\n]+)*},
132 );
133  
134 66827 ▶sub _fetch_next_line {
Subroutine _fetch_next_line: called CC=5 SCAR=16.1
135 66827 my ($self) = @_;
136 66827 my $next_line = $self->next_line;
137 66827 ▶ if (defined $next_line ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $next_line) 15769 51058 66827
138 15769 return $next_line;
139 }
140  
141 51058 my $line = $self->reader->readline;
142 51058 ▶ unless (defined $line) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $line) 11959 39099 51058
143 11959 $self->set_next_line(undef);
144 11959 return;
145 }
146 39099 $self->set_block(1);
147 39099 $self->inc_line;
148 39099 ▶ $line =~ m/\A( *)([^\r\n]*)([\r\n]|\z)/ or die "Unexpected";
Branch: 1 branch
BranchTrueFalseTotal
$line =~ /\A( *)([^\r\n]*)([\r\n]|\z)/ or die "Unexpected" 39099 0 39099
149 39099 $next_line = [ $1, $2, $3 ];
150 39099 $self->set_next_line($next_line);
151 # $ESCAPE_CHAR from YAML.pm
152 39099 ▶ if ($line =~ tr/\x00-\x08\x0b-\x0c\x0e-\x1f//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ tr/\000-\b\cK\f\cN-\037//) 29 39070 39099
153 29 $self->exception("Control characters are not allowed");
154 }
155  
156 39070 return $next_line;
157 }
158  
159 52 my %TOKEN_NAMES = (
160 '"' => 'DOUBLEQUOTE',
161 "'" => 'SINGLEQUOTE',
162 '|' => 'LITERAL',
163 '>' => 'FOLDED',
164 '!' => 'TAG',
165 '*' => 'ALIAS',
166 '&' => 'ANCHOR',
167 ':' => 'COLON',
168 '-' => 'DASH',
169 '?' => 'QUESTION',
170 '[' => 'FLOWSEQ_START',
171 ']' => 'FLOWSEQ_END',
172 '{' => 'FLOWMAP_START',
173 '}' => 'FLOWMAP_END',
174 ',' => 'FLOW_COMMA',
175 '---' => 'DOC_START',
176 '...' => 'DOC_END',
177 );
178  
179  
180 41914 ▶sub fetch_next_tokens {
Subroutine fetch_next_tokens: called CC=12 SCAR=24.8
Pod undocumented
181 41914 my ($self) = @_;
182 41914 my $next = $self->next_tokens;
183 41914 ▶ return $next if @$next;
Branch: 1 branch
BranchTrueFalseTotal
if @$next 811 41103 41914
184  
185 41103 my $next_line = $self->_fetch_next_line;
186 41074 ▶ if (not $next_line) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($next_line) 7537 33537 41074
187 7537 return [];
188 }
189  
190 33537 my $spaces = $next_line->[0];
191 33537 my $yaml = \$next_line->[1];
192 33537 ▶ if (not length $$yaml) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $$yaml) 159 33378 33537
193 159 $self->_push_tokens([ EOL => join('', @$next_line), $self->line ]);
194 159 $self->set_next_line(undef);
195 159 return $next;
196 }
197 33378 ▶ if (substr($$yaml, 0, 1) eq '#') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($$yaml, 0, 1) eq "#") 551 32827 33378
198 551 $self->_push_tokens([ EOL => join('', @$next_line), $self->line ]);
199 551 $self->set_next_line(undef);
200 551 return $next;
201 }
202 32827 ▶ if (not $spaces and substr($$yaml, 0, 1) eq "%") {
Branch: 1 branch
BranchTrueFalseTotal
if (not $spaces and substr($$yaml, 0, 1) eq "%") 326 32501 32827
Condition100%3/3
not $spaces and substr($$yaml, 0, 1) eq "%"
!ll&&!rl&&r
1368218819326
MC/DC100%2/2
not $spaces and substr($$yaml, 0, 1) eq "%"
not $spaces substr($$yaml, 0, 1) eq "%"
Truth table100%3/3
not(A) and B
A= not $spacesB= substr($$yaml, 0, 1) eq "%"
ABresult
0X0
100
111
203 326 $self->_fetch_next_tokens_directive($yaml, $next_line->[2]);
204 326 $self->set_context(0);
205 326 $self->set_next_line(undef);
206 326 return $next;
207 }
208 32501 ▶ if (not $spaces and $$yaml =~ s/\A(---|\.\.\.)(?=$RE_WS|\z)//) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $spaces and $$yaml =~ s/\A(---|\.\.\.)(?=$RE_WS|\z)//) { } 4331 28170 32501
elsif ($self->flowcontext and $$yaml =~ /\A[ \t]+(#.*)?\z/) { } 59 28111 28170
Condition100%3/3
not $spaces and $$yaml =~ s/\A(---|\.\.\.)(?=$RE_WS|\z)//
!ll&&!rl&&r
13682144884331
MC/DC100%2/2
not $spaces and $$yaml =~ s/\A(---|\.\.\.)(?=$RE_WS|\z)//
not $spaces $$yaml =~ s/\A(---|\.\.\.)(?=$RE_WS|\z)//
Truth table100%3/3
not(A) and B
A= not $spacesB= $$yaml =~ s/\A(---|\.\.\.)(?=$RE_WS|\z)//
ABresult
0X0
100
111
209 4331 $self->_push_tokens([ $TOKEN_NAMES{ $1 } => $1, $self->line ]);
210 }
211 ▶ elsif ($self->flowcontext and $$yaml =~ m/\A[ \t]+(#.*)?\z/) {
Condition100%3/3
$self->flowcontext and $$yaml =~ /\A[ \t]+(#.*)?\z/
!ll&&!rl&&r
2748163059
MC/DC100%2/2
$self->flowcontext and $$yaml =~ /\A[ \t]+(#.*)?\z/
$self->flowcontext $$yaml =~ /\A[ \t]+(#.*)?\z/
Truth table100%3/3
A and B
A= $self->flowcontextB= $$yaml =~ /\A[ \t]+(#.*)?\z/
ABresult
0X0
100
111
212 59 $self->_push_tokens([ EOL => join('', @$next_line), $self->line ]);
213 59 $self->set_next_line(undef);
214 59 return $next;
215 }
216 else {
217 28111 $self->_push_tokens([ SPACE => $spaces, $self->line ]);
218 }
219  
220 32442 my $partial = $self->_fetch_next_tokens($next_line);
221 32436 ▶ unless ($partial) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($partial) 4769 27667 32436
222 4769 $self->set_next_line(undef);
223 }
224 32436 return $next;
225 }
226  
227 52 my %ANCHOR_ALIAS_TAG = ( '&' => 1, '*' => 1, '!' => 1 );
228 52 my %BLOCK_SCALAR = ( '|' => 1, '>' => 1 );
229 52 my %COLON_DASH_QUESTION = ( ':' => 1, '-' => 1, '?' => 1 );
230 52 my %QUOTED = ( '"' => 1, "'" => 1 );
231 52 my %FLOW = ( '{' => 1, '[' => 1, '}' => 1, ']' => 1, ',' => 1 );
232 52 my %CONTEXT = ( '"' => 1, "'" => 1, '>' => 1, '|' => 1 );
233  
234 52 my $RE_ESCAPES = qr{(?:
235 \\([ \\\/_0abefnrtvLNP\t"]) | \\x([0-9a-fA-F]{2})
236 | \\u([A-Fa-f0-9]{4}) | \\U([A-Fa-f0-9]{4,8})
237 )}x;
238 52 my %CONTROL = (
239 '\\' => '\\', '/' => '/', n => "\n", t => "\t", r => "\r", b => "\b",
240 'a' => "\a", 'b' => "\b", 'e' => "\e", 'f' => "\f", 'v' => "\x0b", "\t" => "\t",
241 'P' => "\x{2029}", L => "\x{2028}", 'N' => "\x85",
242 '0' => "\0", '_' => "\xa0", ' ' => ' ', q/"/ => q/"/,
243 );
244  
245 56233 ▶sub _fetch_next_tokens {
Subroutine _fetch_next_tokens: called CC=28 SCAR=33.4
246 56233 TRACE and warn __PACKAGE__.':'.__LINE__.": _fetch_next_tokens\n";
247 56233 my ($self, $next_line) = @_;
248  
249 56233 my $yaml = \$next_line->[1];
250 56233 my $eol = $next_line->[2];
251  
252 56233 my @tokens;
253  
254 56233 while (1) {
255 104622 ▶ unless (length $$yaml) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $$yaml) 6836 97786 104622
256 6836 push @tokens, ( EOL => $eol, $self->line );
257 6836 $self->_push_tokens(\@tokens);
258 6836 return;
259 }
260 97786 my $first = substr($$yaml, 0, 1);
261 97786 my $plain = 0;
262  
263 97786 ▶ if ($self->context) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->context) 1815 95971 97786
264 1815 ▶ if ($$yaml =~ s/\A($RE_WS*)://) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$yaml =~ s/\A($RE_WS*)://) 165 1650 1815
265 165 ▶ push @tokens, ( WS => $1, $self->line ) if $1;
Branch: 1 branch
BranchTrueFalseTotal
if $1 12 153 165
266 165 push @tokens, ( COLON => ':', $self->line );
267 165 $self->set_context(0);
268 165 next;
269 }
270 1650 ▶ if ($$yaml =~ s/\A($RE_WS*(?: #.*))\z//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$yaml =~ s/\A($RE_WS*(?: #.*))\z//) 10 1640 1650
271 10 push @tokens, ( EOL => $1 . $eol, $self->line );
272 10 $self->_push_tokens(\@tokens);
273 10 return;
274 }
275 1640 $self->set_context(0);
276 }
277 97611 ▶ if ($CONTEXT{ $first }) {
Branch: 5 branches
BranchTrueFalseTotal
if ($CONTEXT{$first}) { } 6437 91174 97611
elsif ($COLON_DASH_QUESTION{$first}) { } 29408 61766 91174
elsif ($ANCHOR_ALIAS_TAG{$first}) { } 5389 56377 61766
elsif ($first eq ' ' or $first eq "\t") { } 9300 47077 56377
elsif ($FLOW{$first}) { } 7702 39375 47077
278 6437 push @tokens, ( CONTEXT => $first, $self->line );
279 6437 $self->_push_tokens(\@tokens);
280 6437 return 1;
281 }
282 elsif ($COLON_DASH_QUESTION{ $first }) {
283 29408 my $token_name = $TOKEN_NAMES{ $first };
284 29408 ▶ if ($$yaml =~ s/\A\Q$first\E($RE_WS+|\z)//) {
Branch: 2 branches
BranchTrueFalseTotal
if ($$yaml =~ s/\A\Q$first\E($RE_WS+|\z)//) { } 28869 539 29408
elsif ($self->flowcontext and $$yaml =~ s/\A:(?=[,\{\}\[\]])//) { } 7 971 978
285 28869 my $after = $1;
286 28869 ▶ if (not $self->flowcontext and not $self->block) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->flowcontext or $self->block) 8 28861 28869
Condition100%3/3
$self->flowcontext or $self->block
l!l&&r!l&&!r
1260276018
MC/DC100%2/2
$self->flowcontext or $self->block
$self->flowcontext $self->block
Truth table100%3/3
A or B
A= $self->flowcontextB= $self->block
ABresult
1X1
011
000
287 8 push @tokens, ERROR => $first . $after, $self->line;
288 8 $self->_push_tokens(\@tokens);
289 8 $self->exception("Tabs can not be used for indentation");
290 }
291 28861 ▶ if ($after =~ tr/\t//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($after =~ tr/\t//) 80 28781 28861
292 80 $self->set_block(0);
293 }
294 28861 my $token_name = $TOKEN_NAMES{ $first };
295 28861 push @tokens, ( $token_name => $first, $self->line );
296 28861 ▶ if (not defined $1) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $1) 0 28861 28861
297 0 push @tokens, ( EOL => $eol, $self->line );
298 0 $self->_push_tokens(\@tokens);
299 0 return;
300 }
301 28861 my $ws = $1;
302 28861 ▶ if ($$yaml =~ s/\A(#.*|)\z//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$yaml =~ s/\A(#.*|)\z//) 2822 26039 28861
303 2822 push @tokens, ( EOL => $ws . $1 . $eol, $self->line );
304 2822 $self->_push_tokens(\@tokens);
305 2822 return;
306 }
307 26039 push @tokens, ( WS => $ws, $self->line );
308 26039 next;
309 }
310 ▶ elsif ($self->flowcontext and $$yaml =~ s/\A:(?=[,\{\}\[\]])//) {
Condition100%3/3
$self->flowcontext and $$yaml =~ s/\A:(?=[,\{\}\[\]])//
!ll&&!rl&&r
439937
MC/DC100%2/2
$self->flowcontext and $$yaml =~ s/\A:(?=[,\{\}\[\]])//
$self->flowcontext $$yaml =~ s/\A:(?=[,\{\}\[\]])//
Truth table100%3/3
A and B
A= $self->flowcontextB= $$yaml =~ s/\A:(?=[,\{\}\[\]])//
ABresult
0X0
100
111
311 7 push @tokens, ( $token_name => $first, $self->line );
312 7 next;
313 }
314 532 $plain = 1;
315 }
316 elsif ($ANCHOR_ALIAS_TAG{ $first }) {
317 5389 my $token_name = $TOKEN_NAMES{ $first };
318 5389 my $REGEX = $REGEXES{ $token_name };
319 5389 ▶ if ($$yaml =~ s/\A$REGEX//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$yaml =~ s/\A$REGEX//) { } 5389 0 5389
320 5389 push @tokens, ( $token_name => $1, $self->line );
321 }
322 else {
323 0 push @tokens, ( "Invalid $token_name" => $$yaml, $self->line );
324 0 $self->_push_tokens(\@tokens);
325 0 return;
326 }
327 }
328 ▶ elsif ($first eq ' ' or $first eq "\t") {
Condition100%3/3
$first eq " " or $first eq "\t"
l!l&&r!l&&!r
916014047077
MC/DC100%2/2
$first eq " " or $first eq "\t"
$first eq " " $first eq "\t"
Truth table100%3/3
A or B
A= $first eq " "B= $first eq "\t"
ABresult
1X1
011
000
329 9300 ▶ if ($$yaml =~ s/\A($RE_WS+)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$yaml =~ s/\A($RE_WS+)//) 9300 0 9300
330 9300 my $ws = $1;
331 9300 ▶ if ($$yaml =~ s/\A((?:#.*)?\z)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$yaml =~ s/\A((?:#.*)?\z)//) 213 9087 9300
332 213 push @tokens, ( EOL => $ws . $1 . $eol, $self->line );
333 213 $self->_push_tokens(\@tokens);
334 213 return;
335 }
336 9087 push @tokens, ( WS => $ws, $self->line );
337 }
338 }
339 elsif ($FLOW{ $first }) {
340 7702 push @tokens, ( $TOKEN_NAMES{ $first } => $first, $self->line );
341 7702 substr($$yaml, 0, 1, '');
342 7702 my $flowcontext = $self->flowcontext;
343 7702 ▶ if ($first eq '{' or $first eq '[') {
Branch: 2 branches
BranchTrueFalseTotal
if ($first eq '{' or $first eq '[') { } 2651 5051 7702
elsif ($first eq '}' or $first eq ']') { } 2640 2411 5051
Condition100%3/3
$first eq "{" or $first eq "["
l!l&&r!l&&!r
121114405051
MC/DC100%2/2
$first eq "{" or $first eq "["
$first eq "{" $first eq "["
Truth table100%3/3
A or B
A= $first eq "{"B= $first eq "["
ABresult
1X1
011
000
344 2651 $self->set_flowcontext(++$flowcontext);
345 }
346 ▶ elsif ($first eq '}' or $first eq ']') {
Condition100%3/3
$first eq "}" or $first eq "]"
l!l&&r!l&&!r
120914312411
MC/DC100%2/2
$first eq "}" or $first eq "]"
$first eq "}" $first eq "]"
Truth table100%3/3
A or B
A= $first eq "}"B= $first eq "]"
ABresult
1X1
011
000
347 2640 $self->set_flowcontext(--$flowcontext);
348 }
349 }
350 else {
351 39375 $plain = 1;
352 }
353  
354 62085 ▶ if ($plain) {
Branch: 1 branch
BranchTrueFalseTotal
if ($plain) 39907 22178 62085
355 39907 push @tokens, ( CONTEXT => '', $self->line );
356 39907 $self->_push_tokens(\@tokens);
357 39907 return 1;
358 }
359  
360 }
361  
362 0 return;
363 }
364  
365 39868 ▶sub fetch_plain {
Subroutine fetch_plain: called CC=27 SCAR=33.0
Pod undocumented
366 39868 my ($self, $indent, $context) = @_;
367 39868 my $next_line = $self->next_line;
368 39868 my $yaml = \$next_line->[1];
369 39868 my $eol = $next_line->[2];
370 39868 my $REGEX = $RE_PLAIN_WORDS;
371 39868 ▶ if ($self->flowcontext) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->flowcontext) 2914 36954 39868
372 2914 $REGEX = $RE_PLAIN_WORDS_FLOW;
373 }
374  
375 39868 my @tokens;
376 39868 ▶ unless ($$yaml =~ s/\A($REGEX(?:[:]+(?=\:(\s|\z)))?)//) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($$yaml =~ s/\A($REGEX(?:[:]+(?=\:(\s|\z)))?)//) 7 39861 39868
377 7 $self->_push_tokens(\@tokens);
378 7 $self->exception("Invalid plain scalar");
379 }
380 39861 my $plain = $1;
381 39861 push @tokens, ( PLAIN => $plain, $self->line );
382  
383 39861 ▶ if ($$yaml =~ s/\A(?:($RE_WS+#.*)|($RE_WS*))\z//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$yaml =~ s/\A(?:($RE_WS+#.*)|($RE_WS*))\z//) { } 19391 20470 39861
384 19391 ▶ if (defined $1) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $1) { } 131 19260 19391
385 131 push @tokens, ( EOL => $1 . $eol, $self->line );
386 131 $self->_push_tokens(\@tokens);
387 131 $self->set_next_line(undef);
388 131 return;
389 }
390 else {
391 19260 push @tokens, ( EOL => $2. $eol, $self->line );
392 19260 $self->set_next_line(undef);
393 }
394 }
395 else {
396 20470 $self->_push_tokens(\@tokens);
397 20470 my $partial = $self->_fetch_next_tokens($next_line);
398 20468 ▶ if (not $partial) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($partial) 3485 16983 20468
399 3485 $self->set_next_line(undef);
400 }
401 20468 return;
402 }
403  
404 19260 my $RE2 = $RE_PLAIN_WORDS2;
405 19260 ▶ if ($self->flowcontext) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->flowcontext) 132 19128 19260
406 132 $RE2 = $RE_PLAIN_WORDS_FLOW2;
407 }
408 19260 my $fetch_next = 0;
409 19260 my @lines = ($plain);
410 19260 my @next;
411 19260 LOOP: while (1) {
412 19620 $next_line = $self->_fetch_next_line;
413 19620 ▶ if (not $next_line) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($next_line) 3609 16011 19620
414 3609 last LOOP;
415 }
416 16011 my $spaces = $next_line->[0];
417 16011 my $yaml = \$next_line->[1];
418 16011 my $eol = $next_line->[2];
419  
420 16011 ▶ if (not length $$yaml) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $$yaml) 104 15907 16011
421 104 push @tokens, ( EOL => $spaces . $eol, $self->line );
422 104 $self->set_next_line(undef);
423 104 push @lines, '';
424 104 next LOOP;
425 }
426  
427 15907 ▶ if (not $spaces and $$yaml =~ s/\A(---|\.\.\.)(?=$RE_WS|\z)//) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $spaces and $$yaml =~ s/\A(---|\.\.\.)(?=$RE_WS|\z)//) 630 15277 15907
Condition100%3/3
not $spaces and $$yaml =~ s/\A(---|\.\.\.)(?=$RE_WS|\z)//
!ll&&!rl&&r
107564521630
MC/DC100%2/2
not $spaces and $$yaml =~ s/\A(---|\.\.\.)(?=$RE_WS|\z)//
not $spaces $$yaml =~ s/\A(---|\.\.\.)(?=$RE_WS|\z)//
Truth table100%3/3
not(A) and B
A= not $spacesB= $$yaml =~ s/\A(---|\.\.\.)(?=$RE_WS|\z)//
ABresult
0X0
100
111
428 630 push @next, $TOKEN_NAMES{ $1 } => $1, $self->line;
429 630 $fetch_next = 1;
430 630 last LOOP;
431 }
432 15277 ▶ if ((length $spaces) < $indent) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $spaces < $indent) 14869 408 15277
433 14869 last LOOP;
434 }
435  
436 408 my $ws = '';
437 408 ▶ if ($$yaml =~ s/\A($RE_WS+)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$yaml =~ s/\A($RE_WS+)//) 25 383 408
438 25 $ws = $1;
439 }
440 408 ▶ if (not length $$yaml) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $$yaml) 11 397 408
441 11 push @tokens, ( EOL => $spaces . $ws . $eol, $self->line );
442 11 $self->set_next_line(undef);
443 11 push @lines, '';
444 11 next LOOP;
445 }
446 397 ▶ if ($$yaml =~ s/\A(#.*)\z//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$yaml =~ s/\A(#.*)\z//) 10 387 397
447 10 push @tokens, ( EOL => $spaces . $ws . $1 . $eol, $self->line );
448 10 $self->set_next_line(undef);
449 10 last LOOP;
450 }
451  
452 387 ▶ if ($$yaml =~ s/\A($RE2)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$yaml =~ s/\A($RE2)//) { } 297 90 387
453 297 push @tokens, INDENT => $spaces, $self->line;
454 297 push @tokens, WS => $ws, $self->line;
455 297 push @tokens, PLAIN => $1, $self->line;
456 297 push @lines, $1;
457 297 my $ws = '';
458 297 ▶ if ($$yaml =~ s/\A($RE_WS+)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$yaml =~ s/\A($RE_WS+)//) 42 255 297
459 42 $ws = $1;
460 }
461 297 ▶ if (not length $$yaml) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $$yaml) 245 52 297
462 245 push @tokens, EOL => $ws . $eol, $self->line;
463 245 $self->set_next_line(undef);
464 245 next LOOP;
465 }
466  
467 52 ▶ if ($$yaml =~ s/\A(#.*)\z//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$yaml =~ s/\A(#.*)\z//) { } 17 35 52
468 17 push @tokens, EOL => $ws . $1 . $eol, $self->line;
469 17 $self->set_next_line(undef);
470 17 last LOOP;
471 }
472 else {
473 35 ▶ push @tokens, WS => $ws, $self->line if $ws;
Branch: 1 branch
BranchTrueFalseTotal
if $ws 10 25 35
474 35 $fetch_next = 1;
475 }
476 }
477 else {
478 90 push @tokens, SPACE => $spaces, $self->line;
479 90 push @tokens, WS => $ws, $self->line;
480 90 ▶ if ($self->flowcontext) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->flowcontext) { } 90 0 90
481 90 $fetch_next = 1;
482 }
483 else {
484 0 push @tokens, ERROR => $$yaml, $self->line;
485 }
486 }
487  
488 125 last LOOP;
489  
490 }
491 # remove empty lines at the end
492 19260 ▶ while (@lines > 1 and $lines[-1] eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (@lines > 1 and $lines[-1] eq "") 90 19260 19350
Condition100%3/3
@lines > 1 and $lines[-1] eq ""
!ll&&!rl&&r
1901824290
MC/DC100%2/2
@lines > 1 and $lines[-1] eq ""
@lines > 1 $lines[-1] eq ""
Truth table100%3/3
A and B
A= @lines > 1B= $lines[-1] eq ""
ABresult
0X0
100
111
493 90 pop @lines;
494 }
495 19260 ▶ if (@lines > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@lines > 1) { } 242 19018 19260
496 242 my $value = YAML::PP::Render->render_multi_val(\@lines);
497 242 my @eol;
498 242 ▶ if ($tokens[-3] eq 'EOL') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens[-3] eq "EOL") 207 35 242
499 207 @eol = splice @tokens, -3;
500 }
501 242 $self->push_subtokens( { name => 'PLAIN_MULTI', value => $value }, \@tokens);
502 242 $self->_push_tokens([ @eol, @next ]);
503 }
504 else {
505 19018 $self->_push_tokens([ @tokens, @next ]);
506 }
507 19260 @tokens = ();
508 19260 ▶ if ($fetch_next) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fetch_next) 755 18505 19260
509 755 my $partial = $self->_fetch_next_tokens($next_line);
510 755 ▶ if (not $partial) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($partial) 610 145 755
511 610 $self->set_next_line(undef);
512 }
513 }
514 19260 return;
515 }
516  
517 1720 ▶sub fetch_block {
Subroutine fetch_block: called CC=23 SCAR=31.4
Pod undocumented
518 1720 my ($self, $indent, $context) = @_;
519 1720 my $next_line = $self->next_line;
520 1720 my $yaml = \$next_line->[1];
521 1720 my $eol = $next_line->[2];
522  
523 1720 my @tokens;
524 1720 my $token_name = $TOKEN_NAMES{ $context };
525 1720 ▶ $$yaml =~ s/\A\Q$context\E// or die "Unexpected";
Branch: 1 branch
BranchTrueFalseTotal
$$yaml =~ s/\A\Q$context\E// or die "Unexpected" 1720 0 1720
526 1720 push @tokens, ( $token_name => $context, $self->line );
527 1720 my $current_indent = $indent;
528 1720 my $started = 0;
529 1720 my $set_indent = 0;
530 1720 my $chomp = '';
531 1720 ▶ if ($$yaml =~ s/\A([1-9])([+-]?)//) {
Branch: 2 branches
BranchTrueFalseTotal
if ($$yaml =~ s/\A([1-9])([+-]?)//) { } 215 1505 1720
elsif ($$yaml =~ s/\A([+-])([1-9])?//) { } 409 1096 1505
532 215 push @tokens, ( BLOCK_SCALAR_INDENT => $1, $self->line );
533 215 $set_indent = $1;
534 215 ▶ $chomp = $2 if $2;
Branch: 1 branch
BranchTrueFalseTotal
if $2 85 130 215
535 215 ▶ push @tokens, ( BLOCK_SCALAR_CHOMP => $2, $self->line ) if $2;
Branch: 1 branch
BranchTrueFalseTotal
if $2 85 130 215
536 }
537 elsif ($$yaml =~ s/\A([+-])([1-9])?//) {
538 409 push @tokens, ( BLOCK_SCALAR_CHOMP => $1, $self->line );
539 409 $chomp = $1;
540 409 ▶ push @tokens, ( BLOCK_SCALAR_INDENT => $2, $self->line ) if $2;
Branch: 1 branch
BranchTrueFalseTotal
if $2 9 400 409
541 409 ▶ $set_indent = $2 if $2;
Branch: 1 branch
BranchTrueFalseTotal
if $2 9 400 409
542 }
543 1720 ▶ if ($set_indent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($set_indent) 224 1496 1720
544 224 $started = 1;
545 224 ▶ $indent-- if $indent > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $indent > 0 190 34 224
546 224 $current_indent = $indent + $set_indent;
547 }
548 1720 ▶ if (not length $$yaml) {
Branch: 2 branches
BranchTrueFalseTotal
if (not length $$yaml) { } 1662 58 1720
elsif ($$yaml =~ s/\A($RE_WS*(?:$RE_WS#.*|))\z//) { } 52 6 58
549 1662 push @tokens, ( EOL => $eol, $self->line );
550 }
551 elsif ($$yaml =~ s/\A($RE_WS*(?:$RE_WS#.*|))\z//) {
552 52 push @tokens, ( EOL => $1 . $eol, $self->line );
553 }
554 else {
555 6 $self->_push_tokens(\@tokens);
556 6 $self->exception("Invalid block scalar");
557 }
558  
559 1714 my @lines;
560 1714 while (1) {
561 5254 $self->set_next_line(undef);
562 5254 $next_line = $self->_fetch_next_line;
563 5254 ▶ if (not $next_line) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($next_line) 812 4442 5254
564 812 last;
565 }
566 4442 my $spaces = $next_line->[0];
567 4442 my $content = $next_line->[1];
568 4442 my $eol = $next_line->[2];
569 4442 ▶ if (not $spaces and $content =~ m/\A(---|\.\.\.)(?=$RE_WS|\z)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $spaces and $content =~ /\A(---|\.\.\.)(?=$RE_WS|\z)/) 200 4242 4442
Condition100%3/3
not $spaces and $content =~ /\A(---|\.\.\.)(?=$RE_WS|\z)/
!ll&&!rl&&r
29151327200
MC/DC100%2/2
not $spaces and $content =~ /\A(---|\.\.\.)(?=$RE_WS|\z)/
not $spaces $content =~ /\A(---|\.\.\.)(?=$RE_WS|\z)/
Truth table100%3/3
not(A) and B
A= not $spacesB= $content =~ /\A(---|\.\.\.)(?=$RE_WS|\z)/
ABresult
0X0
100
111
570 200 last;
571 }
572 4242 ▶ if ((length $spaces) < $current_indent) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $spaces < $current_indent) 1436 2806 4242
573 1436 ▶ if (length $content) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $content) { } 702 734 1436
574 702 ▶ if ($content =~ m/\A\t/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /\A\t/) 2 700 702
575 2 $self->_push_tokens(\@tokens);
576 2 $self->exception("Invalid block scalar");
577 }
578 700 last;
579 }
580 else {
581 734 push @lines, '';
582 734 push @tokens, ( EOL => $spaces . $eol, $self->line );
583 734 next;
584 }
585 }
586 2806 ▶ if ((length $spaces) > $current_indent) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $spaces > $current_indent) 1572 1234 2806
587 1572 ▶ if ($started) {
Branch: 1 branch
BranchTrueFalseTotal
if ($started) 372 1200 1572
588 372 ($spaces, my $more_spaces) = unpack "a${current_indent}a*", $spaces;
589 372 $content = $more_spaces . $content;
590 }
591 }
592 2806 ▶ unless (length $content) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $content) 257 2549 2806
593 257 push @lines, '';
594 257 push @tokens, ( INDENT => $spaces, $self->line, EOL => $eol, $self->line );
595 257 ▶ unless ($started) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($started) 131 126 257
596 131 $current_indent = length $spaces;
597 }
598 257 next;
599 }
600 2549 ▶ unless ($started) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($started) 1382 1167 2549
601 1382 $started = 1;
602 1382 $current_indent = length $spaces;
603 }
604 2549 push @lines, $content;
605 2549 push @tokens, (
606 INDENT => $spaces, $self->line,
607 BLOCK_SCALAR_CONTENT => $content, $self->line,
608 EOL => $eol, $self->line,
609 );
610 }
611 1712 my $value = YAML::PP::Render->render_block_scalar($context, $chomp, \@lines);
612 1712 my @eol = splice @tokens, -3;
613 1712 $self->push_subtokens( { name => 'BLOCK_SCALAR', value => $value }, \@tokens );
614 1712 $self->_push_tokens([ @eol ]);
615 1712 return 0;
616 }
617  
618 4717 ▶sub fetch_quoted {
Subroutine fetch_quoted: called CC=20 SCAR=30.0
Pod undocumented
619 4717 my ($self, $indent, $context) = @_;
620 4717 my $next_line = $self->next_line;
621 4717 my $yaml = \$next_line->[1];
622 4717 my $spaces = $next_line->[0];
623  
624 4717 my $token_name = $TOKEN_NAMES{ $context };
625 4717 ▶ $$yaml =~ s/\A\Q$context// or die "Unexpected";;
Branch: 1 branch
BranchTrueFalseTotal
$$yaml =~ s/\A\Q$context\E// or die "Unexpected" 4717 0 4717
626 4717 my @tokens = ( $token_name => $context, $self->line );
627  
628 4717 my $start = 1;
629 4717 my @values;
630 4717 while (1) {
631  
632 5567 ▶ unless ($start) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($start) 850 4717 5567
633 850 ▶ $next_line = $self->_fetch_next_line or do {
Branch: 1 branch
BranchTrueFalseTotal
$next_line = $self->_fetch_next_line or do { for (my $i = 0; $i < @tokens; $i += 3) { my $token = $tokens[$i + 1]; if (ref $token) { $tokens[$i + 1] = $token->{"orig"}; } ; } ; $self->_push_tokens(\@tokens); $self->exception("Missing closing quote <$context> at EOF") } 849 1 850
634 1 ▶ for (my $i = 0; $i < @tokens; $i+= 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @tokens) 3 1 4
635 3 my $token = $tokens[ $i + 1 ];
636 3 ▶ if (ref $token) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $token) 1 2 3
637 1 $tokens[ $i + 1 ] = $token->{orig};
638 }
639 }
640 1 $self->_push_tokens(\@tokens);
641 1 $self->exception("Missing closing quote <$context> at EOF");
642 };
643 849 $start = 0;
644 849 $spaces = $next_line->[0];
645 849 $yaml = \$next_line->[1];
646  
647 849 ▶ if (not length $$yaml) {
Branch: 3 branches
BranchTrueFalseTotal
if (not length $$yaml) { } 160 689 849
elsif (not $spaces and $$yaml =~ /\A(---|\.\.\.)(?=$RE_WS|\z)/) { } 3 686 689
elsif (length $spaces < $indent) { } 3 683 686
648 160 push @tokens, ( EOL => $spaces . $next_line->[2], $self->line );
649 160 $self->set_next_line(undef);
650 160 push @values, { value => '', orig => '' };
651 160 next;
652 }
653 ▶ elsif (not $spaces and $$yaml =~ m/\A(---|\.\.\.)(?=$RE_WS|\z)/) {
Condition100%3/3
not $spaces and $$yaml =~ /\A(---|\.\.\.)(?=$RE_WS|\z)/
!ll&&!rl&&r
5841023
MC/DC100%2/2
not $spaces and $$yaml =~ /\A(---|\.\.\.)(?=$RE_WS|\z)/
not $spaces $$yaml =~ /\A(---|\.\.\.)(?=$RE_WS|\z)/
Truth table100%3/3
not(A) and B
A= not $spacesB= $$yaml =~ /\A(---|\.\.\.)(?=$RE_WS|\z)/
ABresult
0X0
100
111
654 3 ▶ for (my $i = 0; $i < @tokens; $i+= 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @tokens) 9 3 12
655 9 my $token = $tokens[ $i + 1 ];
656 9 ▶ if (ref $token) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $token) 3 6 9
657 3 $tokens[ $i + 1 ] = $token->{orig};
658 }
659 }
660 3 $self->_push_tokens(\@tokens);
661 3 $self->exception("Missing closing quote <$context> or invalid document marker");
662 }
663 elsif ((length $spaces) < $indent) {
664 3 ▶ for (my $i = 0; $i < @tokens; $i+= 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @tokens) 9 3 12
665 9 my $token = $tokens[ $i + 1 ];
666 9 ▶ if (ref $token) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $token) 3 6 9
667 3 $tokens[ $i + 1 ] = $token->{orig};
668 }
669 }
670 3 $self->_push_tokens(\@tokens);
671 3 $self->exception("Wrong indendation or missing closing quote <$context>");
672 }
673  
674 683 ▶ if ($$yaml =~ s/\A($RE_WS+)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$yaml =~ s/\A($RE_WS+)//) 95 588 683
675 95 $spaces .= $1;
676 }
677 683 push @tokens, ( WS => $spaces, $self->line );
678 }
679  
680 5400 my $v = $self->_read_quoted_tokens($start, $context, $yaml, \@tokens);
681 5398 push @values, $v;
682 5398 ▶ if ($tokens[-3] eq $token_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens[-3] eq $token_name) 4708 690 5398
683 4708 ▶ if ($start) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start) { } 4217 491 4708
684 $self->push_subtokens(
685 { name => 'QUOTED', value => $v->{value} }, \@tokens
686 4217 );
687 }
688 else {
689 491 my $value = YAML::PP::Render->render_quoted($context, \@values);
690 491 $self->push_subtokens(
691 { name => 'QUOTED_MULTILINE', value => $value }, \@tokens
692 );
693 }
694 4708 ▶ $self->set_context(1) if $self->flowcontext;
Branch: 1 branch
BranchTrueFalseTotal
if $self->flowcontext 1805 2903 4708
695 4708 ▶ if (length $$yaml) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $$yaml) { } 2566 2142 4708
696 2566 my $partial = $self->_fetch_next_tokens($next_line);
697 2566 ▶ if (not $partial) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($partial) 1017 1549 2566
698 1017 $self->set_next_line(undef);
699 }
700 2566 return 0;
701 }
702 else {
703 2142 @tokens = ();
704 2142 push @tokens, ( EOL => $next_line->[2], $self->line );
705 2142 $self->_push_tokens(\@tokens);
706 2142 $self->set_next_line(undef);
707 2142 return;
708 }
709 }
710 690 $tokens[-2] .= $next_line->[2];
711 690 $self->set_next_line(undef);
712 690 $start = 0;
713 }
714 }
715  
716 5400 ▶sub _read_quoted_tokens {
Subroutine _read_quoted_tokens: called CC=8 SCAR=20.8
717 5400 my ($self, $start, $first, $yaml, $tokens) = @_;
718 5400 my $quoted = '';
719 5400 my $decoded = '';
720 5400 my $token_name = $TOKEN_NAMES{ $first };
721 5400 my $eol = '';
722 5400 ▶ if ($first eq "'") {
Branch: 1 branch
BranchTrueFalseTotal
if ($first eq q[']) { } 2197 3203 5400
723 2197 my $regex = $REGEXES{SINGLEQUOTED};
724 2197 ▶ if ($$yaml =~ s/\A($regex)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$yaml =~ s/\A($regex)//) 2197 0 2197
725 2197 $quoted .= $1;
726 2197 $decoded .= $1;
727 2197 $decoded =~ s/''/'/g;
728 }
729 2197 ▶ unless (length $$yaml) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $$yaml) 88 2109 2197
730 88 ▶ if ($quoted =~ s/($RE_WS+)\z//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($quoted =~ s/($RE_WS+)\z//) 24 64 88
731 24 $eol = $1;
732 24 $decoded =~ s/($eol)\z//;
733 }
734 }
735 }
736 else {
737 3203 ($quoted, $decoded, $eol) = $self->_read_doublequoted($yaml);
738 }
739 5400 my $value = { value => $decoded, orig => $quoted };
740  
741 5400 ▶ if ($$yaml =~ s/\A$first//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$yaml =~ s/\A$first//) 4708 692 5400
742 4708 ▶ if ($start) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start) { } 4217 491 4708
743 4217 push @$tokens, ( $token_name . 'D' => $value, $self->line );
744 }
745 else {
746 491 push @$tokens, ( $token_name . 'D_LINE' => $value, $self->line );
747 }
748 4708 push @$tokens, ( $token_name => $first, $self->line );
749 4708 return $value;
750 }
751 692 ▶ if (length $$yaml) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $$yaml) 2 690 692
752 2 push @$tokens, ( $token_name . 'D' => $value->{orig}, $self->line );
753 2 $self->_push_tokens($tokens);
754 2 $self->exception("Invalid quoted <$first> string");
755 }
756  
757 690 push @$tokens, ( $token_name . 'D_LINE' => $value, $self->line );
758 690 push @$tokens, ( EOL => $eol, $self->line );
759  
760 690 return $value;
761 }
762  
763 3203 ▶sub _read_doublequoted {
Subroutine _read_doublequoted: called CC=10 SCAR=23.0
764 3203 my ($self, $yaml) = @_;
765 3203 my $quoted = '';
766 3203 my $decoded = '';
767 3203 my $eol = '';
768 3203 while (1) {
769 9367 my $last = 1;
770 9367 ▶ if ($$yaml =~ s/\A([^"\\ \t]+)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$yaml =~ s/\A([^"\\ \t]+)//) 5584 3783 9367
771 5584 $quoted .= $1;
772 5584 $decoded .= $1;
773 5584 $last = 0;
774 }
775 9367 ▶ if ($$yaml =~ s/\A($RE_ESCAPES)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$yaml =~ s/\A($RE_ESCAPES)//) 1475 7892 9367
776 1475 $quoted .= $1;
777 1475 ▶ my $dec = defined $2 ? $CONTROL{ $2 }
Branch: 3 branches
BranchTrueFalseTotal
defined $2 ? : 1362 113 1475
defined $3 ? : 95 18 113
defined $4 ? : 17 1 18
778 : defined $3 ? chr hex $3
779 : defined $4 ? chr hex $4
780 : chr hex $5;
781 1475 $decoded .= $dec;
782 1475 $last = 0;
783 }
784 9367 ▶ if ($$yaml =~ s/\A([ \t]+)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$yaml =~ s/\A([ \t]+)//) 2762 6605 9367
785 2762 my $spaces = $1;
786 2762 ▶ if (length $$yaml) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $$yaml) { } 2621 141 2762
787 2621 $quoted .= $spaces;
788 2621 $decoded .= $spaces;
789 2621 $last = 0;
790 }
791 else {
792 141 $eol = $spaces;
793 141 last;
794 }
795 }
796 9226 ▶ if ($$yaml =~ s/\A(\\)\z//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$yaml =~ s/\A(\\)\z//) 82 9144 9226
797 82 $quoted .= $1;
798 82 $decoded .= $1;
799 82 last;
800 }
801 9144 ▶ last if $last;
Branch: 1 branch
BranchTrueFalseTotal
if $last 2980 6164 9144
802 }
803 3203 return ($quoted, $decoded, $eol);
804 }
805  
806 326 ▶sub _fetch_next_tokens_directive {
Subroutine _fetch_next_tokens_directive: called CC=16 SCAR=30.5
807 326 my ($self, $yaml, $eol) = @_;
808 326 my @tokens;
809  
810 326 my $trailing_ws = '';
811 326 ▶ my $warn = $ENV{YAML_PP_RESERVED_DIRECTIVE} || 'warn';
Condition100%2/2
$ENV{'YAML_PP_RESERVED_DIRECTIVE'} || 'warn'
l!l
30026
MC/DC100%1/1
$ENV{'YAML_PP_RESERVED_DIRECTIVE'} || 'warn'
$ENV{'YAML_PP_RESERVED_DIRECTIVE'}
Truth table100%2/2
A
A= $ENV{'YAML_PP_RESERVED_DIRECTIVE'}
Aresult
11
00
812 326 ▶ if ($$yaml =~ s/\A(\s*%YAML[ \t]+([0-9]+\.[0-9]+))//) {
Branch: 3 branches
BranchTrueFalseTotal
if ($$yaml =~ s/\A(\s*%YAML[ \t]+([0-9]+\.[0-9]+))//) { } 163 163 326
elsif ($$yaml =~ s/\A(\s*%TAG[ \t]+(!$RE_NS_WORD_CHAR*!|!)[ \t]+(tag:\S+|!$RE_URI_CHAR+))($RE_WS*)//) { } 118 45 163
elsif ($$yaml =~ s/\A(\s*\A%(?:\w+).*)//) { } 45 0 45
813 163 my $dir = $1;
814 163 my $version = $2;
815 163 ▶ if ($$yaml =~ s/\A($RE_WS+)//) {
Branch: 2 branches
BranchTrueFalseTotal
if ($$yaml =~ s/\A($RE_WS+)//) { } 28 135 163
elsif (length $$yaml) { } 1 134 135
816 28 $trailing_ws = $1;
817 }
818 elsif (length $$yaml) {
819 1 push @tokens, ( 'Invalid directive' => $dir.$$yaml.$eol, $self->line );
820 1 $self->_push_tokens(\@tokens);
821 1 return;
822 }
823 162 ▶ if ($version !~ m/^1\.[12]$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($version =~ /^1\.[12]$/) 9 153 162
824 9 ▶ if ($warn eq 'warn') {
Branch: 2 branches
BranchTrueFalseTotal
if ($warn eq 'warn') { } 0 9 9
elsif ($warn eq 'fatal') { } 0 9 9
825 0 warn "Unsupported YAML version '$dir'";
826 }
827 elsif ($warn eq 'fatal') {
828 0 push @tokens, ( 'Unsupported YAML version' => $dir, $self->line );
829 0 $self->_push_tokens(\@tokens);
830 0 return;
831 }
832 }
833 162 push @tokens, ( YAML_DIRECTIVE => $dir, $self->line );
834 }
835 elsif ($$yaml =~ s/\A(\s*%TAG[ \t]+(!$RE_NS_WORD_CHAR*!|!)[ \t]+(tag:\S+|!$RE_URI_CHAR+))($RE_WS*)//) {
836 118 push @tokens, ( TAG_DIRECTIVE => $1, $self->line );
837 # TODO
838 118 my $tag_alias = $2;
839 118 my $tag_url = $3;
840 118 $trailing_ws = $4;
841 }
842 elsif ($$yaml =~ s/\A(\s*\A%(?:\w+).*)//) {
843 45 push @tokens, ( RESERVED_DIRECTIVE => $1, $self->line );
844 45 ▶ if ($warn eq 'warn') {
Branch: 2 branches
BranchTrueFalseTotal
if ($warn eq 'warn') { } 0 45 45
elsif ($warn eq 'fatal') { } 0 45 45
845 0 warn "Found reserved directive '$1'";
846 }
847 elsif ($warn eq 'fatal') {
848 0 die "Found reserved directive '$1'";
849 }
850 }
851 else {
852 0 push @tokens, ( 'Invalid directive' => $$yaml, $self->line );
853 0 push @tokens, ( EOL => $eol, $self->line );
854 0 $self->_push_tokens(\@tokens);
855 0 return;
856 }
857 325 ▶ if (not length $$yaml) {
Branch: 3 branches
BranchTrueFalseTotal
if (not length $$yaml) { } 297 28 325
elsif ($trailing_ws and $$yaml =~ s/\A(#.*)?\z//) { } 27 1 28
elsif ($$yaml =~ s/\A([ \t]+#.*)?\z//) { } 0 1 1
858 297 push @tokens, ( EOL => $eol, $self->line );
859 }
860 ▶ elsif ($trailing_ws and $$yaml =~ s/\A(#.*)?\z//) {
Condition66%2/3
$trailing_ws and $$yaml =~ s/\A(#.*)?\z//
!ll&&!rl&&r
0127
MC/DC50%1/2
$trailing_ws and $$yaml =~ s/\A(#.*)?\z//
$trailing_ws $$yaml =~ s/\A(#.*)?\z//
Truth table66%2/3
A and B
A= $trailing_wsB= $$yaml =~ s/\A(#.*)?\z//
ABresult
0X0
100
111
861 27 push @tokens, ( EOL => "$trailing_ws$1$eol", $self->line );
862 27 $self->_push_tokens(\@tokens);
863 27 return;
864 }
865 elsif ($$yaml =~ s/\A([ \t]+#.*)?\z//) {
866 0 push @tokens, ( EOL => "$1$eol", $self->line );
867 0 $self->_push_tokens(\@tokens);
868 0 return;
869 }
870 else {
871 1 push @tokens, ( 'Invalid directive' => $trailing_ws.$$yaml, $self->line );
872 1 push @tokens, ( EOL => $eol, $self->line );
873 }
874 298 $self->_push_tokens(\@tokens);
875 298 return;
876 }
877  
878 133509 ▶sub _push_tokens {
Subroutine _push_tokens: called CC=4 SCAR=13.9
879 133509 my ($self, $new_tokens) = @_;
880 133509 my $next = $self->next_tokens;
881 133509 my $line = $self->line;
882 133509 my $column = $self->offset;
883  
884 133509 ▶ for (my $i = 0; $i < @$new_tokens; $i += 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$new_tokens) 231125 133509 364634
885 231125 my $value = $new_tokens->[ $i + 1 ];
886 231125 my $name = $new_tokens->[ $i ];
887 231125 my $line = $new_tokens->[ $i + 2 ];
888 231125 my $push = {
889 name => $name,
890 line => $line,
891 column => $column,
892 value => $value,
893 };
894 231125 ▶ $column += length $value unless $name eq 'CONTEXT';
Branch: 1 branch
BranchTrueFalseTotal
unless $name eq "CONTEXT" 184781 46344 231125
895 231125 push @$next, $push;
896 231125 ▶ if ($name eq 'EOL') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "EOL") 34285 196840 231125
897 34285 $column = 0;
898 }
899 }
900 133509 $self->set_offset($column);
901 133509 return $next;
902 }
903  
904 6662 ▶sub push_subtokens {
Subroutine push_subtokens: called CC=4 SCAR=13.9
Pod undocumented
905 6662 my ($self, $token, $subtokens) = @_;
906 6662 my $next = $self->next_tokens;
907 6662 my $line = $self->line;
908 6662 my $column = $self->offset;
909 6662 $token->{column} = $column;
910 6662 $token->{subtokens} = \my @sub;
911  
912 6662 ▶ for (my $i = 0; $i < @$subtokens; $i+=3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$subtokens) 29130 6662 35792
913 29130 my $name = $subtokens->[ $i ];
914 29130 my $value = $subtokens->[ $i + 1 ];
915 29130 my $line = $subtokens->[ $i + 2 ];
916 29130 my $push = {
917 name => $subtokens->[ $i ],
918 line => $line,
919 column => $column,
920 };
921 29130 ▶ if (ref $value eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq 'HASH') { } 5391 23739 29130
922 5391 %$push = ( %$push, %$value );
923 5391 $column += length $value->{orig};
924 }
925 else {
926 23739 $push->{value} = $value;
927 23739 $column += length $value;
928 }
929 29130 ▶ if ($push->{name} eq 'EOL') {
Branch: 1 branch
BranchTrueFalseTotal
if ($push->{"name"} eq "EOL") 4714 24416 29130
930 4714 $column = 0;
931 }
932 29130 push @sub, $push;
933 }
934 6662 $token->{line} = $sub[0]->{line};
935 6662 push @$next, $token;
936 6662 $self->set_offset($column);
937 6662 return $next;
938 }
939  
940 61 ▶sub exception {
Subroutine exception: called CC=3 SCAR=11.0
Pod undocumented
941 61 my ($self, $msg) = @_;
942 61 my $next = $self->next_tokens;
943 61 $next = [];
944 61 ▶ my $line = @$next ? $next->[0]->{line} : $self->line;
Branch: 1 branch
BranchTrueFalseTotal
@$next ? : 0 61 61
945 61 my @caller = caller(0);
946 61 my $yaml = '';
947 61 ▶ if (my $nl = $self->next_line) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $nl = $self->next_line) 60 1 61
948 60 $yaml = join '', @$nl;
949 60 $yaml = $nl->[1];
950 }
951 61 my $e = YAML::PP::Exception->new(
952 line => $line,
953 column => $self->offset + 1,
954 msg => $msg,
955 next => $next,
956 where => $caller[1] . ' line ' . $caller[2],
957 yaml => $yaml,
958 );
959 61 croak $e;
960 }
961  
962 52 1;
« blib/lib/YAML/PP/Common.pm ↑ Summary blib/lib/YAML/PP/Highlight.pm »