Regexp/Tokenizer.pm

filter: Statementstmt 94.8% 511 / 539 Branchbran 75.4% 187 / 248 Conditioncond 70.0% 49 / 70 MC/DCmcdc 48.7% 20 / 41 Subroutinesub 95.5% 86 / 90 Podpod 100% 29 / 29 totaltotal 86.7% 882 / 1017 CC 157 SCAR 21.3
CC
157
Cov
87%
__initial_match
30.0
__PPIX_TOKENIZER__init
22.4
_update_location
16.2
CRAP 8.5
« Regexp/Structure/Quantifier.pm ↑ Summary Regexp/Lexer.pm »
1 package PPIx::Regexp::Tokenizer;
2  
3 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 9 ▶use base qw{ PPIx::Regexp::Support };
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 9 ▶use Carp qw{ carp croak confess };
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 ▶use PPI::Document;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 9 ▶use PPIx::Regexp::Constant qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
11 ARRAY_REF
12 CODE_REF
13 HASH_REF
14 LOCATION_LINE
15 LOCATION_CHARACTER
16 LOCATION_COLUMN
17 LOCATION_LOGICAL_LINE
18 MINIMUM_PERL
19 REGEXP_REF
20 TOKEN_LITERAL
21 TOKEN_UNKNOWN
22 @CARP_NOT
23 9 };
24 9 ▶use PPIx::Regexp::Token::Assertion ();
Subroutine BEGIN: called CC=1 SCAR=0.0
25 9 ▶use PPIx::Regexp::Token::Backreference ();
Subroutine BEGIN: called CC=1 SCAR=0.0
26 9 ▶use PPIx::Regexp::Token::Backtrack ();
Subroutine BEGIN: called CC=1 SCAR=0.0
27 9 ▶use PPIx::Regexp::Token::CharClass::POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
28 9 ▶use PPIx::Regexp::Token::CharClass::POSIX::Unknown ();
Subroutine BEGIN: called CC=1 SCAR=0.0
29 9 ▶use PPIx::Regexp::Token::CharClass::Simple ();
Subroutine BEGIN: called CC=1 SCAR=0.0
30 9 ▶use PPIx::Regexp::Token::Code ();
Subroutine BEGIN: called CC=1 SCAR=0.0
31 9 ▶use PPIx::Regexp::Token::Comment ();
Subroutine BEGIN: called CC=1 SCAR=0.0
32 9 ▶use PPIx::Regexp::Token::Condition ();
Subroutine BEGIN: called CC=1 SCAR=0.0
33 9 ▶use PPIx::Regexp::Token::Control ();
Subroutine BEGIN: called CC=1 SCAR=0.0
34 9 ▶use PPIx::Regexp::Token::Delimiter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
35 9 ▶use PPIx::Regexp::Token::Greediness ();
Subroutine BEGIN: called CC=1 SCAR=0.0
36 9 ▶use PPIx::Regexp::Token::GroupType::Assertion ();
Subroutine BEGIN: called CC=1 SCAR=0.0
37 9 ▶use PPIx::Regexp::Token::GroupType::Atomic_Script_Run ();
Subroutine BEGIN: called CC=1 SCAR=0.0
38 9 ▶use PPIx::Regexp::Token::GroupType::BranchReset ();
Subroutine BEGIN: called CC=1 SCAR=0.0
39 9 ▶use PPIx::Regexp::Token::GroupType::Code ();
Subroutine BEGIN: called CC=1 SCAR=0.0
40 9 ▶use PPIx::Regexp::Token::GroupType::Modifier ();
Subroutine BEGIN: called CC=1 SCAR=0.0
41 9 ▶use PPIx::Regexp::Token::GroupType::NamedCapture ();
Subroutine BEGIN: called CC=1 SCAR=0.0
42 9 ▶use PPIx::Regexp::Token::GroupType::Script_Run ();
Subroutine BEGIN: called CC=1 SCAR=0.0
43 9 ▶use PPIx::Regexp::Token::GroupType::Subexpression ();
Subroutine BEGIN: called CC=1 SCAR=0.0
44 9 ▶use PPIx::Regexp::Token::GroupType::Switch ();
Subroutine BEGIN: called CC=1 SCAR=0.0
45 9 ▶use PPIx::Regexp::Token::Interpolation ();
Subroutine BEGIN: called CC=1 SCAR=0.0
46 9 ▶use PPIx::Regexp::Token::Literal ();
Subroutine BEGIN: called CC=1 SCAR=0.0
47 9 ▶use PPIx::Regexp::Token::Modifier ();
Subroutine BEGIN: called CC=1 SCAR=0.0
48 9 ▶use PPIx::Regexp::Token::Operator ();
Subroutine BEGIN: called CC=1 SCAR=0.0
49 9 ▶use PPIx::Regexp::Token::Quantifier ();
Subroutine BEGIN: called CC=1 SCAR=0.0
50 9 ▶use PPIx::Regexp::Token::Recursion ();
Subroutine BEGIN: called CC=1 SCAR=0.0
51 9 ▶use PPIx::Regexp::Token::Structure ();
Subroutine BEGIN: called CC=1 SCAR=0.0
52 9 ▶use PPIx::Regexp::Token::Unknown ();
Subroutine BEGIN: called CC=1 SCAR=0.0
53 9 ▶use PPIx::Regexp::Token::Whitespace ();
Subroutine BEGIN: called CC=1 SCAR=0.0
54 9 ▶use PPIx::Regexp::Util qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
55 is_ppi_regexp_element
56 __instance
57 9 };
58  
59 9 ▶use Scalar::Util qw{ looks_like_number };
Subroutine BEGIN: called CC=1 SCAR=0.0
60  
61 9 our $VERSION = '0.092';
62  
63 9 our $DEFAULT_POSTDEREF;
64 9 ▶defined $DEFAULT_POSTDEREF
Branch: 1 branch
BranchTrueFalseTotal
defined $PPIx::Regexp::Tokenizer::DEFAULT_POSTDEREF or $PPIx::Regexp::Tokenizer::DEFAULT_POSTDEREF = 1 0 9 9
65 or $DEFAULT_POSTDEREF = 1;
66  
67 {
68 # Names of classes containing tokenization machinery. There are few
69 # known ordering requirements, since each class recognizes its own,
70 # and I have tried to prevent overlap. Absent such constraints, the
71 # order is in perceived frequency of acceptance, to keep the search
72 # as short as possible. If I were conscientious I would gather
73 # statistics on this.
74 9 my @classes = ( # TODO make readonly when acceptable way appears
75 'PPIx::Regexp::Token::Literal',
76 'PPIx::Regexp::Token::Interpolation',
77 'PPIx::Regexp::Token::Control', # Note 1
78 'PPIx::Regexp::Token::CharClass::Simple', # Note 2
79 'PPIx::Regexp::Token::Quantifier',
80 'PPIx::Regexp::Token::Greediness',
81 'PPIx::Regexp::Token::CharClass::POSIX', # Note 3
82 'PPIx::Regexp::Token::Structure',
83 'PPIx::Regexp::Token::Assertion',
84 'PPIx::Regexp::Token::Backreference',
85 'PPIx::Regexp::Token::Operator', # Note 4
86 );
87  
88 # Note 1: If we are in quote mode ( \Q ... \E ), Control makes a
89 # literal out of anything it sees other than \E. So it
90 # needs to come before almost all other tokenizers. Not
91 # Literal, which already makes literals, and not
92 # Interpolation, which is legal in quote mode, but
93 # everything else.
94  
95 # Note 2: CharClass::Simple must come after Literal, because it
96 # relies on Literal to recognize a Unicode named character
97 # ( \N{something} ), so any \N that comes through to it
98 # must be the \N simple character class (which represents
99 # anything but a newline, and was introduced in Perl
100 # 5.11.0.
101  
102 # Note 3: CharClass::POSIX has to come before Structure, since both
103 # look for square brackets, and CharClass::POSIX is the
104 # more particular.
105  
106 # Note 4: Operator relies on Literal making the characters literal
107 # if they appear in a context where they can not be
108 # operators, and Control making them literals if quoting,
109 # so it must come after both.
110  
111 # Return the declared tokenizer classes.
112 543 ▶ sub __tokenizer_classes {
Subroutine __tokenizer_classes: called CC=1 SCAR=0.0
113 543 return @classes;
114 }
115  
116 }
117  
118 {
119 9 my $errstr;
120  
121 742 ▶ sub new {
Subroutine new: called CC=10 SCAR=24.1
Pod documented
122 742 my ( $class, $re, %args ) = @_;
123 742 ▶ ref $class and $class = ref $class;
Branch: 1 branch
BranchTrueFalseTotal
ref $class and $class = ref $class 0 742 742
124  
125 742 $errstr = undef;
126  
127 exists $args{default_modifiers}
128 and ARRAY_REF ne ref $args{default_modifiers}
129 742 ▶ and do {
Branch: 1 branch
BranchTrueFalseTotal
exists $args{"default_modifiers"} and "ARRAY" ne ref $args{"default_modifiers"} and do { $errstr = "default_modifiers must be an array reference"; return } 0 742 742
Condition66%2/3
exists $args{"default_modifiers"} and "ARRAY" ne ref $args{"default_modifiers"}
!ll&&!rl&&r
73570
MC/DC0%0/2
exists $args{"default_modifiers"} and "ARRAY" ne ref $args{"default_modifiers"}
exists $args{"default_modifiers"} "ARRAY" ne ref $args{"default_modifiers"}
Truth table66%2/3
A and B
A= exists $args{"default_modifiers"}B= "ARRAY" ne ref $args{"default_modifiers"}
ABresult
0X0
100
111
130 0 $errstr = 'default_modifiers must be an array reference';
131 0 return;
132 };
133  
134 my $self = {
135 index_locations => $args{index_locations}, # Index locations
136 capture => undef, # Captures from find_regexp.
137 content => undef, # The string we are tokenizing.
138 cookie => {}, # Cookies
139 cursor_curr => 0, # The current position in the string.
140 cursor_limit => undef, # The end of the portion of the
141 # string being tokenized.
142 cursor_orig => undef, # Position of cursor when tokenizer
143 # called. Used by get_token to prevent
144 # recursion.
145 cursor_modifiers => undef, # Position of modifiers.
146 default_modifiers => $args{default_modifiers} || [],
147 delimiter_finish => undef, # Finishing delimiter of regexp.
148 delimiter_start => undef, # Starting delimiter of regexp.
149 encoding => $args{encoding}, # Character encoding.
150 expect => undef, # Extra classes to expect.
151 expect_next => undef, # Extra classes as of next parse cycle
152 failures => 0, # Number of parse failures.
153 find => undef, # String for find_regexp
154 known => {}, # Known tokenizers, by mode.
155 location => $args{location},
156 match => undef, # Match from find_regexp.
157 mode => 'init', # Initialize
158 modifiers => [{}], # Modifier hash.
159 pending => [], # Tokens made but not returned.
160 prior => TOKEN_UNKNOWN, # Prior significant token.
161 source => $re, # The object we were initialized with.
162 strict => $args{strict}, # like "use re 'strict';".
163 trace => __PACKAGE__->__defined_or(
164 742 ▶ $args{trace}, $ENV{PPIX_REGEXP_TOKENIZER_TRACE}, 0 ),
Condition100%2/2
$args{'default_modifiers'} || []
l!l
7735
MC/DC100%1/1
$args{'default_modifiers'} || []
$args{'default_modifiers'}
Truth table100%2/2
A
A= $args{'default_modifiers'}
Aresult
11
00
165 };
166  
167 742 ▶ if ( __instance( $re, 'PPI::Element' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (__instance($re, 'PPI::Element')) { } 11 731 742
elsif (ref $re) { } 2 729 731
168 11 ▶ is_ppi_regexp_element( $re )
Branch: 1 branch
BranchTrueFalseTotal
is_ppi_regexp_element($re) or return __set_errstr(ref $re, "not supported by", $class) 11 0 11
169 or return __set_errstr( ref $re, 'not supported by', $class );
170 # TODO conditionalizstion on PPI class does not really
171 # belong here, but at the moment I have no other idea of
172 # where to put it.
173 11 ▶ $self->{content} = $re->isa( 'PPI::Token::HereDoc' ) ?
Branch: 1 branch
BranchTrueFalseTotal
$re->isa('PPI::Token::HereDoc') ? : 0 11 11
174 join( '', $re->content(), "\n", $re->heredoc(),
175 $re->terminator(), "\n" ) :
176 $re->content();
177 } elsif ( ref $re ) {
178 2 return __set_errstr( ref $re, 'not supported' );
179 } else {
180 729 $self->{content} = $re;
181 }
182  
183 740 bless $self, $class;
184  
185 740 $self->{content} = $self->decode( $self->{content} );
186  
187 740 $self->{cursor_limit} = length $self->{content};
188  
189 $self->{trace}
190 740 ▶ and warn "\ntokenizing '$self->{content}'\n";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"trace"} and warn qq[\ntokenizing '$self->{"content"}'\n] 0 740 740
191  
192 740 return $self;
193 }
194  
195 2 ▶ sub __set_errstr {
Subroutine __set_errstr: called CC=1 SCAR=0.0
196 2 $errstr = join ' ', @_;
197 2 return;
198 }
199  
200 2 ▶ sub errstr {
Subroutine errstr: called CC=1 SCAR=0.0
Pod documented
201 2 return $errstr;
202 }
203  
204 }
205  
206 9 ▶sub capture {
Subroutine capture: called CC=4 SCAR=14.0
Pod documented
207 715 my ( $self ) = @_;
208 715 ▶ $self->{capture} or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"capture"} or return 694 21 715
209 694 ▶ defined wantarray or return;
Branch: 1 branch
BranchTrueFalseTotal
defined wantarray or return 694 0 694
210 694 ▶ return wantarray ? @{ $self->{capture} } : $self->{capture};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 694 0 694
211 }
212  
213 1 ▶sub content {
Subroutine content: called CC=1 SCAR=0.0
Pod documented
214 1 my ( $self ) = @_;
215 1 return $self->{content};
216 }
217  
218 10182 ▶sub cookie {
Subroutine cookie: called CC=6 SCAR=19.2
Pod documented
219 10182 my ( $self, $name, @args ) = @_;
220 10182 ▶ defined $name
Branch: 1 branch
BranchTrueFalseTotal
defined $name or confess("Programming error - undefined cookie name") 10182 0 10182
221 or confess "Programming error - undefined cookie name";
222 10182 ▶ if ( $self->{trace} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"trace"}) 0 10182 10182
223 0 local $" = ', ';
224 0 warn "cookie( '$name', @args )\n";
225 }
226 10182 ▶ @args or return $self->{cookie}{$name};
Branch: 1 branch
BranchTrueFalseTotal
@args or return $self->{"cookie"}{$name} 721 9461 10182
227 721 my $cookie = shift @args;
228 721 ▶ if ( CODE_REF eq ref $cookie ) {
Branch: 2 branches
BranchTrueFalseTotal
if ('CODE' eq ref $cookie) { } 593 128 721
elsif (defined $cookie) { } 0 128 128
229 593 return ( $self->{cookie}{$name} = $cookie );
230 } elsif ( defined $cookie ) {
231 0 confess "Programming error - cookie must be CODE ref or undef";
232 } else {
233 128 return delete $self->{cookie}{$name};
234 }
235 }
236  
237 # NOTE: Currently this is called only against
238 # COOKIE_LOOKAROUND_ASSERTION, once in PPIx::Token::GroupType::Assertion
239 # to prevent the cookie from being remade if it already exists, and once
240 # in PPIx::Regexp::Token::Assertion to determine if \K is inside a
241 # lookaround assertion. If it gets used other places, or if there is
242 # call for it, I should consider removing the underscores and
243 # documenting it as public.
244 57 ▶sub __cookie_exists {
Subroutine __cookie_exists: called CC=2 SCAR=7.1
245 57 my ( $self, $name ) = @_;
246 57 ▶ defined $name
Branch: 1 branch
BranchTrueFalseTotal
defined $name or confess("Programming error - undefined cookie name") 57 0 57
247 or confess "Programming error - undefined cookie name";
248 57 return $self->{cookie}{$name};
249 }
250  
251 0 ▶sub default_modifiers {
Subroutine default_modifiers: not called CC=1 SCAR=6.9
Pod documented
252 0 my ( $self ) = @_;
253 0 return [ @{ $self->{default_modifiers} } ];
254 }
255  
256 334 ▶sub __effective_modifiers {
Subroutine __effective_modifiers: called CC=2 SCAR=6.9
257 334 my ( $self ) = @_;
258 HASH_REF eq ref $self->{effective_modifiers}
259 334 ▶ or return {};
Branch: 1 branch
BranchTrueFalseTotal
"HASH" eq ref $self->{"effective_modifiers"} or return {} 326 8 334
260 326 return { %{ $self->{effective_modifiers} } };
261 }
262  
263 0 ▶sub encoding {
Subroutine encoding: not called CC=1 SCAR=6.9
Pod documented
264 0 my ( $self ) = @_;
265 0 return $self->{encoding};
266 }
267  
268 330 ▶sub expect {
Subroutine expect: called CC=3 SCAR=11.2
Pod documented
269 330 my ( $self, @args ) = @_;
270  
271 @args
272 330 ▶ or return;
Branch: 1 branch
BranchTrueFalseTotal
@args or return 330 0 330
273  
274 $self->{expect_next} = [
275 330 ▶ map { m/ \A PPIx::Regexp:: /smx ? $_ : 'PPIx::Regexp::' . $_ }
Branch: 1 branch
BranchTrueFalseTotal
/ \A PPIx::Regexp:: /msx ? : 2602 0 2602
276 @args
277 ];
278 330 $self->{expect} = undef;
279 330 return;
280 }
281  
282 8 ▶sub failures {
Subroutine failures: called CC=1 SCAR=0.0
Pod documented
283 8 my ( $self ) = @_;
284 8 return $self->{failures};
285 }
286  
287 589 ▶sub find_matching_delimiter {
Subroutine find_matching_delimiter: called CC=10 SCAR=23.0
Pod documented
288 589 my ( $self ) = @_;
289 589 ▶ $self->{cursor_curr} ||= 0;
Condition100%2/2
$self->{"cursor_curr"} ||= 0
l!l
208381
MC/DC100%1/1
$self->{"cursor_curr"} ||= 0
$self->{"cursor_curr"}
Truth table100%2/2
A
A= $self->{"cursor_curr"}
Aresult
11
00
290 my $start = substr
291 $self->{content},
292 $self->{cursor_curr},
293 589 1;
294  
295 589 my $inx = $self->{cursor_curr};
296 589 ▶ my $finish = (
Condition66%2/3
(my $bracketed = $self->close_bracket($start)) || $start
l!l&&r!l&&!r
495400
MC/DC0%0/2
(my $bracketed = $self->close_bracket($start)) || $start
(my $bracketed = $self->close_bracket($start)) $start
Truth table66%2/3
A || B
A= (my $bracketed = $self->close_bracket($start))B= $start
ABresult
1X1
011
000
297 my $bracketed = $self->close_bracket( $start ) ) || $start;
298  
299 =begin comment
300  
301 $self->{trace}
302 and warn "Find matching delimiter: Start with '$start' at $self->{cursor_curr}, end with '$finish' at or before $self->{cursor_limit}\n";
303  
304 =end comment
305  
306 =cut
307  
308 589 my $nest = 0;
309  
310 589 ▶ while ( ++$inx < $self->{cursor_limit} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$inx < $self->{"cursor_limit"}) 6144 2 6146
311 6144 my $char = substr $self->{content}, $inx, 1;
312  
313 =begin comment
314  
315 $self->{trace}
316 and warn " looking at '$char' at $inx, nest level $nest\n";
317  
318 =end comment
319  
320 =cut
321  
322 6144 ▶ if ( $char eq '\\' && $finish ne '\\' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($char eq '\\' and $finish ne '\\') { } 317 5827 6144
elsif ($bracketed and $char eq $start) { } 1 5826 5827
elsif ($char eq $finish) { } 588 5238 5826
Condition100%3/3
$char eq "\\" and $finish ne "\\"
!ll&&!rl&&r
58234317
MC/DC100%2/2
$char eq "\\" and $finish ne "\\"
$char eq "\\" $finish ne "\\"
Truth table100%3/3
A and B
A= $char eq "\\"B= $finish ne "\\"
ABresult
0X0
100
111
323 317 ++$inx;
324 ▶ } elsif ( $bracketed && $char eq $start ) {
Condition100%3/3
$bracketed and $char eq $start
!ll&&!rl&&r
55442821
MC/DC100%2/2
$bracketed and $char eq $start
$bracketed $char eq $start
Truth table100%3/3
A and B
A= $bracketedB= $char eq $start
ABresult
0X0
100
111
325 1 ++$nest;
326 } elsif ( $char eq $finish ) {
327 --$nest < 0
328 588 ▶ and return $inx - $self->{cursor_curr};
Branch: 1 branch
BranchTrueFalseTotal
--$nest < 0 and return $inx - $self->{"cursor_curr"} 587 1 588
329 }
330 }
331  
332 2 return;
333 }
334  
335 16627 ▶sub find_regexp {
Subroutine find_regexp: called CC=9 SCAR=22.5
Pod documented
336 16627 my ( $self, $regexp ) = @_;
337  
338 16627 ▶ REGEXP_REF eq ref $regexp
Branch: 1 branch
BranchTrueFalseTotal
"Regexp" eq ref $regexp or confess("Argument is a ", ref $regexp || "scalar", " not a Regexp") 16627 0 16627
Condition0%0/2
ref $regexp || 'scalar'
l!l
00
MC/DC0%0/1
ref $regexp || 'scalar'
ref $regexp
Truth table0%0/2
A
A= ref $regexp
Aresult
11
00
339 or confess
340 'Argument is a ', ( ref $regexp || 'scalar' ), ' not a Regexp';
341  
342 16627 ▶ defined $self->{find} or $self->_remainder();
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"find"} or $self->_remainder 13004 3623 16627
343  
344 16627 ▶ $self->{find} =~ $regexp
Branch: 1 branch
BranchTrueFalseTotal
$self->{"find"} =~ /$regexp/msx or return 1848 14779 16627
345 or return;
346  
347 1848 my @capture;
348 1848 foreach my $inx ( 0 .. $#+ ) {
349 4267 ▶ if ( defined $-[$inx] && defined $+[$inx] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $-[$inx] and defined $+[$inx]) { } 3778 489 4267
Condition66%2/3
defined $-[$inx] and defined $+[$inx]
!ll&&!rl&&r
48903778
MC/DC50%1/2
defined $-[$inx] and defined $+[$inx]
defined $-[$inx] defined $+[$inx]
Truth table66%2/3
A and B
A= defined $-[$inx]B= defined $+[$inx]
ABresult
0X0
100
111
350 push @capture, $self->{capture} = substr
351 $self->{find},
352 3778 $-[$inx],
353 $+[$inx] - $-[$inx];
354 } else {
355 489 push @capture, undef;
356 }
357 }
358 1848 $self->{match} = shift @capture;
359 1848 $self->{capture} = \@capture;
360  
361 # The following circumlocution seems to be needed under Perl 5.13.0
362 # for reasons I do not fathom -- at least in the case where
363 # wantarray is false. RT 56864 details the symptoms, which I was
364 # never able to reproduce outside Perl::Critic. But returning $+[0]
365 # directly, the value could transmogrify between here and the
366 # calling module.
367 ## my @data = ( $-[0], $+[0] );
368 ## return wantarray ? @data : $data[1];
369 1848 ▶ return wantarray ? ( $-[0] + 0, $+[0] + 0 ) : $+[0] + 0;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1848 1848
370 }
371  
372 2598 ▶sub get_mode {
Subroutine get_mode: called CC=1 SCAR=0.0
Pod documented
373 2598 my ( $self ) = @_;
374 2598 return $self->{mode};
375 }
376  
377 1794 ▶sub get_start_delimiter {
Subroutine get_start_delimiter: called CC=1 SCAR=0.0
Pod documented
378 1794 my ( $self ) = @_;
379 1794 return $self->{delimiter_start};
380 }
381  
382 4133 ▶sub get_token {
Subroutine get_token: called CC=5 SCAR=16.8
Pod documented
383 4133 my ( $self ) = @_;
384  
385 caller eq __PACKAGE__ or $self->{cursor_curr} > $self->{cursor_orig}
386 4133 ▶ or confess 'Programming error - get_token() called without ',
Branch: 1 branch
BranchTrueFalseTotal
caller eq __PACKAGE__ or $self->{"cursor_curr"} > $self->{"cursor_orig"} or confess("Programming error - get_token() called without ", "first calling make_token()") 4133 0 4133
Condition66%2/3
caller eq __PACKAGE__ or $self->{"cursor_curr"} > $self->{"cursor_orig"}
l!l&&r!l&&!r
4116170
MC/DC0%0/2
caller eq __PACKAGE__ or $self->{"cursor_curr"} > $self->{"cursor_orig"}
caller eq __PACKAGE__ $self->{"cursor_curr"} > $self->{"cursor_orig"}
Truth table66%2/3
A or B
A= caller eq __PACKAGE__B= $self->{"cursor_curr"} > $self->{"cursor_orig"}
ABresult
1X1
011
000
387 'first calling make_token()';
388  
389 4133 my $handler = '__PPIX_TOKENIZER__' . $self->{mode};
390  
391 my $code = $self->can( $handler )
392 or confess 'Programming error - ',
393 "Getting token in mode '$self->{mode}'. ",
394 "cursor_curr = $self->{cursor_curr}; ",
395 "cursor_limit = $self->{cursor_limit}; ",
396 "length( content ) = ", length $self->{content},
397 4133 ▶ "; content = '$self->{content}'";
Branch: 1 branch
BranchTrueFalseTotal
my $code = $self->can($handler) or confess("Programming error - ", qq[Getting token in mode '$self->{"mode"}'. ], qq[cursor_curr = $self->{"cursor_curr"}; ], qq[cursor_limit = $self->{"cursor_limit"}; ], "length( content ) = ", length $self->{"content"}, qq[; content = '$self->{"content"}']) 4133 0 4133
398  
399 my $character = substr(
400 $self->{content},
401 $self->{cursor_curr},
402 4133 1
403 );
404  
405 $self->{trace}
406 4133 ▶ and warn "get_token() got '$character' from $self->{cursor_curr}\n";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"trace"} and warn qq[get_token() got '${character}' from $self->{"cursor_curr"}\n] 0 4133 4133
407  
408 4133 return ( $code->( $self, $character ) );
409 }
410  
411 141 ▶sub interpolates {
Subroutine interpolates: called CC=1 SCAR=0.0
Pod documented
412 141 my ( $self ) = @_;
413 141 return $self->{delimiter_start} ne q{'};
414 }
415  
416 5243 ▶sub make_token {
Subroutine make_token: called CC=15 SCAR=27.7
Pod documented
417 5243 my ( $self, $length, $class, $arg ) = @_;
418 5243 ▶ defined $class or $class = caller;
Branch: 1 branch
BranchTrueFalseTotal
defined $class or $class = caller 5021 222 5243
419  
420 5243 ▶ if ( $length + $self->{cursor_curr} > $self->{cursor_limit} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length + $self->{"cursor_curr"} > $self->{"cursor_limit"}) 0 5243 5243
421 $length = $self->{cursor_limit} - $self->{cursor_curr}
422 0 ▶ or return;
Branch: 1 branch
BranchTrueFalseTotal
$length = $self->{"cursor_limit"} - $self->{"cursor_curr"} or return 0 0 0
423 }
424  
425 5243 ▶ $class =~ m/ \A PPIx::Regexp:: /smx
Branch: 1 branch
BranchTrueFalseTotal
$class =~ / \A PPIx::Regexp:: /msx or $class = 'PPIx::Regexp::' . $class 5243 0 5243
426 or $class = 'PPIx::Regexp::' . $class;
427 my $content = substr
428 $self->{content},
429 $self->{cursor_curr},
430 5243 $length;
431  
432 $self->{trace}
433 5243 ▶ and warn "make_token( $length, '$class' ) => '$content'\n";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"trace"} and warn "make_token( $length, '${class}' ) => '${content}'\n" 0 5243 5243
434 5243 ▶ $self->{trace} > 1
Branch: 1 branch
BranchTrueFalseTotal
$self->{"trace"} > 1 and warn qq[ make_token: cursor_curr = $self->{"cursor_curr"}; ], qq[cursor_limit = $self->{"cursor_limit"}\n] 0 5243 5243
435 and warn " make_token: cursor_curr = $self->{cursor_curr}; ",
436 "cursor_limit = $self->{cursor_limit}\n";
437 my $token = $class->__new( $content,
438 tokenizer => $self,
439 5243 ▶ %{ $arg || {} } )
Branch: 1 branch
BranchTrueFalseTotal
my $token = $class->__new($content, "tokenizer", $self, %{$arg or {};}) or return 5243 0 5243
Condition100%2/2
$arg || {}
l!l
1445099
MC/DC100%1/1
$arg || {}
$arg
Truth table100%2/2
A
A= $arg
Aresult
11
00
440 or return;
441  
442 $self->{index_locations}
443 5243 ▶ and $self->_update_location( $token );
Branch: 1 branch
BranchTrueFalseTotal
$self->{"index_locations"} and $self->_update_location($token) 94 5149 5243
444  
445 $token->significant()
446 5243 ▶ and $self->{expect} = undef;
Branch: 1 branch
BranchTrueFalseTotal
$token->significant and $self->{"expect"} = undef 5078 165 5243
447  
448 5243 ▶ $token->isa( TOKEN_UNKNOWN ) and $self->{failures}++;
Branch: 1 branch
BranchTrueFalseTotal
$token->isa("PPIx::Regexp::Token::Unknown") and ++$self->{"failures"} 37 5206 5243
449  
450 5243 $self->{cursor_curr} += $length;
451 5243 $self->{find} = undef;
452 5243 $self->{match} = undef;
453 5243 $self->{capture} = undef;
454  
455 5243 foreach my $name ( keys %{ $self->{cookie} } ) {
456 3615 my $cookie = $self->{cookie}{$name};
457 $cookie->( $self, $token )
458 3615 ▶ or delete $self->{cookie}{$name};
Branch: 1 branch
BranchTrueFalseTotal
&$cookie($self, $token) or delete $self->{"cookie"}{$name} 3559 56 3615
459 }
460  
461 # Record this token as the prior token if it is significant. We must
462 # do this after processing cookies, so that the cookies have access
463 # to the old token if they want.
464 $token->significant()
465 5243 ▶ and $self->{prior_significant_token} = $token;
Branch: 1 branch
BranchTrueFalseTotal
$token->significant and $self->{"prior_significant_token"} = $token 5078 165 5243
466  
467 5243 return $token;
468 }
469  
470 86 ▶sub match {
Subroutine match: called CC=1 SCAR=0.0
Pod documented
471 86 my ( $self ) = @_;
472 86 return $self->{match};
473 }
474  
475 4932 ▶sub modifier {
Subroutine modifier: called CC=1 SCAR=0.0
Pod documented
476 4932 my ( $self, $modifier ) = @_;
477 return PPIx::Regexp::Token::Modifier::__asserts(
478 4932 $self->{modifiers}[-1], $modifier );
479 }
480  
481 292 ▶sub modifier_duplicate {
Subroutine modifier_duplicate: called CC=1 SCAR=0.0
Pod documented
482 292 my ( $self ) = @_;
483 292 push @{ $self->{modifiers} },
484 292 { %{ $self->{modifiers}[-1] } };
485 292 return;
486 }
487  
488 595 ▶sub modifier_modify {
Subroutine modifier_modify: called CC=1 SCAR=0.0
Pod documented
489 595 my ( $self, %args ) = @_;
490  
491 # Modifier code is centralized in PPIx::Regexp::Token::Modifier
492 $self->{modifiers}[-1] =
493 PPIx::Regexp::Token::Modifier::__PPIX_TOKENIZER__modifier_modify(
494 595 $self->{modifiers}[-1], \%args );
495  
496 595 return;
497  
498 }
499  
500 288 ▶sub modifier_pop {
Subroutine modifier_pop: called CC=2 SCAR=6.9
Pod documented
501 288 my ( $self ) = @_;
502 288 @{ $self->{modifiers} } > 1
503 288 ▶ and pop @{ $self->{modifiers} };
Branch: 1 branch
BranchTrueFalseTotal
@{$self->{"modifiers"};} > 1 and pop @{$$self{"modifiers"};} 282 6 288
504 288 return;
505 }
506  
507 8 ▶sub modifier_seen {
Subroutine modifier_seen: called CC=3 SCAR=11.0
Pod documented
508 8 my ( $self, $modifier ) = @_;
509 8 foreach my $mod ( reverse @{ $self->{modifiers} } ) {
510 10 ▶ exists $mod->{$modifier}
Branch: 1 branch
BranchTrueFalseTotal
exists $mod->{$modifier} and return 1 3 7 10
511 and return 1;
512 }
513 5 return;
514 }
515  
516 5780 ▶sub next_token {
Subroutine next_token: called CC=6 SCAR=18.0
Pod documented
517 5780 my ( $self ) = @_;
518  
519 {
520  
521 5780 ▶ if ( @{ $self->{pending} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"pending"};}) 5241 4655 9896
522 5241 return shift @{ $self->{pending} };
523 }
524  
525 4655 ▶ if ( $self->{cursor_curr} >= $self->{cursor_limit} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"cursor_curr"} >= $self->{"cursor_limit"}) 1099 3556 4655
526 $self->{cursor_limit} >= length $self->{content}
527 1099 ▶ and return;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"cursor_limit"} >= length $self->{"content"} and return 539 560 1099
528 560 ▶ $self->{mode} eq 'finish' and return;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"mode"} eq "finish" and return 0 560 560
529 560 $self->_set_mode( 'finish' );
530 560 $self->{cursor_limit} += length $self->{delimiter_finish};
531 }
532  
533 4116 ▶ if ( my @tokens = $self->get_token() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@tokens) = $self->get_token) 4116 0 4116
534 4116 push @{ $self->{pending} }, @tokens;
535 4116 redo;
536  
537 }
538  
539 }
540  
541 0 return;
542  
543 }
544  
545 379 ▶sub peek {
Subroutine peek: called CC=4 SCAR=14.0
Pod documented
546 379 my ( $self, $offset ) = @_;
547 379 ▶ defined $offset or $offset = 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $offset or $offset = 0 314 65 379
548 379 ▶ $offset < 0 and return;
Branch: 1 branch
BranchTrueFalseTotal
$offset < 0 and return 0 379 379
549 379 $offset += $self->{cursor_curr};
550 379 ▶ $offset >= $self->{cursor_limit} and return;
Branch: 1 branch
BranchTrueFalseTotal
$offset >= $self->{"cursor_limit"} and return 0 379 379
551 379 return substr $self->{content}, $offset, 1;
552 }
553  
554 83 ▶sub ppi_document {
Subroutine ppi_document: called CC=2 SCAR=7.1
Pod documented
555 83 my ( $self ) = @_;
556  
557 83 ▶ defined $self->{find} or $self->_remainder();
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"find"} or $self->_remainder 83 0 83
558  
559 83 return PPI::Document->new( \"$self->{find}" );
560 }
561  
562 2413 ▶sub prior_significant_token {
Subroutine prior_significant_token: called CC=4 SCAR=15.6
Pod documented
563 2413 my ( $self, $method, @args ) = @_;
564 2413 ▶ defined $method or return $self->{prior_significant_token};
Branch: 1 branch
BranchTrueFalseTotal
defined $method or return $self->{"prior_significant_token"} 2394 19 2413
565 $self->{prior_significant_token}->can( $method )
566 or confess 'Programming error - ',
567 ( ref $self->{prior_significant_token} ||
568 2394 ▶ $self->{prior_significant_token} ),
Branch: 1 branch
BranchTrueFalseTotal
$self->{"prior_significant_token"}->can($method) or confess("Programming error - ", ref $self->{"prior_significant_token"} || $self->{"prior_significant_token"}, " does not support method ", $method) 2394 0 2394
Condition0%0/3
ref $self->{'prior_significant_token'} || $self->{'prior_significant_token'}
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self->{'prior_significant_token'} || $self->{'prior_significant_token'}
ref $self->{'prior_significant_token'} $self->{'prior_significant_token'}
Truth table0%0/3
A || B
A= ref $self->{'prior_significant_token'}B= $self->{'prior_significant_token'}
ABresult
1X1
011
000
569 ' does not support method ', $method;
570 2394 return $self->{prior_significant_token}->$method( @args );
571 }
572  
573 # my $length = $token->__recognize_postderef( $tokenizer, $iterator ).
574 #
575 # This method is private to the PPIx-Regexp package, and may be changed
576 # or retracted without warning. What it does is to recognize postfix
577 # dereferences. It returns the length in characters of the first postfix
578 # dereference found, or a false value if none is found.
579 #
580 # The optional $iterator argument can be one of the following:
581 # - A code reference, which will be called to provide PPI::Element
582 # objects to be checked to see if they represent a postfix
583 # dereference.
584 # - A PPI::Element, which is checked to see if it is a postfix
585 # dereference.
586 # - Undef, or omitted, in which case ppi() is called on the invocant,
587 # and everything that follows the '->' operator is checked to see if
588 # it is a postfix dereference.
589 # - Anything else results in an exception and stack trace.
590  
591 {
592 149 ▶ sub __recognize_postderef {
Subroutine __recognize_postderef: called CC=13 SCAR=26.0
593 149 my ( $self, $token, $iterator ) = @_;
594  
595 # Note that if ppi() gets called I have to hold a reference to
596 # the returned object until I am done with all its children.
597 149 my $ppi;
598 149 ▶ if ( ! defined $iterator ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $iterator) { } 145 4 149
elsif ($iterator->isa('PPI::Element')) { } 4 0 4
elsif ('CODE' ne ref $iterator) { } 0 0 0
599  
600 # This MUST be done before ppi() is called.
601 $self->{index_locations}
602 145 ▶ and $self->_update_location( $token );
Branch: 1 branch
BranchTrueFalseTotal
$self->{"index_locations"} and $self->_update_location($token) 2 143 145
603  
604 145 $ppi = $token->ppi();
605 29 my @ops = grep { '->' eq $_->content() } @{
606 145 ▶ $ppi->find( 'PPI::Token::Operator' ) || [] };
Condition100%2/2
$ppi->find('PPI::Token::Operator') || []
l!l
19126
MC/DC100%1/1
$ppi->find('PPI::Token::Operator') || []
$ppi->find('PPI::Token::Operator')
Truth table100%2/2
A
A= $ppi->find('PPI::Token::Operator')
Aresult
11
00
607 151 ▶ $iterator = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
608 151 ▶ my $op = shift @ops
Branch: 1 branch
BranchTrueFalseTotal
my $op = shift @ops or return 15 136 151
609 or return;
610 15 return $op->snext_sibling();
611 145 };
612 } elsif ( $iterator->isa( 'PPI::Element' ) ) {
613 4 my @eles = ( $iterator );
614 4 ▶ $iterator = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
615 4 return shift @eles;
616 4 };
617 } elsif ( CODE_REF ne ref $iterator ) {
618 0 confess 'Programming error - Iterator not understood';
619 }
620  
621 149 my $accept = $token->__postderef_accept_cast();
622  
623 149 ▶ while ( my $elem = $iterator->() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $elem = &$iterator()) 19 136 155
624  
625 19 my $content = $elem->content();
626  
627 # As of PPI 1.238, all postfix dereferences are parsed as
628 # casts. So if we find a cast of the correct content we have
629 # a postfix deref.
630 19 ▶ $elem->isa( 'PPI::Token::Cast' )
Branch: 1 branch
BranchTrueFalseTotal
$elem->isa("PPI::Token::Cast") or next 15 4 19
631 or next;
632  
633 15 ▶ if ( $content =~ m/ ( .* ) \* \z /smx ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($content =~ / ( .* ) \* \z /msx) { } 10 5 15
elsif ($accept->{$content}) { } 5 0 5
634 # If we're an acceptable cast ending in a glob, accept
635 # it.
636 10 ▶ $accept->{$1}
Branch: 1 branch
BranchTrueFalseTotal
$accept->{$1} and return length $content 8 2 10
637 and return length $content;
638 } elsif ( $accept->{$content} ) {
639 # If we're an acceptable cast followed by a subscript,
640 # we're a slice -- accept both cast and subscript.
641 5 ▶ my $next = $elem->snext_sibling()
Branch: 1 branch
BranchTrueFalseTotal
my $next = $elem->snext_sibling or next 5 0 5
642 or next;
643 5 ▶ $next->isa( 'PPI::Structure::Subscript' )
Branch: 1 branch
BranchTrueFalseTotal
$next->isa("PPI::Structure::Subscript") or next 5 0 5
644 or next;
645 5 return length( $content ) + length( $next->content() );
646 }
647  
648 # Otherwise, we're not a postfix dereference; try the next
649 # iteration.
650 }
651  
652 # No postfix dereference found.
653 136 return;
654 }
655 }
656  
657 9 ▶sub significant {
Subroutine significant: not called CC=1 SCAR=1.2
Pod documented
658 0 return 1;
659 }
660  
661 4 ▶sub strict {
Subroutine strict: called CC=1 SCAR=0.0
Pod documented
662 4 my ( $self ) = @_;
663 4 return $self->{strict};
664 }
665  
666 3036 ▶sub _known_tokenizers {
Subroutine _known_tokenizers: called CC=4 SCAR=13.9
667 3036 my ( $self ) = @_;
668  
669 3036 my $mode = $self->{mode};
670  
671 3036 my @expect;
672 3036 ▶ if ( $self->{expect_next} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"expect_next"}) 328 2708 3036
673 328 $self->{expect} = $self->{expect_next};
674 328 $self->{expect_next} = undef;
675 }
676 3036 ▶ if ( $self->{expect} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"expect"}) 334 2702 3036
677 @expect = $self->_known_tokenizer_check(
678 334 @{ $self->{expect} } );
679 }
680  
681 exists $self->{known}{$mode} and return (
682 3036 ▶ @expect, @{ $self->{known}{$mode} } );
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{"known"}{$mode} and return @expect, @{$self->{"known"}{$mode};} 2493 543 3036
683  
684 543 my @found = $self->_known_tokenizer_check(
685 $self->__tokenizer_classes() );
686  
687 543 $self->{known}{$mode} = \@found;
688 543 return (@expect, @found);
689 }
690  
691 877 ▶sub _known_tokenizer_check {
Subroutine _known_tokenizer_check: called CC=3 SCAR=11.0
692 877 my ( $self, @args ) = @_;
693  
694 877 my $handler = '__PPIX_TOKENIZER__' . $self->{mode};
695 877 my @found;
696  
697 877 foreach my $class ( @args ) {
698  
699 8611 ▶ $class->can( $handler ) or next;
Branch: 1 branch
BranchTrueFalseTotal
$class->can($handler) or next 8408 203 8611
700 8408 push @found, $class;
701  
702 }
703  
704 877 return @found;
705 }
706  
707 205 ▶sub tokens {
Subroutine tokens: called CC=2 SCAR=6.9
Pod documented
708 205 my ( $self ) = @_;
709  
710 205 my @rslt;
711 205 ▶ while ( my $token = $self->next_token() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $self->next_token) 1933 205 2138
712 1933 push @rslt, $token;
713 }
714  
715 205 return @rslt;
716 }
717  
718 # $self->_deprecation_notice( $type, $name );
719 #
720 # This method centralizes deprecation. Type is 'attribute' or
721 # 'method'. Deprecation is driven of the %deprecate hash. Values
722 # are:
723 # false - no warning
724 # 1 - warn on first use
725 # 2 - warn on each use
726 # 3 - die on each use.
727 #
728 # $self->_deprecation_in_progress( $type, $name )
729 #
730 # This method returns true if the deprecation is in progress. In
731 # fact it returns the deprecation level.
732  
733 =begin comment
734  
735 {
736  
737 my %deprecate = (
738 attribute => {
739 postderef => 3,
740 },
741 );
742  
743 sub _deprecation_notice {
744 my ( undef, $type, $name, $repl ) = @_; # Invocant unused
745 $deprecate{$type} or return;
746 $deprecate{$type}{$name} or return;
747 my $msg = sprintf 'The %s %s is %s', $name, $type,
748 $deprecate{$type}{$name} > 2 ? 'removed' : 'deprecated';
749 defined $repl
750 and $msg .= "; use $repl instead";
751 $deprecate{$type}{$name} >= 3
752 and croak $msg;
753 warnings::enabled( 'deprecated' )
754 and carp $msg;
755 $deprecate{$type}{$name} == 1
756 and $deprecate{$type}{$name} = 0;
757 return;
758 }
759  
760 sub _deprecation_in_progress {
761 my ( $self, $type, $name ) = @_;
762 $deprecate{$type} or return;
763 return $deprecate{$type}{$name};
764 }
765  
766 }
767  
768 =end comment
769  
770 =cut
771  
772 3623 ▶sub _remainder {
Subroutine _remainder: called CC=2 SCAR=7.0
773 3623 my ( $self ) = @_;
774  
775 $self->{cursor_curr} > $self->{cursor_limit}
776 3623 ▶ and confess "Programming error - Trying to find past end of string";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"cursor_curr"} > $self->{"cursor_limit"} and confess("Programming error - Trying to find past end of string") 0 3623 3623
777 $self->{find} = substr(
778 $self->{content},
779 $self->{cursor_curr},
780 $self->{cursor_limit} - $self->{cursor_curr}
781 3623 );
782  
783 3623 return;
784 }
785  
786 10 ▶sub _make_final_token {
Subroutine _make_final_token: called CC=1 SCAR=0.0
787 10 my ( $self, $len, $class, $arg ) = @_;
788 10 my $token = $self->make_token( $len, $class, $arg );
789 10 $self->_set_mode( 'kaput' );
790 10 return $token;
791 }
792  
793 1657 ▶sub _set_mode {
Subroutine _set_mode: called CC=3 SCAR=11.0
794 1657 my ( $self, $mode ) = @_;
795 $self->{trace}
796 1657 ▶ and warn "Tokenizer going from mode $self->{mode} to $mode\n";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"trace"} and warn qq[Tokenizer going from mode $self->{"mode"} to $mode\n] 0 1657 1657
797 1657 $self->{mode} = $mode;
798 1657 ▶ if ( 'kaput' eq $mode ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("kaput" eq $mode) 537 1120 1657
799 $self->{cursor_curr} = $self->{cursor_limit} =
800 537 length $self->{content};
801 }
802 1657 return;
803 }
804  
805 10 ▶sub __init_error {
Subroutine __init_error: called CC=2 SCAR=6.9
806 10 my ( $self , $err ) = @_;
807 10 ▶ defined $err
Branch: 1 branch
BranchTrueFalseTotal
defined $err or $err = "Tokenizer found illegal first characters" 2 8 10
808 or $err = 'Tokenizer found illegal first characters';
809 return $self->_make_final_token(
810 10 length $self->{content}, TOKEN_UNKNOWN, {
811 error => $err,
812 },
813 );
814 }
815  
816 107 ▶sub _update_location {
Subroutine _update_location: called CC=16 SCAR=27.8
817 107 my ( $self, $token ) = @_;
818 $token->{location} # Idempotent
819 107 ▶ and return;
Branch: 1 branch
BranchTrueFalseTotal
$token->{"location"} and return 2 105 107
820 105 ▶ my $loc = $self->{_location} ||= do {
Condition66%2/3
$self->{"_location"} ||= do { my(%loc) = ("location", $self->{"location"}); if (__instance($self->{"source"}, "PPI::Element")) { $loc{"location"} ||= $self->{"source"}->location; if (my $doc = $self->{"source"}->document) { $loc{"tab_width"} = $doc->tab_width; } ; } ; $loc{"tab_width"} ||= 1; \%loc }
l!l&&r!l&&!r
93120
MC/DC0%0/2
$self->{"_location"} ||= do { my(%loc) = ("location", $self->{"location"}); if (__instance($self->{"source"}, "PPI::Element")) { $loc{"location"} ||= $self->{"source"}->location; if (my $doc = $self->{"source"}->document) { $loc{"tab_width"} = $doc->tab_width; } ; } ; $loc{"tab_width"} ||= 1; \%loc }
$self->{"_location"} do { my(%loc) = ("location", $self->{"location"}); if (__instance($self->{"source"}, "PPI::Element")) { $loc{"location"} ||= $self->{"source"}->location; if (my $doc = $self->{"source"}->document) { $loc{"tab_width"} = $doc->tab_width; } ; } ; $loc{"tab_width"} ||= 1; \%loc }
Truth table66%2/3
A ||= B
A= $self->{"_location"}B= do { my(%loc) = ("location", $self->{"location"}); if (__instance($self->{"source"}, "PPI::Element")) { $loc{"location"} ||= $self->{"source"}->location; if (my $doc = $self->{"source"}->document) { $loc{"tab_width"} = $doc->tab_width; } ; } ; $loc{"tab_width"} ||= 1; \%loc }
ABresult
1X1
011
000
821 my %loc = (
822 location => $self->{location},
823 12 );
824 12 ▶ if ( __instance( $self->{source}, 'PPI::Element' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (__instance($self->{"source"}, "PPI::Element")) 11 1 12
825 11 ▶ $loc{location} ||= $self->{source}->location();
Condition33%1/3
$loc{"location"} ||= $self->{"source"}->location
l!l&&r!l&&!r
0110
MC/DC0%0/2
$loc{"location"} ||= $self->{"source"}->location
$loc{"location"} $self->{"source"}->location
Truth table33%1/3
A ||= B
A= $loc{"location"}B= $self->{"source"}->location
ABresult
1X1
011
000
826 11 ▶ if ( my $doc = $self->{source}->document() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $doc = $self->{"source"}->document) 11 0 11
827 11 $loc{tab_width} = $doc->tab_width();
828 }
829 }
830 12 ▶ $loc{tab_width} ||= 1;
Condition100%2/2
$loc{"tab_width"} ||= 1
l!l
111
MC/DC100%1/1
$loc{"tab_width"} ||= 1
$loc{"tab_width"}
Truth table100%2/2
A
A= $loc{"tab_width"}
Aresult
11
00
831 12 \%loc;
832 };
833 $loc->{location}
834 105 ▶ or return;
Branch: 1 branch
BranchTrueFalseTotal
$loc->{"location"} or return 105 0 105
835 105 $token->{location} = [ @{ $loc->{location} } ];
836 105 ▶ if ( defined( my $content = $token->content() ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $content = $token->content)) 105 0 105
837  
838 105 my $lines;
839 105 pos( $content ) = 0;
840 105 ▶ $lines++ while $content =~ m/ \n /smxgc;
Branch: 1 branch
BranchTrueFalseTotal
$content =~ / \n /cgmsx and do { ++$lines } 2 105 107
841 105 ▶ if ( pos $content ) {
Branch: 1 branch
BranchTrueFalseTotal
if (pos $content) 2 103 105
842 2 $loc->{location}[LOCATION_LINE] += $lines;
843 2 $loc->{location}[LOCATION_LOGICAL_LINE] += $lines;
844 $loc->{location}[LOCATION_CHARACTER] =
845 2 $loc->{location}[LOCATION_COLUMN] = 1;
846 }
847  
848 105 ▶ if ( my $chars = length( $content ) - pos( $content ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $chars = length($content) - pos($content)) 102 3 105
849 102 $loc->{location}[LOCATION_CHARACTER] += $chars;
850 102 ▶ if ( $loc->{tab_width} > 1 && $content =~ m/ \t /smx ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($loc->{'tab_width'} > 1 and $content =~ / \t /msx) { } 5 97 102
Condition100%3/3
$loc->{"tab_width"} > 1 and $content =~ / \t /msx
!ll&&!rl&&r
8895
MC/DC100%2/2
$loc->{"tab_width"} > 1 and $content =~ / \t /msx
$loc->{"tab_width"} > 1 $content =~ / \t /msx
Truth table100%3/3
A and B
A= $loc->{"tab_width"} > 1B= $content =~ / \t /msx
ABresult
0X0
100
111
851 5 my $pos = $loc->{location}[LOCATION_COLUMN];
852 5 my $tab_width = $loc->{tab_width};
853 # Stolen shamelessly from PPI::Document::_visual_length
854 5 my ( $vis_inc );
855 5 foreach my $part ( split /(\t)/, $content ) {
856 10 ▶ if ($part eq "\t") {
Branch: 1 branch
BranchTrueFalseTotal
if ($part eq "\t") { } 5 5 10
857 5 $vis_inc = $tab_width - ($pos-1) % $tab_width;
858 } else {
859 5 $vis_inc = length $part;
860 }
861 10 $pos += $vis_inc;
862 }
863 5 $loc->{location}[LOCATION_COLUMN] = $pos;
864 } else {
865 97 $loc->{location}[LOCATION_COLUMN] += $chars;
866 }
867 }
868  
869 }
870 105 return;
871 }
872  
873 537 ▶sub __PPIX_TOKENIZER__init {
Subroutine __PPIX_TOKENIZER__init: called CC=22 SCAR=31.1
874 537 my ( $self ) = @_;
875  
876 537 ▶ $self->find_regexp(
Branch: 1 branch
BranchTrueFalseTotal
$self->find_regexp(qr/ \A ( \s* ) ( qr | m | s )? ( \s* ) ( . ) /msx) or return $self->__init_error 537 0 537
877 qr{ \A ( \s* ) ( qr | m | s )? ( \s* ) ( . ) }smx )
878 or return $self->__init_error();
879  
880 537 my ( $leading_white, $type, $next_white, $delim_start ) = $self->capture();
881  
882 537 ▶ defined $type
Branch: 1 branch
BranchTrueFalseTotal
defined $type or $type = "" 149 388 537
883 or $type = '';
884  
885 537 ▶ $type
Branch: 1 branch
BranchTrueFalseTotal
$type or $delim_start =~ m[ \A [/?] \z ]msx or return $self->__init_error 531 6 537
Condition100%3/3
$type or $delim_start =~ m[ \A [/?] \z ]msx
l!l&&r!l&&!r
1493826
MC/DC100%2/2
$type or $delim_start =~ m[ \A [/?] \z ]msx
$type $delim_start =~ m[ \A [/?] \z ]msx
Truth table100%3/3
A or B
A= $typeB= $delim_start =~ m[ \A [/?] \z ]msx
ABresult
1X1
011
000
886 or $delim_start =~ m< \A [/?] \z >smx
887 or return $self->__init_error();
888 531 ▶ $type
Branch: 1 branch
BranchTrueFalseTotal
$type and not $next_white and $delim_start =~ / \A \w \z /msx and return $self->__init_error 2 529 531
Condition100%6/6
$type and not $next_white and $delim_start =~ / \A \w \z /msx
!ll&&!rl&&r
3901392
$type and not $next_white
!ll&&!rl&&r
3828141
MC/DC100%3/3
$type and not $next_white and $delim_start =~ / \A \w \z /msx
$type not $next_white $delim_start =~ / \A \w \z /msx
Truth table100%4/4
A and not(B) and C
A= $typeB= not $next_whiteC= $delim_start =~ / \A \w \z /msx
ABCresult
0XX0
10X0
1100
1111
889 and not $next_white
890 and $delim_start =~ m< \A \w \z >smx
891 and return $self->__init_error();
892  
893 529 $self->{type} = $type;
894  
895 529 my @tokens;
896  
897 529 ▶ '' ne $leading_white
Branch: 1 branch
BranchTrueFalseTotal
"" ne $leading_white and push @tokens, $self->make_token(length $leading_white, "PPIx::Regexp::Token::Whitespace") 1 528 529
898 and push @tokens, $self->make_token( length $leading_white,
899 'PPIx::Regexp::Token::Whitespace' );
900 529 push @tokens, $self->make_token( length $type,
901 'PPIx::Regexp::Token::Structure' );
902 529 ▶ '' ne $next_white
Branch: 1 branch
BranchTrueFalseTotal
"" ne $next_white and push @tokens, $self->make_token(length $next_white, "PPIx::Regexp::Token::Whitespace") 8 521 529
903 and push @tokens, $self->make_token( length $next_white,
904 'PPIx::Regexp::Token::Whitespace' );
905  
906 529 $self->{delimiter_start} = $delim_start;
907  
908 $self->{trace}
909 529 ▶ and warn "Tokenizer found regexp start delimiter '$delim_start' at $self->{cursor_curr}\n";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"trace"} and warn qq[Tokenizer found regexp start delimiter '${delim_start}' at $self->{"cursor_curr"}\n] 0 529 529
910  
911 529 ▶ if ( my $offset = $self->find_matching_delimiter() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $offset = $self->find_matching_delimiter) { } 529 0 529
912 529 my $cursor_limit = $self->{cursor_curr} + $offset;
913 $self->{trace}
914 529 ▶ and warn "Tokenizer found regexp end delimiter at $cursor_limit\n";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"trace"} and warn "Tokenizer found regexp end delimiter at $cursor_limit\n" 0 529 529
915 529 ▶ if ( $self->__number_of_extra_parts() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->__number_of_extra_parts) { } 46 483 529
916 ### my $found_embedded_comments;
917 46 ▶ if ( $self->close_bracket(
Branch: 1 branch
BranchTrueFalseTotal
if ($self->close_bracket($self->{'delimiter_start'})) { } 7 39 46
918 $self->{delimiter_start} ) ) {
919 pos $self->{content} = $self->{cursor_curr} +
920 7 $offset + 1;
921 # If we're bracketed, there may be Perl comments between
922 # the regex and the replacement. PPI gets the parse
923 # wrong as of 1.220, but if we get the handling of the
924 # underlying string right, we will Just Work when PPI
925 # gets it right.
926 7 ▶ while ( $self->{content} =~
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"content"} =~ / \G \s* \n \s* \# [^\n]* /cgmsx) 2 7 9
927 m/ \G \s* \n \s* \# [^\n]* /smxgc ) {
928 ## $found_embedded_comments = 1;
929 }
930 7 $self->{content} =~ m/ \s* /smxgc;
931 } else {
932 pos $self->{content} = $self->{cursor_curr} +
933 39 $offset;
934 }
935 # Localizing cursor_curr and delimiter_start would be
936 # cleaner, but I don't want the old values restored if a
937 # parse error occurs.
938 46 my $cursor_curr = $self->{cursor_curr};
939 46 my $delimiter_start = $self->{delimiter_start};
940 46 $self->{cursor_curr} = pos $self->{content};
941 $self->{delimiter_start} = substr
942 $self->{content},
943 $self->{cursor_curr},
944 46 1;
945 $self->{trace}
946 46 ▶ and warn "Tokenizer found replacement start delimiter '$self->{delimiter_start}' at $self->{cursor_curr}\n";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"trace"} and warn qq[Tokenizer found replacement start delimiter '$self->{"delimiter_start"}' at $self->{"cursor_curr"}\n] 0 46 46
947 46 ▶ if ( my $s_off = $self->find_matching_delimiter() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $s_off = $self->find_matching_delimiter) { } 44 2 46
948 $self->{cursor_modifiers} =
949 44 $self->{cursor_curr} + $s_off + 1;
950 $self->{trace}
951 44 ▶ and warn "Tokenizer found replacement end delimiter at @{[
Branch: 1 branch
BranchTrueFalseTotal
$self->{"trace"} and warn qq[Tokenizer found replacement end delimiter at @{[$self->{"cursor_curr"} + $s_off];}\n] 0 44 44
952 0 $self->{cursor_curr} + $s_off ]}\n";
953 44 $self->{cursor_curr} = $cursor_curr;
954 44 $self->{delimiter_start} = $delimiter_start;
955 } else {
956 $self->{trace}
957 2 ▶ and warn 'Tokenizer failed to find replacement',
Branch: 1 branch
BranchTrueFalseTotal
$self->{"trace"} and warn "Tokenizer failed to find replacement", qq[end delimiter starting at $self->{"cursor_curr"}\n] 0 2 2
958 "end delimiter starting at $self->{cursor_curr}\n";
959 2 $self->{cursor_curr} = 0;
960 # TODO If I were smart enough here I could check for
961 # PPI mis-parses like s{foo}
962 # #{bar}
963 # {baz}
964 # here, doing so if $found_embedded_comments (commented
965 # out above) is true. The problem is that there seem to
966 # as many mis-parses as there are possible delimiters.
967 2 return $self->__init_error(
968 'Tokenizer found mismatched replacement delimiters',
969 );
970 }
971 } else {
972 483 $self->{cursor_modifiers} = $cursor_limit + 1;
973 }
974 527 $self->{cursor_limit} = $cursor_limit;
975 } else {
976 0 $self->{cursor_curr} = 0;
977 return $self->_make_final_token(
978 0 length( $self->{content} ), TOKEN_UNKNOWN, {
979 error => 'Tokenizer found mismatched regexp delimiters',
980 },
981 );
982 }
983  
984 {
985 # We have to instantiate the trailing tokens now so we can
986 # figure out what modifiers are in effect. But we can't
987 # index their locations (if desired) because they are being
988 # instantiated out of order
989  
990 527 local $self->{index_locations} = 0;
991  
992 527 my @mods = @{ $self->{default_modifiers} };
993 527 pos $self->{content} = $self->{cursor_modifiers};
994 527 local $self->{cursor_curr} = $self->{cursor_modifiers};
995 527 local $self->{cursor_limit} = length $self->{content};
996 527 my @trailing;
997 {
998 527 my $len = $self->find_regexp( qr{ \A [[:lower:]]* }smx );
999 527 push @trailing, $self->make_token( $len,
1000 'PPIx::Regexp::Token::Modifier' );
1001 }
1002 527 ▶ if ( my $len = $self->find_regexp( qr{ \A \s+ }smx ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $len = $self->find_regexp(qr/ \A \s+ /msx)) 1 526 527
1003 1 push @trailing, $self->make_token( $len,
1004 'PPIx::Regexp::Token::Whitespace' );
1005 }
1006 527 ▶ if ( my $len = $self->find_regexp( qr{ \A .+ }smx ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $len = $self->find_regexp(qr/ \A .+ /msx)) 1 526 527
1007 1 push @trailing, $self->make_token( $len, TOKEN_UNKNOWN, {
1008 error => 'Trailing characters after expression',
1009 } );
1010 }
1011 527 $self->{trailing_tokens} = \@trailing;
1012 527 push @mods, $trailing[0]->content();
1013 $self->{effective_modifiers} =
1014 527 PPIx::Regexp::Token::Modifier::__aggregate_modifiers (
1015 @mods );
1016 $self->{modifiers} = [
1017 527 { %{ $self->{effective_modifiers} } },
1018 ];
1019 }
1020  
1021 $self->{delimiter_finish} = substr
1022 $self->{content},
1023 $self->{cursor_limit},
1024 527 1;
1025  
1026 527 push @tokens, $self->make_token( 1,
1027 'PPIx::Regexp::Token::Delimiter' );
1028  
1029 527 $self->_set_mode( 'regexp' );
1030  
1031 527 $self->{find} = undef;
1032  
1033 527 return @tokens;
1034 }
1035  
1036 # Match the initial part of the regexp including any leading white
1037 # space. The initial delimiter is the first thing not consumed, though
1038 # we check it for sanity.
1039 0 ▶sub __initial_match {
Subroutine __initial_match: not called CC=5 SCAR=34.0
1040 0 my ( $self ) = @_;
1041  
1042 0 ▶ $self->find_regexp(
Branch: 1 branch
BranchTrueFalseTotal
$self->find_regexp(qr/ \A ( \s* ) ( qr | m | s )? ( \s* ) (?: [^\w\s] ) /msx) or return 0 0 0
1043 qr{ \A ( \s* ) ( qr | m | s )? ( \s* ) (?: [^\w\s] ) }smx )
1044 or return;
1045  
1046 0 my ( $leading_white, $type, $next_white ) = $self->capture();
1047  
1048 0 ▶ defined $type
Branch: 1 branch
BranchTrueFalseTotal
defined $type or $type = "" 0 0 0
1049 or $type = '';
1050  
1051 0 $self->{type} = $type;
1052  
1053 0 my @tokens;
1054  
1055 0 ▶ '' ne $leading_white
Branch: 1 branch
BranchTrueFalseTotal
"" ne $leading_white and push @tokens, $self->make_token(length $leading_white, "PPIx::Regexp::Token::Whitespace") 0 0 0
1056 and push @tokens, $self->make_token( length $leading_white,
1057 'PPIx::Regexp::Token::Whitespace' );
1058 0 push @tokens, $self->make_token( length $type,
1059 'PPIx::Regexp::Token::Structure' );
1060 0 ▶ '' ne $next_white
Branch: 1 branch
BranchTrueFalseTotal
"" ne $next_white and push @tokens, $self->make_token(length $next_white, "PPIx::Regexp::Token::Whitespace") 0 0 0
1061 and push @tokens, $self->make_token( length $next_white,
1062 'PPIx::Regexp::Token::Whitespace' );
1063  
1064 0 return @tokens;
1065 }
1066  
1067 {
1068 9 my %extra_parts = (
1069 s => 1,
1070 );
1071  
1072 # Return the number of extra delimited parts. This will be 0 except
1073 # for s///, which will be 1.
1074 855 ▶ sub __number_of_extra_parts {
Subroutine __number_of_extra_parts: called CC=2 SCAR=6.9
1075 855 my ( $self ) = @_;
1076 855 ▶ return $extra_parts{$self->{type}} || 0;
Condition100%2/2
$extra_parts{$self->{'type'}} || 0
l!l
72783
MC/DC100%1/1
$extra_parts{$self->{'type'}} || 0
$extra_parts{$self->{'type'}}
Truth table100%2/2
A
A= $extra_parts{$self->{'type'}}
Aresult
11
00
1077 }
1078 }
1079  
1080 {
1081 9 my @part_class = qw{
1082 PPIx::Regexp::Structure::Regexp
1083 PPIx::Regexp::Structure::Replacement
1084 };
1085  
1086 # Return the classes for the parts of the expression.
1087 326 ▶ sub __part_classes {
Subroutine __part_classes: called CC=1 SCAR=0.0
1088 326 my ( $self ) = @_;
1089 326 my $max = $self->__number_of_extra_parts();
1090 326 return @part_class[ 0 .. $max ];
1091 }
1092 }
1093  
1094 9 ▶sub __PPIX_TOKENIZER__regexp {
Subroutine __PPIX_TOKENIZER__regexp: called CC=7 SCAR=19.8
1095 3036 my ( $self, $character ) = @_;
1096  
1097 3036 my $mode = $self->{mode};
1098 3036 my $handler = '__PPIX_TOKENIZER__' . $mode;
1099  
1100 3036 $self->{cursor_orig} = $self->{cursor_curr};
1101 3036 foreach my $class ( $self->_known_tokenizers() ) {
1102 13478 my @tokens = grep { $_ } $class->$handler( $self, $character );
1103 $self->{trace}
1104 13478 ▶ and warn $class, "->$handler( \$self, '$character' )",
Branch: 1 branch
BranchTrueFalseTotal
$self->{"trace"} and warn $class, "->$handler( \$self, '${character}' )", " => (@tokens)\n" 0 13478 13478
1105 " => (@tokens)\n";
1106 @tokens
1107 and return ( map {
1108 13478 ▶ ref $_ ? $_ : $self->make_token( $_,
Branch: 2 branches
BranchTrueFalseTotal
@tokens and return map({ref $_ ? $_ : $self->make_token($_, $class);} @tokens) 3009 10469 13478
ref $_ ? : 731 2302 3033
1109 $class ) } @tokens );
1110 }
1111  
1112 # Find a fallback processor for the character.
1113 27 ▶ my $fallback = __PACKAGE__->can( '__PPIX_TOKEN_FALLBACK__' . $mode )
Condition40%2/5
__PACKAGE__->can('__PPIX_TOKEN_FALLBACK__' . $mode) || __PACKAGE__->can('__PPIX_TOKEN_FALLBACK__regexp') || confess("Programming error - unable to find fallback for $mode")
l!l
270
__PACKAGE__->can('__PPIX_TOKEN_FALLBACK__' . $mode) or __PACKAGE__->can("__PPIX_TOKEN_FALLBACK__regexp")
l!l&&r!l&&!r
2700
MC/DC0%0/2
__PACKAGE__->can('__PPIX_TOKEN_FALLBACK__' . $mode) || __PACKAGE__->can('__PPIX_TOKEN_FALLBACK__regexp') || confess("Programming error - unable to find fallback for $mode")
__PACKAGE__->can('__PPIX_TOKEN_FALLBACK__' . $mode) __PACKAGE__->can("__PPIX_TOKEN_FALLBACK__regexp")
Truth table33%1/3
A or B
A= __PACKAGE__->can('__PPIX_TOKEN_FALLBACK__' . $mode)B= __PACKAGE__->can("__PPIX_TOKEN_FALLBACK__regexp")
ABresult
1X1
011
000
1114 || __PACKAGE__->can( '__PPIX_TOKEN_FALLBACK__regexp' )
1115 || confess "Programming error - unable to find fallback for $mode";
1116 27 return $fallback->( $self, $character );
1117 }
1118  
1119 9 *__PPIX_TOKENIZER__repl = \&__PPIX_TOKENIZER__regexp;
1120  
1121 18 ▶sub __PPIX_TOKEN_FALLBACK__regexp {
Subroutine __PPIX_TOKEN_FALLBACK__regexp: called CC=3 SCAR=11.0
1122 18 my ( $self, $character ) = @_;
1123  
1124 # As a fallback in regexp mode, any escaped character is a literal.
1125 18 ▶ if ( $character eq '\\'
Branch: 1 branch
BranchTrueFalseTotal
if ($character eq "\\" and $self->{"cursor_limit"} - $self->{"cursor_curr"} > 1) 2 16 18
Condition66%2/3
$character eq "\\" and $self->{"cursor_limit"} - $self->{"cursor_curr"} > 1
!ll&&!rl&&r
1602
MC/DC50%1/2
$character eq "\\" and $self->{"cursor_limit"} - $self->{"cursor_curr"} > 1
$character eq "\\" $self->{"cursor_limit"} - $self->{"cursor_curr"} > 1
Truth table66%2/3
A and B
A= $character eq "\\"B= $self->{"cursor_limit"} - $self->{"cursor_curr"} > 1
ABresult
0X0
100
111
1126 && $self->{cursor_limit} - $self->{cursor_curr} > 1
1127 ) {
1128 2 return $self->make_token( 2, TOKEN_LITERAL );
1129 }
1130  
1131 # Any normal character is unknown.
1132 16 return $self->make_token( 1, TOKEN_UNKNOWN, {
1133 error => 'Tokenizer found unexpected literal',
1134 },
1135 );
1136 }
1137  
1138 9 ▶sub __PPIX_TOKEN_FALLBACK__repl {
Subroutine __PPIX_TOKEN_FALLBACK__repl: called CC=6 SCAR=20.5
1139 9 my ( $self, $character ) = @_;
1140  
1141 # As a fallback in replacement mode, any escaped character is a literal.
1142 9 ▶ if ( $character eq '\\'
Branch: 1 branch
BranchTrueFalseTotal
if ($character eq "\\" and defined(my $next = $self->peek(1))) 5 4 9
Condition66%2/3
$character eq "\\" and defined(my $next = $self->peek(1))
!ll&&!rl&&r
405
MC/DC50%1/2
$character eq "\\" and defined(my $next = $self->peek(1))
$character eq "\\" defined(my $next = $self->peek(1))
Truth table66%2/3
A and B
A= $character eq "\\"B= defined(my $next = $self->peek(1))
ABresult
0X0
100
111
1143 && defined ( my $next = $self->peek( 1 ) ) ) {
1144  
1145 5 ▶ if ( $self->interpolates() || $next eq q<'> || $next eq '\\' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->interpolates or $next eq "'" or $next eq "\\") 5 0 5
Condition33%2/6
$self->interpolates or $next eq "'" or $next eq "\\"
l!l&&r!l&&!r
500
$self->interpolates or $next eq "'"
l!l&&r!l&&!r
500
MC/DC0%0/3
$self->interpolates or $next eq "'" or $next eq "\\"
$self->interpolates $next eq "'" $next eq "\\"
Truth table25%1/4
A or B or C
A= $self->interpolatesB= $next eq "'"C= $next eq "\\"
ABCresult
1XX1
01X1
0011
0000
1146 5 return $self->make_token( 2, TOKEN_LITERAL );
1147 }
1148 0 return $self->make_token( 1, TOKEN_LITERAL );
1149 }
1150  
1151 # So is any normal character.
1152 4 return $self->make_token( 1, TOKEN_LITERAL );
1153 }
1154  
1155 560 ▶sub __PPIX_TOKENIZER__finish {
Subroutine __PPIX_TOKENIZER__finish: called CC=7 SCAR=19.5
1156 560 my ( $self ) = @_; # $character unused
1157  
1158 $self->{cursor_limit} > length $self->{content}
1159 560 ▶ and confess "Programming error - ran off string";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"cursor_limit"} > length $self->{"content"} and confess("Programming error - ran off string") 0 560 560
1160  
1161 my @tokens = $self->make_token( length $self->{delimiter_finish},
1162 560 'PPIx::Regexp::Token::Delimiter' );
1163  
1164 560 ▶ if ( $self->{cursor_curr} == $self->{cursor_modifiers} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'cursor_curr'} == $self->{'cursor_modifiers'}) { } 516 44 560
1165  
1166 # We are out of string. Add the trailing tokens (created when we
1167 # did the initial bracket scan) and close up shop.
1168
1169 516 push @tokens, $self->_get_trailing_tokens();
1170  
1171 516 $self->_set_mode( 'kaput' );
1172  
1173 } else {
1174  
1175 # Clear the cookies, because we are going around again.
1176 44 $self->{cookie} = {};
1177  
1178 # Move the cursor limit to just before the modifiers.
1179 44 $self->{cursor_limit} = $self->{cursor_modifiers} - 1;
1180  
1181 # If the preceding regular expression was bracketed, we need to
1182 # consume possible whitespace and find another delimiter.
1183  
1184 44 ▶ if ( $self->close_bracket( $self->{delimiter_start} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->close_bracket($self->{"delimiter_start"})) 7 37 44
1185 7 my $accept;
1186 # If we are bracketed, there can be honest-to-God Perl
1187 # comments between the regexp and the replacement, not just
1188 # regexp comments. As of version 1.220, PPI does not get
1189 # this parse right, but if we can handle this is a string,
1190 # then we will Just Work when PPI gets itself straight.
1191 7 ▶ while ( $self->find_regexp(
Branch: 1 branch
BranchTrueFalseTotal
if ($self->find_regexp(qr/ \A ( \s* \n \s* ) ( \# [^\n]* \n ) /msx)) 2 7 9
1192 qr{ \A ( \s* \n \s* ) ( \# [^\n]* \n ) }smx ) ) {
1193 2 my ( $white_space, $comment ) = $self->capture();
1194 2 push @tokens, $self->make_token(
1195 length $white_space,
1196 'PPIx::Regexp::Token::Whitespace',
1197 ), $self->make_token(
1198 length $comment,
1199 'PPIx::Regexp::Token::Comment',
1200 );
1201 }
1202 7 ▶ $accept = $self->find_regexp( qr{ \A \s+ }smx )
Branch: 1 branch
BranchTrueFalseTotal
$accept = $self->find_regexp(qr/ \A \s+ /msx) and push @tokens, $self->make_token($accept, "PPIx::Regexp::Token::Whitespace") 3 4 7
1203 and push @tokens, $self->make_token(
1204 $accept, 'PPIx::Regexp::Token::Whitespace' );
1205 7 my $character = $self->peek();
1206 7 $self->{delimiter_start} = $character;
1207 7 push @tokens, $self->make_token(
1208 1, 'PPIx::Regexp::Token::Delimiter' );
1209 $self->{delimiter_finish} = substr
1210 $self->{content},
1211 7 $self->{cursor_limit} - 1,
1212 1;
1213 }
1214  
1215 44 ▶ if ( $self->modifier( 'e*' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->modifier('e*')) { } 11 33 44
1216 # With /e or /ee, the replacement portion is code. We make
1217 # it all into one big PPIx::Regexp::Token::Code, slap on the
1218 # trailing delimiter and modifiers, and return it all.
1219 push @tokens, $self->make_token(
1220 $self->{cursor_limit} - $self->{cursor_curr},
1221 11 'PPIx::Regexp::Token::Code',
1222 { perl_version_introduced => MINIMUM_PERL },
1223 );
1224 11 $self->{cursor_limit} = length $self->{content};
1225 11 push @tokens, $self->make_token( 1,
1226 'PPIx::Regexp::Token::Delimiter' ),
1227 $self->_get_trailing_tokens();
1228 11 $self->_set_mode( 'kaput' );
1229 } else {
1230 # Put our mode to replacement.
1231 33 $self->_set_mode( 'repl' );
1232 }
1233  
1234 }
1235  
1236 560 return @tokens;
1237  
1238 }
1239  
1240 # To common processing on trailing tokens.
1241 527 ▶sub _get_trailing_tokens {
Subroutine _get_trailing_tokens: called CC=3 SCAR=11.0
1242 527 my ( $self ) = @_;
1243 527 ▶ if ( $self->{index_locations} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"index_locations"}) 11 516 527
1244 # We turned off index_locations when these were created, because
1245 # they were done out of order. Fix that now.
1246 11 foreach my $token ( @{ $self->{trailing_tokens} } ) {
1247 11 $self->_update_location( $token );
1248 }
1249 }
1250 527 return @{ delete $self->{trailing_tokens} };
1251 }
1252  
1253 9 1;
1254  
1255 __END__
« Regexp/Structure/Quantifier.pm ↑ Summary Regexp/Lexer.pm »