| 1 | package YATT::Lite::LRXML::ParseEntpath; | ||||||||||||||||||||||||||||
| 2 | 47 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 47 | ▶ | use warnings qw(FATAL all NONFATAL misc); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 47 | ▶ | package YATT::Lite::LRXML; use YATT::Lite::LRXML; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # item ::= | ||||||||||||||||||||||||||||
| 8 | # pathItem | ||||||||||||||||||||||||||||
| 9 | # [ pathItem+ ] | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | # pathItem ::= | ||||||||||||||||||||||||||||
| 12 | # [call => name, item, item, ...] | ||||||||||||||||||||||||||||
| 13 | # [var => name] | ||||||||||||||||||||||||||||
| 14 | # [array => item, item, ...] | ||||||||||||||||||||||||||||
| 15 | # [hash => item, item, ...] | ||||||||||||||||||||||||||||
| 16 | # [aref => item] | ||||||||||||||||||||||||||||
| 17 | # [href => item] | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # Ex: | ||||||||||||||||||||||||||||
| 20 | # [aref => [var => x]] | ||||||||||||||||||||||||||||
| 21 | # [aref => [[var => i], [var => j]] | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 125 | ▶ | sub _parse_text_entities { | ||||||||||||||||||||||||||
|
Subroutine
_parse_text_entities: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 125 | my MY $self = shift; | |||||||||||||||||||||||||||
| 25 | 125 | $self->_parse_text_entities_at($self->{_curpos}, @_); | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | 288 | ▶ | sub _parse_text_entities_at { | ||||||||||||||||||||||||||
|
Subroutine
_parse_text_entities_at: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 28 | 288 | my MY $self = $_[0]; | |||||||||||||||||||||||||||
| 29 | 288 | local ($self->{_curpos}, $_) = @_[1,2]; | |||||||||||||||||||||||||||
| 30 | 288 | my ($curpos) = ($self->{_curpos}); | |||||||||||||||||||||||||||
| 31 | 288 | my $totalEnd = $curpos + length $_; | |||||||||||||||||||||||||||
| 32 | 288 | my @result; | |||||||||||||||||||||||||||
| 33 | { | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 288 | my $total = length $_; | |||||||||||||||||||||||||||
| 36 | 288 | ▶ | while (s{^(.*?)$$self{_re_entopn}}{}xs) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 59 | my $before = $curpos; | |||||||||||||||||||||||||||
| 38 | 59 | ▶ | if (length $1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 19 | push @result, $1; | |||||||||||||||||||||||||||
| 40 | 19 | $self->{_endln} += numLines($1); | |||||||||||||||||||||||||||
| 41 | 19 | $curpos += length $1; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | 59 | push @result, my $node = $self->mkentity($curpos, undef, $self->{_endln}); | |||||||||||||||||||||||||||
| 44 | 59 | $curpos = $totalEnd - length $_; | |||||||||||||||||||||||||||
| 45 | 59 | $node->[NODE_END] = $curpos; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | 288 | ▶ | if (@result) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 53 | ▶ | push @result, $_ if length $_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 53 | \@result; | |||||||||||||||||||||||||||
| 51 | } else { | ||||||||||||||||||||||||||||
| 52 | 235 | $_; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | # &yatt:foo:bar | ||||||||||||||||||||||||||||
| 57 | # | ||||||||||||||||||||||||||||
| 58 | # entpath ::= pipeline ';' | ||||||||||||||||||||||||||||
| 59 | # pipeline ::= (pathElem | '[' <group ']'> | '{' <group '}'>)+ | ||||||||||||||||||||||||||||
| 60 | # pathElem ::= ':' name ('(' <group ')'>)? | ||||||||||||||||||||||||||||
| 61 | # group C ::= term* C | ||||||||||||||||||||||||||||
| 62 | # term ::= (pipeline | expr | text) [,:]? | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 47 | our (%open_head, %open_rest, %close_ch, %for_expr); | |||||||||||||||||||||||||||
| 65 | 47 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 66 | 47 | %open_head = qw| ( call [ array { hash|; | |||||||||||||||||||||||||||
| 67 | 47 | %open_rest = qw| ( invoke [ aref { href|; | |||||||||||||||||||||||||||
| 68 | 47 | %close_ch = qw( ( ) [ ] { } ); | |||||||||||||||||||||||||||
| 69 | 47 | %for_expr = (aref => 1); | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | 722 | ▶ | sub _parse_entpath { | ||||||||||||||||||||||||||
|
Subroutine
_parse_entpath: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 72 | 722 | my MY $self = shift; | |||||||||||||||||||||||||||
| 73 | 722 | local $self->{_original_entpath} = $_; | |||||||||||||||||||||||||||
| 74 | 722 | ▶ | my $how = shift || '_parse_pipeline'; | ||||||||||||||||||||||||||
|
Condition100%2/2
shift() || '_parse_pipeline'
MC/DC100%1/1
shift() || '_parse_pipeline'
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 75 | 722 | my $prevlen = length $_; | |||||||||||||||||||||||||||
| 76 | 722 | my @pipe = $self->$how(@_); | |||||||||||||||||||||||||||
| 77 | 718 | ▶ | unless (s{^;}{}xs) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 7 | ▶ | if (/^\s|^$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | die $self->synerror_at($self->{_startln} | ||||||||||||||||||||||||||||
| 80 | 3 | , q{Entity has no terminator: '%s'} | |||||||||||||||||||||||||||
| 81 | , $self->shortened_original_entpath); | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | } else { | ||||||||||||||||||||||||||||
| 84 | die $self->synerror_at($self->{_startln} | ||||||||||||||||||||||||||||
| 85 | 4 | , q{Syntax error in entity: '%s'} | |||||||||||||||||||||||||||
| 86 | , $self->shortened_original_entpath); | ||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | 711 | $self->{_curpos} += $prevlen - length $_; | |||||||||||||||||||||||||||
| 90 | 711 | @pipe; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | 953 | ▶ | sub _parse_pipeline { | ||||||||||||||||||||||||||
|
Subroutine
_parse_pipeline: called CC=10 SCAR=23.1
| |||||||||||||||||||||||||||||
| 93 | 953 | (my MY $self) = @_; | |||||||||||||||||||||||||||
| 94 | 953 | ▶ | unless (defined $_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 0 | Carp::confess "parse_pipeline for undefined \$_!"; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | 953 | my @pipe; | |||||||||||||||||||||||||||
| 98 | 953 | ▶ | while (s{^ : (?<var>\w+) (?<open>\()? | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | | ^ (?<open>\[) | ||||||||||||||||||||||||||||
| 100 | | ^ (?<open>(?<hash>\{))}{}xs) { | ||||||||||||||||||||||||||||
| 101 | 1046 | ▶ | my $table = @pipe ? \%open_rest : \%open_head; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | my $type = $+{open} ? $table->{$+{open}} | ||||||||||||||||||||||||||||
| 103 | 1046 | ▶ | : @pipe ? 'prop' : 'var'; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 104 | 1046 | push @pipe, do { | |||||||||||||||||||||||||||
| 105 | # if (not @pipe and $+{hash}) { | ||||||||||||||||||||||||||||
| 106 | # [$type, $self->_parse_hash] | ||||||||||||||||||||||||||||
| 107 | # } else { | ||||||||||||||||||||||||||||
| 108 | [$type, defined $+{var} ? $+{var} : () | ||||||||||||||||||||||||||||
| 109 | , $+{open} | ||||||||||||||||||||||||||||
| 110 | 1046 | ▶ | ? $self->_parse_entgroup($close_ch{$+{open}}, $for_expr{$type}) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 111 | : ()]; | ||||||||||||||||||||||||||||
| 112 | # } | ||||||||||||||||||||||||||||
| 113 | }; | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | 949 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | @pipe | ||||||||||||||||||||||||||||
| 117 | 728 | } else { | |||||||||||||||||||||||||||
| 118 | 221 | ▶ | @pipe > 1 ? \@pipe : $pipe[0] | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | 589 | ▶ | sub _parse_entgroup { | ||||||||||||||||||||||||||
|
Subroutine
_parse_entgroup: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 122 | 589 | (my MY $self, my ($close, $for_expr)) = @_; | |||||||||||||||||||||||||||
| 123 | 589 | my $prevlen = length $_; | |||||||||||||||||||||||||||
| 124 | 589 | my $emptycnt; | |||||||||||||||||||||||||||
| 125 | my @pipe; | ||||||||||||||||||||||||||||
| 126 | 589 | ▶ | do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 963 | push @pipe, $self->_parse_entterm($for_expr); | |||||||||||||||||||||||||||
| 128 | 963 | ▶ | if (length $_ == $prevlen and $emptycnt++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
length $_ == $prevlen and $emptycnt++
MC/DC100%2/2
length $_ == $prevlen and $emptycnt++
length $_ == $prevlen
$emptycnt++
Truth table100%3/3
A and B
A= length $_ == $prevlenB= $emptycnt++
| |||||||||||||||||||||||||||||
| 129 | die $self->synerror_at($self->{_startln} | ||||||||||||||||||||||||||||
| 130 | 1 | , q{Syntax error in entity: '%s'} | |||||||||||||||||||||||||||
| 131 | , $self->shortened_original_entpath); | ||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | 962 | $prevlen = length $_; | |||||||||||||||||||||||||||
| 134 | } until (s{^ ($$self{_re_eclose})}{}xs); | ||||||||||||||||||||||||||||
| 135 | 588 | ▶ | die $self->synerror_at($self->{_startln}, q{Paren mismatch: expect %s got %s: str=%s} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | , $close, $1, $_) | ||||||||||||||||||||||||||||
| 137 | unless $1 eq $close; | ||||||||||||||||||||||||||||
| 138 | 585 | @pipe; | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | 963 | ▶ | sub _parse_entterm { | ||||||||||||||||||||||||||
|
Subroutine
_parse_entterm: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||
| 141 | 963 | (my MY $self, my ($for_expr)) = @_; | |||||||||||||||||||||||||||
| 142 | 963 | ▶ | my $text_type = $for_expr ? 'expr' : 'text'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 963 | ▶ | if (s{^ ,}{}xs) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 144 | 14 | return [text => '']; | |||||||||||||||||||||||||||
| 145 | } elsif (s{^ (?=[\)\]\};])}{}xs) { | ||||||||||||||||||||||||||||
| 146 | 159 | return; | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | 790 | my $term = do { | |||||||||||||||||||||||||||
| 149 | 790 | ▶ | if (s{^(?: (?<text> $$self{_ch_etext} (?:$$self{_ch_etext} | :)* ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | | $$self{_re_eparen} | ||||||||||||||||||||||||||||
| 151 | )}{}xs) { | ||||||||||||||||||||||||||||
| 152 | 569 | my $text = ''; | |||||||||||||||||||||||||||
| 153 | TEXT: { | ||||||||||||||||||||||||||||
| 154 | 569 | ▶ | do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | 1158 | ▶ | last TEXT if $+{close}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | 589 | ▶ | if (defined $+{text}) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 157 | 566 | $text .= $+{text}; | |||||||||||||||||||||||||||
| 158 | } elsif (defined $+{paren}) { | ||||||||||||||||||||||||||||
| 159 | 11 | $text .= $+{paren}; | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | $text .= $+{open} . $self->_parse_group_string($close_ch{$+{open}}) | ||||||||||||||||||||||||||||
| 162 | 589 | ▶ | if $+{open}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | } while (s{^ (?: (?<text> (?:$$self{_ch_etext} | :)+) | ||||||||||||||||||||||||||||
| 164 | | $$self{_re_eparen} | ||||||||||||||||||||||||||||
| 165 | | $$self{_re_eopen} | ||||||||||||||||||||||||||||
| 166 | | (?= (?<close>[\)\]\};,])))}{}xs); | ||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | 569 | ▶ | [($text =~ s/^=// ? 'expr' : $text_type) => $text]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | } else { | ||||||||||||||||||||||||||||
| 170 | 221 | $self->_parse_pipeline; | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | }; | ||||||||||||||||||||||||||||
| 173 | # Suffix. | ||||||||||||||||||||||||||||
| 174 | 790 | s{^ [,:]?}{}xs; | |||||||||||||||||||||||||||
| 175 | 790 | $term; | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 12 | ▶ | sub _parse_group_string { | ||||||||||||||||||||||||||
|
Subroutine
_parse_group_string: called CC=5 SCAR=17.8
| |||||||||||||||||||||||||||||
| 179 | 12 | (my MY $self, my $close) = @_; | |||||||||||||||||||||||||||
| 180 | 12 | my $oldpos = pos; | |||||||||||||||||||||||||||
| 181 | 12 | my $text = ''; | |||||||||||||||||||||||||||
| 182 | 12 | ▶ | while (s{^ ((?:$$self{_ch_etext}+ | [,:])*) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | (?: $$self{_re_eopen} | $$self{_re_eclose})}{}xs) { | ||||||||||||||||||||||||||||
| 184 | # print pos($_), "\n"; | ||||||||||||||||||||||||||||
| 185 | 12 | $text .= $&; | |||||||||||||||||||||||||||
| 186 | 12 | ▶ | if ($+{close}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | die $self->synerror_at($self->{_startln}, q{Paren mismatch: expect %s got %s: str=%s} | ||||||||||||||||||||||||||||
| 188 | , $close, $+{close}, substr($_, $oldpos, pos)) | ||||||||||||||||||||||||||||
| 189 | 12 | ▶ | unless $+{close} eq $close; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | 12 | last; | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | 0 | ▶ | $text .= $self->_parse_group_string($close_ch{$+{open}}) if $+{open}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | 12 | $text; | |||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 0 | ▶ | sub _parse_hash { | ||||||||||||||||||||||||||
|
Subroutine
_parse_hash: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 198 | 0 | (my MY $self) = @_; | |||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | 0 | my ($lastlen, @hash); | |||||||||||||||||||||||||||
| 201 | 0 | ▶ | while (not defined $lastlen or length $_ < $lastlen) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $lastlen or length $_ < $lastlen
MC/DC0%0/2
not defined $lastlen or length $_ < $lastlen
not defined $lastlen
length $_ < $lastlen
Truth table0%0/3
not(A) or B
A= not defined $lastlenB= length $_ < $lastlen
| |||||||||||||||||||||||||||||
| 202 | 0 | $lastlen = length $_; | |||||||||||||||||||||||||||
| 203 | 0 | ▶ | return @hash if s/^\}//; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 204 | 0 | ▶ | s{^ ($$self{_ch_etext}*) (?: [:,])}{}xs or last; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 205 | 0 | push @hash, [text => $1]; | |||||||||||||||||||||||||||
| 206 | 0 | push @hash, $self->_parse_entterm; | |||||||||||||||||||||||||||
| 207 | 0 | s{^,}{}; | |||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | 0 | die $self->synerror_at($self->{_startln}, q{Paren mismatch: expect \} got %s} | |||||||||||||||||||||||||||
| 210 | , $self->shortened_original_entpath); | ||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 47 | ▶ | use YATT::Lite::Breakpoint qw(break_load_parseentpath); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 214 | 47 | break_load_parseentpath(); | |||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 47 | 1; | |||||||||||||||||||||||||||