blib/lib/JQ/Lite/Tokenizer.pm

filter: Statementstmt 100% 28 / 28 Branchbran 62.5% 5 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 90.2% 37 / 41 CC 6 SCAR 14.7
CC
6
Cov
92%
tokenize
6.1
BEGIN
1.0
BEGIN
1.0
CRAP 4.4
« blib/lib/JQ/Lite/Builtin/Type.pm ↑ Summary blib/lib/JQ/Lite/Builtin/Math.pm »
1 package JQ::Lite::Tokenizer;
2  
3 182 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 182 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 182 ▶use JQ::Lite::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # The tokenizer deliberately recognizes only the top-level pipeline boundary.
9 # Filter-local syntax remains owned by the existing, compatibility-sensitive
10 # parser and filter implementations while those constructs are ported to ASTs.
11 1043 ▶sub tokenize {
Subroutine tokenize: called CC=6 SCAR=18.0
Pod undocumented
12 1043 my ($source) = @_;
13  
14 1043 ▶ return [] unless defined $source;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $source 0 1043 1043
15  
16 1043 my @parts = JQ::Lite::Util::_split_top_level_pipes($source);
17 1043 my @tokens;
18 1043 my $offset = 0;
19  
20 1043 for my $index (0 .. $#parts) {
21 1526 my $text = $parts[$index];
22 1526 my $start = index($source, $text, $offset);
23 1526 ▶ $start = $offset if $start < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $start < 0 0 1526 1526
24 1526 my $end = $start + length($text);
25  
26 1526 push @tokens, {
27 type => 'FILTER',
28 value => $text,
29 start => $start,
30 end => $end,
31 };
32  
33 1526 ▶ if ($index < $#parts) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index < $#parts) 483 1043 1526
34 483 my $pipe = index($source, '|', $end);
35 483 ▶ $pipe = $end if $pipe < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $pipe < 0 0 483 483
36 483 push @tokens, {
37 type => 'PIPE',
38 value => '|',
39 start => $pipe,
40 end => $pipe + 1,
41 };
42 483 $offset = $pipe + 1;
43 }
44 }
45  
46 1043 push @tokens, {
47 type => 'EOF',
48 value => undef,
49 start => length($source),
50 end => length($source),
51 };
52  
53 1043 return \@tokens;
54 }
55  
56 182 1;
« blib/lib/JQ/Lite/Builtin/Type.pm ↑ Summary blib/lib/JQ/Lite/Builtin/Math.pm »