blib/lib/Text/Nunjucks/Parser/Parser.pm

filter: Statementstmt 49.0% 660 / 1345 Branchbran 43.9% 288 / 656 Conditioncond 43.6% 124 / 284 MC/DCmcdc 38.4% 63 / 164 Subroutinesub 56.1% 73 / 130 Podpod 0.0% 0 / 115 totaltotal 44.8% 1208 / 2694 CC 427 SCAR 35.0
CC
427
Cov
47%
parse_statement
158.8
parse_statement
158.8
parse_nodes
58.3
CRAP 33.1
« blib/lib/Text/Nunjucks/Nodes.pm ↑ Summary blib/lib/Text/Nunjucks/Runtime/Regex.pm »
1 package Text::Nunjucks::Parser::Parser;
2 # ABSTRACT: The recursive-descent parser (parser.js class Parser)
3  
4 19 our $VERSION = '0.001';
5  
6 19 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 19 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 19 ▶use builtin qw( true false );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 19 ▶use Text::Nunjucks::Lexer;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 19 ▶use Text::Nunjucks::Nodes;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 19 ▶use Text::Nunjucks::Lib;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 19 ▶use Text::Nunjucks::Lib::TemplateError;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 19 ▶use Text::Nunjucks::Lib::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 19 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 19 ▶no warnings 'experimental::builtin';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # upstream: class Parser extends Obj in parser.js (ADR 0002: a Moo class).
19  
20 # init(tokens): this.tokens / this.peeked = null / this.breakOnBlocks = null /
21 # this.dropLeadingWhitespace = false / this.extensions = []. Field spelling
22 # follows upstream (breakOnBlocks, dropLeadingWhitespace) as Lexer keeps
23 # trimBlocks; the mutated state is rw.
24 19 has tokens => ( is => 'rw' );
25 19 has peeked => ( is => 'rw' );
26 19 has breakOnBlocks => ( is => 'rw' );
27 9618 ▶has dropLeadingWhitespace => ( is => 'rw', default => sub { 0 } );
Subroutine __ANON__: called CC=1 SCAR=0.0
28 9618 ▶has extensions => ( is => 'rw', default => sub { [] } );
Subroutine __ANON__: called CC=1 SCAR=0.0
29  
30 # new Parser(tokens): positional constructor.
31 9618 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
32 9618 my ( $orig, $class, $tokens ) = @_;
33 9618 return $class->$orig( tokens => $tokens );
34 19 };
35  
36 # Collaborators named once (house rule); mirror parser.js's `lexer`, `nodes`
37 # and `lib` module references and the two error constructors.
38 2944061 ▶sub lexer { 'Text::Nunjucks::Lexer' }
Subroutine lexer: called CC=1 SCAR=0.0
Pod undocumented
39 55432 ▶sub lib { 'Text::Nunjucks::Lib' }
Subroutine lib: called CC=1 SCAR=0.0
Pod undocumented
40 19 ▶sub nodes_module { 'Text::Nunjucks::Nodes' }
Subroutine nodes_module: called CC=1 SCAR=0.0
Pod undocumented
41 39 ▶sub template_error_class { 'Text::Nunjucks::Lib::TemplateError' }
Subroutine template_error_class: called CC=1 SCAR=0.0
Pod undocumented
42 0 ▶sub error_class { 'Text::Nunjucks::Lib::Error' }
Subroutine error_class: not called CC=1 SCAR=6.9
Pod undocumented
43  
44 # nodes.X -> the concrete node class; one resolver so a subclass can redirect.
45 206821 ▶sub node {
Subroutine node: called CC=1 SCAR=1.2
Pod undocumented
46 0 ▶ my ( $self, $name ) = @_;
Subroutine node: not called CC=1 SCAR=1.2
Pod undocumented
47 0 return 'Text::Nunjucks::Nodes::' . $name;
48 }
49  
50 # JS String.prototype.charAt: '' outside [0, length). Used by the block-end /
51 # variable-end / whitespace-control checks below, where Perl's substr differs
52 # (negative offsets wrap). Same helper the Tokenizer keeps.
53 43830 ▶sub _char_at {
Subroutine _char_at: called CC=3 SCAR=14.2
54 0 ▶ my ( $self, $str, $i ) = @_;
Subroutine _char_at: not called CC=3 SCAR=14.2
55 0 ▶ return '' if $i < 0 || $i >= length($str);
Branch: 2 branches
BranchTrueFalseTotal
if $i < 0 or $i >= length $str 19701 24129 43830
if $i < 0 or $i >= length $str 0 0 0
Condition50%3/6
$i < 0 or $i >= length $str
l!l&&r!l&&!r
12396730524129
$i < 0 or $i >= length $str
l!l&&r!l&&!r
000
MC/DC100%2/2
$i < 0 or $i >= length $str
$i < 0 $i >= length $str
MC/DC0%0/2
$i < 0 or $i >= length $str
$i < 0 $i >= length $str
Truth table100%3/3
A or B
A= $i < 0B= $i >= length $str
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $i < 0B= $i >= length $str
ABresult
1X1
011
000
56 0 return substr( $str, $i, 1 );
57 }
58  
59 1254200 ▶sub next_token {
Subroutine next_token: called CC=7 SCAR=28.4
Pod undocumented
60 0 ▶ my ( $self, $with_whitespace ) = @_;
Subroutine next_token: not called CC=7 SCAR=28.4
Pod undocumented
61 0 my $tok;
62  
63 0 ▶ if ( $self->peeked ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->peeked) 1019629 234571 1254200
if ($self->peeked) 0 0 0
64 0 ▶ if ( !$with_whitespace && $self->peeked->type eq $self->lexer->TOKEN_WHITESPACE ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $with_whitespace and $self->peeked->type eq $self->lexer->TOKEN_WHITESPACE) { } 0 1019629 1019629
if (not $with_whitespace and $self->peeked->type eq $self->lexer->TOKEN_WHITESPACE) { } 0 0 0
Condition16%1/6
not $with_whitespace and $self->peeked->type eq $self->lexer->TOKEN_WHITESPACE
!ll&&!rl&&r
010196290
not $with_whitespace and $self->peeked->type eq $self->lexer->TOKEN_WHITESPACE
!ll&&!rl&&r
000
MC/DC0%0/2
not $with_whitespace and $self->peeked->type eq $self->lexer->TOKEN_WHITESPACE
not $with_whitespace $self->peeked->type eq $self->lexer->TOKEN_WHITESPACE
MC/DC0%0/2
not $with_whitespace and $self->peeked->type eq $self->lexer->TOKEN_WHITESPACE
not $with_whitespace $self->peeked->type eq $self->lexer->TOKEN_WHITESPACE
Truth table33%1/3
not(A) and B
A= not $with_whitespaceB= $self->peeked->type eq $self->lexer->TOKEN_WHITESPACE
ABresult
0X0
100
111
Truth table0%0/3
not(A) and B
A= not $with_whitespaceB= $self->peeked->type eq $self->lexer->TOKEN_WHITESPACE
ABresult
0X0
100
111
65 0 $self->peeked(undef);
66 }
67 else {
68 0 $tok = $self->peeked;
69 0 $self->peeked(undef);
70 0 return $tok;
71 }
72 }
73  
74 0 $tok = $self->tokens->next_token;
75  
76 0 ▶ if ( !$with_whitespace ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($with_whitespace) 234571 0 234571
unless ($with_whitespace) 0 0 0
77 0 ▶ while ( $tok && $tok->type eq $self->lexer->TOKEN_WHITESPACE ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tok and $tok->type eq $self->lexer->TOKEN_WHITESPACE) 105113 234571 339684
if ($tok and $tok->type eq $self->lexer->TOKEN_WHITESPACE) 0 0 0
Condition50%3/6
$tok and $tok->type eq $self->lexer->TOKEN_WHITESPACE
!ll&&!rl&&r
13382221189105113
$tok and $tok->type eq $self->lexer->TOKEN_WHITESPACE
!ll&&!rl&&r
000
MC/DC100%2/2
$tok and $tok->type eq $self->lexer->TOKEN_WHITESPACE
$tok $tok->type eq $self->lexer->TOKEN_WHITESPACE
MC/DC0%0/2
$tok and $tok->type eq $self->lexer->TOKEN_WHITESPACE
$tok $tok->type eq $self->lexer->TOKEN_WHITESPACE
Truth table100%3/3
A and B
A= $tokB= $tok->type eq $self->lexer->TOKEN_WHITESPACE
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $tokB= $tok->type eq $self->lexer->TOKEN_WHITESPACE
ABresult
0X0
100
111
78 0 $tok = $self->tokens->next_token;
79 }
80 }
81  
82 0 return $tok;
83 }
84  
85 264889 ▶sub peek_token {
Subroutine peek_token: called CC=2 SCAR=9.2
Pod undocumented
86 0 ▶ my ($self) = @_;
Subroutine peek_token: not called CC=2 SCAR=9.2
Pod undocumented
87 0 ▶ $self->peeked( $self->peeked || $self->next_token );
Condition50%3/6
$self->peeked || $self->next_token
l!l&&r!l&&!r
1149351462493705
$self->peeked || $self->next_token
l!l&&r!l&&!r
000
MC/DC100%2/2
$self->peeked || $self->next_token
$self->peeked $self->next_token
MC/DC0%0/2
$self->peeked || $self->next_token
$self->peeked $self->next_token
Truth table100%3/3
A || B
A= $self->peekedB= $self->next_token
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $self->peekedB= $self->next_token
ABresult
1X1
011
000
88 0 return $self->peeked;
89 }
90  
91 873481 ▶sub push_token {
Subroutine push_token: called CC=2 SCAR=11.6
Pod undocumented
92 0 ▶ my ( $self, $tok ) = @_;
Subroutine push_token: not called CC=2 SCAR=11.6
Pod undocumented
93 0 ▶ if ( $self->peeked ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->peeked) 0 873481 873481
if ($self->peeked) 0 0 0
94 0 die $self->error_class->new('pushToken: can only push one token on between reads');
95 }
96 0 $self->peeked($tok);
97 }
98  
99 39 ▶sub error {
Subroutine error: called CC=7 SCAR=26.4
Pod undocumented
100 0 ▶ my ( $self, $msg, $lineno, $colno ) = @_;
Subroutine error: not called CC=7 SCAR=26.4
Pod undocumented
101 0 ▶ if ( !defined $lineno || !defined $colno ) {
Branch: 2 branches
BranchTrueFalseTotal
unless (defined $lineno and defined $colno) 16 23 39
unless (defined $lineno and defined $colno) 0 0 0
Condition33%2/6
defined $lineno and defined $colno
!ll&&!rl&&r
16023
defined $lineno and defined $colno
!ll&&!rl&&r
000
MC/DC50%1/2
defined $lineno and defined $colno
defined $lineno defined $colno
MC/DC0%0/2
defined $lineno and defined $colno
defined $lineno defined $colno
Truth table66%2/3
A and B
A= defined $linenoB= defined $colno
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $linenoB= defined $colno
ABresult
0X0
100
111
102 0 my $tok = $self->peek_token; # JS: this.peekToken() || {}
103 0 ▶ $lineno = $tok ? $tok->lineno : undef;
Branch: 2 branches
BranchTrueFalseTotal
$tok ? : 3 13 16
$tok ? : 0 0 0
104 0 ▶ $colno = $tok ? $tok->colno : undef;
Branch: 2 branches
BranchTrueFalseTotal
$tok ? : 3 13 16
$tok ? : 0 0 0
105 }
106 0 ▶ $lineno += 1 if defined $lineno;
Branch: 2 branches
BranchTrueFalseTotal
if defined $lineno 26 13 39
if defined $lineno 0 0 0
107 0 ▶ $colno += 1 if defined $colno;
Branch: 2 branches
BranchTrueFalseTotal
if defined $colno 26 13 39
if defined $colno 0 0 0
108 0 return $self->template_error_class->new( $msg, $lineno, $colno );
109 }
110  
111 33 ▶sub fail {
Subroutine fail: called CC=1 SCAR=1.2
Pod undocumented
112 0 ▶ my ( $self, $msg, $lineno, $colno ) = @_;
Subroutine fail: not called CC=1 SCAR=1.2
Pod undocumented
113 0 die $self->error( $msg, $lineno, $colno );
114 }
115  
116 69036 ▶sub skip {
Subroutine skip: called CC=3 SCAR=14.2
Pod undocumented
117 0 ▶ my ( $self, $type ) = @_;
Subroutine skip: not called CC=3 SCAR=14.2
Pod undocumented
118 0 my $tok = $self->next_token;
119 0 ▶ if ( !$tok || $tok->type ne $type ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $tok or $tok->type ne $type) 50095 18941 69036
if (not $tok or $tok->type ne $type) 0 0 0
Condition50%3/6
not $tok or $tok->type ne $type
l!l&&r!l&&!r
55009018941
not $tok or $tok->type ne $type
l!l&&r!l&&!r
000
MC/DC100%2/2
not $tok or $tok->type ne $type
not $tok $tok->type ne $type
MC/DC0%0/2
not $tok or $tok->type ne $type
not $tok $tok->type ne $type
Truth table100%3/3
not(A) or B
A= not $tokB= $tok->type ne $type
ABresult
1X1
011
000
Truth table0%0/3
not(A) or B
A= not $tokB= $tok->type ne $type
ABresult
1X1
011
000
120 0 $self->push_token($tok);
121 0 return 0;
122 }
123 0 return 1;
124 }
125  
126 10481 ▶sub expect {
Subroutine expect: called CC=2 SCAR=11.2
Pod undocumented
127 0 ▶ my ( $self, $type ) = @_;
Subroutine expect: not called CC=2 SCAR=11.2
Pod undocumented
128 0 my $tok = $self->next_token;
129 0 ▶ if ( $tok->type ne $type ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tok->type ne $type) 0 10481 10481
if ($tok->type ne $type) 0 0 0
130 0 $self->fail( 'expected ' . $type . ', got ' . $tok->type,
131 $tok->lineno, $tok->colno );
132 }
133 0 return $tok;
134 }
135  
136 761818 ▶sub skip_value {
Subroutine skip_value: called CC=4 SCAR=17.9
Pod undocumented
137 0 ▶ my ( $self, $type, $val ) = @_;
Subroutine skip_value: not called CC=4 SCAR=17.9
Pod undocumented
138 0 my $tok = $self->next_token;
139 0 ▶ if ( !$tok || $tok->type ne $type || $tok->value ne $val ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $tok or $tok->type ne $type or $tok->value ne $val) 736071 25747 761818
if (not $tok or $tok->type ne $type or $tok->value ne $val) 0 0 0
Condition50%6/12
not $tok or $tok->type ne $type or $tok->value ne $val
l!l&&r!l&&!r
6739636210825747
not $tok or $tok->type ne $type
l!l&&r!l&&!r
7267389187855
not $tok or $tok->type ne $type or $tok->value ne $val
l!l&&r!l&&!r
000
not $tok or $tok->type ne $type
l!l&&r!l&&!r
000
MC/DC100%3/3
not $tok or $tok->type ne $type or $tok->value ne $val
not $tok $tok->type ne $type $tok->value ne $val
MC/DC0%0/3
not $tok or $tok->type ne $type or $tok->value ne $val
not $tok $tok->type ne $type $tok->value ne $val
Truth table100%4/4
not(A) or B or C
A= not $tokB= $tok->type ne $typeC= $tok->value ne $val
ABCresult
1XX1
01X1
0011
0000
Truth table0%0/4
not(A) or B or C
A= not $tokB= $tok->type ne $typeC= $tok->value ne $val
ABCresult
1XX1
01X1
0011
0000
140 0 $self->push_token($tok);
141 0 return 0;
142 }
143 0 return 1;
144 }
145  
146 277284 ▶sub skip_symbol {
Subroutine skip_symbol: called CC=1 SCAR=1.2
Pod undocumented
147 0 ▶ my ( $self, $val ) = @_;
Subroutine skip_symbol: not called CC=1 SCAR=1.2
Pod undocumented
148 0 return $self->skip_value( $self->lexer->TOKEN_SYMBOL, $val );
149 }
150  
151 19537 ▶sub advance_after_block_end {
Subroutine advance_after_block_end: called CC=7 SCAR=27.8
Pod undocumented
152 0 ▶ my ( $self, $name ) = @_;
Subroutine advance_after_block_end: not called CC=7 SCAR=27.8
Pod undocumented
153 0 my $tok;
154 0 ▶ if ( !defined $name ) {
Branch: 2 branches
BranchTrueFalseTotal
unless (defined $name) 5218 14319 19537
unless (defined $name) 0 0 0
155 0 $tok = $self->peek_token;
156  
157 0 ▶ if ( !$tok ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($tok) 0 5218 5218
unless ($tok) 0 0 0
158 0 $self->fail('unexpected end of file');
159 }
160  
161 0 ▶ if ( $tok->type ne $self->lexer->TOKEN_SYMBOL ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tok->type ne $self->lexer->TOKEN_SYMBOL) 0 5218 5218
if ($tok->type ne $self->lexer->TOKEN_SYMBOL) 0 0 0
162 0 $self->fail( 'advanceAfterBlockEnd: expected symbol token or '
163 . 'explicit name to be passed' );
164 }
165  
166 0 $name = $self->next_token->value;
167 }
168  
169 0 $tok = $self->next_token;
170  
171 0 ▶ if ( $tok && $tok->type eq $self->lexer->TOKEN_BLOCK_END ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tok and $tok->type eq $self->lexer->TOKEN_BLOCK_END) { } 19531 6 19537
if ($tok and $tok->type eq $self->lexer->TOKEN_BLOCK_END) { } 0 0 0
Condition50%3/6
$tok and $tok->type eq $self->lexer->TOKEN_BLOCK_END
!ll&&!rl&&r
2419531
$tok and $tok->type eq $self->lexer->TOKEN_BLOCK_END
!ll&&!rl&&r
000
MC/DC100%2/2
$tok and $tok->type eq $self->lexer->TOKEN_BLOCK_END
$tok $tok->type eq $self->lexer->TOKEN_BLOCK_END
MC/DC0%0/2
$tok and $tok->type eq $self->lexer->TOKEN_BLOCK_END
$tok $tok->type eq $self->lexer->TOKEN_BLOCK_END
Truth table100%3/3
A and B
A= $tokB= $tok->type eq $self->lexer->TOKEN_BLOCK_END
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $tokB= $tok->type eq $self->lexer->TOKEN_BLOCK_END
ABresult
0X0
100
111
172 0 ▶ if ( $self->_char_at( $tok->value, 0 ) eq '-' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_char_at($tok->value, 0) eq "-") 27 19504 19531
if ($self->_char_at($tok->value, 0) eq "-") 0 0 0
173 0 $self->dropLeadingWhitespace(1);
174 }
175 }
176 else {
177 0 $self->fail( 'expected block end in ' . $name . ' statement' );
178 }
179  
180 0 return $tok;
181 }
182  
183 12403 ▶sub advance_after_variable_end {
Subroutine advance_after_variable_end: called CC=4 SCAR=17.9
Pod undocumented
184 0 ▶ my ($self) = @_;
Subroutine advance_after_variable_end: not called CC=4 SCAR=17.9
Pod undocumented
185 0 my $tok = $self->next_token;
186  
187 0 ▶ if ( $tok && $tok->type eq $self->lexer->TOKEN_VARIABLE_END ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tok and $tok->type eq $self->lexer->TOKEN_VARIABLE_END) { } 12399 4 12403
if ($tok and $tok->type eq $self->lexer->TOKEN_VARIABLE_END) { } 0 0 0
Condition50%3/6
$tok and $tok->type eq $self->lexer->TOKEN_VARIABLE_END
!ll&&!rl&&r
3112399
$tok and $tok->type eq $self->lexer->TOKEN_VARIABLE_END
!ll&&!rl&&r
000
MC/DC100%2/2
$tok and $tok->type eq $self->lexer->TOKEN_VARIABLE_END
$tok $tok->type eq $self->lexer->TOKEN_VARIABLE_END
MC/DC0%0/2
$tok and $tok->type eq $self->lexer->TOKEN_VARIABLE_END
$tok $tok->type eq $self->lexer->TOKEN_VARIABLE_END
Truth table100%3/3
A and B
A= $tokB= $tok->type eq $self->lexer->TOKEN_VARIABLE_END
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $tokB= $tok->type eq $self->lexer->TOKEN_VARIABLE_END
ABresult
0X0
100
111
188 $self->dropLeadingWhitespace(
189 $self->_char_at(
190 $tok->value,
191 0 ▶ length( $tok->value ) - length( $self->tokens->tags->{VARIABLE_END} ) - 1
Branch: 2 branches
BranchTrueFalseTotal
$self->_char_at($tok->value, length($tok->value) - length($self->tokens->tags->{'VARIABLE_END'}) - 1) eq '-' ? : 3 12396 12399
$self->_char_at($tok->value, length($tok->value) - length($self->tokens->tags->{'VARIABLE_END'}) - 1) eq '-' ? : 0 0 0
192 ) eq '-' ? 1 : 0
193 );
194 }
195 else {
196 0 $self->push_token($tok);
197 0 $self->fail('expected variable end');
198 }
199 }
200  
201 1566 ▶sub parse_for {
Subroutine parse_for: called CC=9 SCAR=31.5
Pod undocumented
202 0 ▶ my ($self) = @_;
Subroutine parse_for: not called CC=9 SCAR=31.5
Pod undocumented
203 0 my $for_tok = $self->peek_token;
204 0 my $node;
205 my $end_block;
206  
207 0 ▶ if ( $self->skip_symbol('for') ) {
Branch: 6 branches
BranchTrueFalseTotal
if ($self->skip_symbol('for')) { } 810 756 1566
elsif ($self->skip_symbol('asyncEach')) { } 700 56 756
elsif ($self->skip_symbol('asyncAll')) { } 56 0 56
if ($self->skip_symbol('for')) { } 0 0 0
elsif ($self->skip_symbol('asyncEach')) { } 0 0 0
elsif ($self->skip_symbol('asyncAll')) { } 0 0 0
208 0 $node = $self->node('For')->new( $for_tok->lineno, $for_tok->colno );
209 0 $end_block = 'endfor';
210 }
211 elsif ( $self->skip_symbol('asyncEach') ) {
212 0 $node = $self->node('AsyncEach')->new( $for_tok->lineno, $for_tok->colno );
213 0 $end_block = 'endeach';
214 }
215 elsif ( $self->skip_symbol('asyncAll') ) {
216 0 $node = $self->node('AsyncAll')->new( $for_tok->lineno, $for_tok->colno );
217 0 $end_block = 'endall';
218 }
219 else {
220 0 $self->fail( 'parseFor: expected for{Async}', $for_tok->lineno, $for_tok->colno );
221 }
222  
223 0 $node->name( $self->parse_primary );
224  
225 0 ▶ if ( !$node->name->isa( $self->node('Symbol') ) ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($node->name->isa($self->node("Symbol"))) 0 1566 1566
unless ($node->name->isa($self->node("Symbol"))) 0 0 0
226 0 $self->fail('parseFor: variable name expected for loop');
227 }
228  
229 0 my $type = $self->peek_token->type;
230 0 ▶ if ( $type eq $self->lexer->TOKEN_COMMA ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq $self->lexer->TOKEN_COMMA) 466 1100 1566
if ($type eq $self->lexer->TOKEN_COMMA) 0 0 0
231 # key/value iteration
232 0 my $key = $node->name;
233 0 $node->name( $self->node('Array')->new( $key->lineno, $key->colno ) );
234 0 $node->name->add_child($key);
235  
236 0 ▶ while ( $self->skip( $self->lexer->TOKEN_COMMA ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->skip($self->lexer->TOKEN_COMMA)) 488 466 954
if ($self->skip($self->lexer->TOKEN_COMMA)) 0 0 0
237 0 my $prim = $self->parse_primary;
238 0 $node->name->add_child($prim);
239 }
240 }
241  
242 0 ▶ if ( !$self->skip_symbol('in') ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($self->skip_symbol("in")) 0 1566 1566
unless ($self->skip_symbol("in")) 0 0 0
243 0 $self->fail( 'parseFor: expected "in" keyword for loop',
244 $for_tok->lineno, $for_tok->colno );
245 }
246  
247 0 $node->arr( $self->parse_expression );
248 0 $self->advance_after_block_end( $for_tok->value );
249  
250 0 $node->body( $self->parse_until_blocks( $end_block, 'else' ) );
251  
252 0 ▶ if ( $self->skip_symbol('else') ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->skip_symbol("else")) 19 1547 1566
if ($self->skip_symbol("else")) 0 0 0
253 0 $self->advance_after_block_end('else');
254 0 $node->else_( $self->parse_until_blocks($end_block) );
255 }
256  
257 0 $self->advance_after_block_end;
258  
259 0 return $node;
260 }
261  
262 1346 ▶sub parse_macro {
Subroutine parse_macro: called CC=2 SCAR=10.2
Pod undocumented
263 0 ▶ my ($self) = @_;
Subroutine parse_macro: not called CC=2 SCAR=10.2
Pod undocumented
264 0 my $macro_tok = $self->peek_token;
265 0 ▶ if ( !$self->skip_symbol('macro') ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($self->skip_symbol("macro")) 0 1346 1346
unless ($self->skip_symbol("macro")) 0 0 0
266 0 $self->fail('expected macro');
267 }
268  
269 0 my $name = $self->parse_primary(1);
270 0 my $args = $self->parse_signature;
271 0 my $node = $self->node('Macro')->new( $macro_tok->lineno, $macro_tok->colno, $name, $args );
272  
273 0 $self->advance_after_block_end( $macro_tok->value );
274 0 $node->body( $self->parse_until_blocks('endmacro') );
275 0 $self->advance_after_block_end;
276  
277 0 return $node;
278 }
279  
280 82 ▶sub parse_call {
Subroutine parse_call: called CC=6 SCAR=25.3
Pod undocumented
281 0 ▶ my ($self) = @_;
Subroutine parse_call: not called CC=6 SCAR=25.3
Pod undocumented
282 # a call block is parsed as a normal FunCall, but with an added
283 # 'caller' kwarg which is a Caller node.
284 0 my $call_tok = $self->peek_token;
285 0 ▶ if ( !$self->skip_symbol('call') ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($self->skip_symbol("call")) 0 82 82
unless ($self->skip_symbol("call")) 0 0 0
286 0 $self->fail('expected call');
287 }
288  
289 0 ▶ my $caller_args = $self->parse_signature(1) || $self->node('NodeList')->new;
Condition33%2/6
$self->parse_signature(1) || $self->node('NodeList')->new
l!l&&r!l&&!r
8740
$self->parse_signature(1) || $self->node('NodeList')->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->parse_signature(1) || $self->node('NodeList')->new
$self->parse_signature(1) $self->node('NodeList')->new
MC/DC0%0/2
$self->parse_signature(1) || $self->node('NodeList')->new
$self->parse_signature(1) $self->node('NodeList')->new
Truth table66%2/3
A || B
A= $self->parse_signature(1)B= $self->node('NodeList')->new
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $self->parse_signature(1)B= $self->node('NodeList')->new
ABresult
1X1
011
000
290 0 my $macro_call = $self->parse_primary;
291  
292 0 $self->advance_after_block_end( $call_tok->value );
293 0 my $body = $self->parse_until_blocks('endcall');
294 0 $self->advance_after_block_end;
295  
296 0 my $caller_name = $self->node('Symbol')->new( $call_tok->lineno, $call_tok->colno, 'caller' );
297 0 my $caller_node = $self->node('Caller')->new(
298 $call_tok->lineno, $call_tok->colno,
299 $caller_name, $caller_args, $body
300 );
301  
302 # add the additional caller kwarg, adding kwargs if necessary
303 0 my $args = $macro_call->args->children;
304 0 ▶ if ( !( @$args && blessed( $args->[-1] ) && $args->[-1]->isa( $self->node('KeywordArgs') ) ) ) {
Branch: 2 branches
BranchTrueFalseTotal
unless (@$args and builtin::blessed($args->[-1]) and $args->[-1]->isa($self->node("KeywordArgs"))) 79 3 82
unless (@$args and builtin::blessed($args->[-1]) and $args->[-1]->isa($self->node("KeywordArgs"))) 0 0 0
Condition41%5/12
@$args and builtin::blessed($args->[-1]) and $args->[-1]->isa($self->node("KeywordArgs"))
!ll&&!rl&&r
49303
@$args and builtin::blessed($args->[-1])
!ll&&!rl&&r
49033
@$args and builtin::blessed($args->[-1]) and $args->[-1]->isa($self->node("KeywordArgs"))
!ll&&!rl&&r
000
@$args and builtin::blessed($args->[-1])
!ll&&!rl&&r
000
MC/DC66%2/3
@$args and builtin::blessed($args->[-1]) and $args->[-1]->isa($self->node("KeywordArgs"))
@$args builtin::blessed($args->[-1]) $args->[-1]->isa($self->node("KeywordArgs"))
MC/DC0%0/3
@$args and builtin::blessed($args->[-1]) and $args->[-1]->isa($self->node("KeywordArgs"))
@$args builtin::blessed($args->[-1]) $args->[-1]->isa($self->node("KeywordArgs"))
Truth table75%3/4
A and B and C
A= @$argsB= builtin::blessed($args->[-1])C= $args->[-1]->isa($self->node("KeywordArgs"))
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and B and C
A= @$argsB= builtin::blessed($args->[-1])C= $args->[-1]->isa($self->node("KeywordArgs"))
ABCresult
0XX0
10X0
1100
1111
305 0 push @$args, $self->node('KeywordArgs')->new;
306 }
307 0 my $kwargs = $args->[-1];
308 0 $kwargs->add_child(
309 $self->node('Pair')->new( $call_tok->lineno, $call_tok->colno, $caller_name, $caller_node )
310 );
311  
312 0 return $self->node('Output')->new( $call_tok->lineno, $call_tok->colno, [$macro_call] );
313 }
314  
315 1115 ▶sub parse_with_context {
Subroutine parse_with_context: called CC=5 SCAR=22.3
Pod undocumented
316 0 ▶ my ($self) = @_;
Subroutine parse_with_context: not called CC=5 SCAR=22.3
Pod undocumented
317 0 my $tok = $self->peek_token;
318  
319 0 my $with_context = undef;
320  
321 0 ▶ if ( $self->skip_symbol('with') ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($self->skip_symbol('with')) { } 245 870 1115
elsif ($self->skip_symbol('without')) { } 3 867 870
if ($self->skip_symbol('with')) { } 0 0 0
elsif ($self->skip_symbol('without')) { } 0 0 0
322 0 $with_context = true;
323 }
324 elsif ( $self->skip_symbol('without') ) {
325 0 $with_context = false;
326 }
327  
328 0 ▶ if ( defined $with_context ) { # JS: withContext !== null
Branch: 2 branches
BranchTrueFalseTotal
if (defined $with_context) 248 867 1115
if (defined $with_context) 0 0 0
329 0 ▶ if ( !$self->skip_symbol('context') ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($self->skip_symbol("context")) 0 248 248
unless ($self->skip_symbol("context")) 0 0 0
330 0 $self->fail( 'parseFrom: expected context after with/without',
331 $tok->lineno, $tok->colno );
332 }
333 }
334  
335 0 return $with_context;
336 }
337  
338 669 ▶sub parse_import {
Subroutine parse_import: called CC=3 SCAR=15.3
Pod undocumented
339 0 ▶ my ($self) = @_;
Subroutine parse_import: not called CC=3 SCAR=15.3
Pod undocumented
340 0 my $import_tok = $self->peek_token;
341 0 ▶ if ( !$self->skip_symbol('import') ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($self->skip_symbol("import")) 0 669 669
unless ($self->skip_symbol("import")) 0 0 0
342 0 $self->fail( 'parseImport: expected import', $import_tok->lineno, $import_tok->colno );
343 }
344  
345 0 my $template = $self->parse_expression;
346  
347 0 ▶ if ( !$self->skip_symbol('as') ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($self->skip_symbol("as")) 2 667 669
unless ($self->skip_symbol("as")) 0 0 0
348 0 $self->fail( 'parseImport: expected "as" keyword', $import_tok->lineno, $import_tok->colno );
349 }
350  
351 0 my $target = $self->parse_expression;
352 0 my $with_context = $self->parse_with_context;
353 0 my $node = $self->node('Import')->new(
354 $import_tok->lineno, $import_tok->colno,
355 $template, $target, $with_context
356 );
357  
358 0 $self->advance_after_block_end( $import_tok->value );
359  
360 0 return $node;
361 }
362  
363 445 ▶sub parse_from {
Subroutine parse_from: called CC=10 SCAR=32.5
Pod undocumented
364 0 ▶ my ($self) = @_;
Subroutine parse_from: not called CC=10 SCAR=32.5
Pod undocumented
365 0 my $from_tok = $self->peek_token;
366 0 ▶ if ( !$self->skip_symbol('from') ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($self->skip_symbol("from")) 0 445 445
unless ($self->skip_symbol("from")) 0 0 0
367 0 $self->fail('parseFrom: expected from');
368 }
369  
370 0 my $template = $self->parse_expression;
371  
372 0 ▶ if ( !$self->skip_symbol('import') ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($self->skip_symbol("import")) 2 443 445
unless ($self->skip_symbol("import")) 0 0 0
373 0 $self->fail( 'parseFrom: expected import', $from_tok->lineno, $from_tok->colno );
374 }
375  
376 0 my $names = $self->node('NodeList')->new;
377 0 my $with_context;
378  
379 0 while (1) {
380 0 my $next_tok = $self->peek_token;
381 0 ▶ if ( $next_tok->type eq $self->lexer->TOKEN_BLOCK_END ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($next_tok->type eq $self->lexer->TOKEN_BLOCK_END) 438 453 891
if ($next_tok->type eq $self->lexer->TOKEN_BLOCK_END) 0 0 0
382 0 ▶ if ( !@{ $names->children } ) {
Branch: 2 branches
BranchTrueFalseTotal
unless (@{$names->children;}) 0 438 438
unless (@{$names->children;}) 0 0 0
383 0 $self->fail( 'parseFrom: Expected at least one import name',
384 $from_tok->lineno, $from_tok->colno );
385 }
386  
387 # Since we are manually advancing past the block end,
388 # need to keep track of whitespace control (normally
389 # this is done in `advanceAfterBlockEnd`
390 0 ▶ if ( $self->_char_at( $next_tok->value, 0 ) eq '-' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_char_at($next_tok->value, 0) eq "-") 2 436 438
if ($self->_char_at($next_tok->value, 0) eq "-") 0 0 0
391 0 $self->dropLeadingWhitespace(1);
392 }
393  
394 0 $self->next_token;
395 0 last;
396 }
397  
398 0 ▶ if ( @{ $names->children } > 0 && !$self->skip( $self->lexer->TOKEN_COMMA ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@{$names->children;} > 0 and not $self->skip($self->lexer->TOKEN_COMMA)) 2 451 453
if (@{$names->children;} > 0 and not $self->skip($self->lexer->TOKEN_COMMA)) 0 0 0
Condition50%3/6
@{$names->children;} > 0 and not $self->skip($self->lexer->TOKEN_COMMA)
!ll&&!rl&&r
44382
@{$names->children;} > 0 and not $self->skip($self->lexer->TOKEN_COMMA)
!ll&&!rl&&r
000
MC/DC100%2/2
@{$names->children;} > 0 and not $self->skip($self->lexer->TOKEN_COMMA)
@{$names->children;} > 0 not $self->skip($self->lexer->TOKEN_COMMA)
MC/DC0%0/2
@{$names->children;} > 0 and not $self->skip($self->lexer->TOKEN_COMMA)
@{$names->children;} > 0 not $self->skip($self->lexer->TOKEN_COMMA)
Truth table100%3/3
A and not(B)
A= @{$names->children;} > 0B= not $self->skip($self->lexer->TOKEN_COMMA)
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= @{$names->children;} > 0B= not $self->skip($self->lexer->TOKEN_COMMA)
ABresult
0X0
100
111
399 0 $self->fail( 'parseFrom: expected comma', $from_tok->lineno, $from_tok->colno );
400 }
401  
402 0 my $name = $self->parse_primary;
403 0 ▶ if ( $self->_char_at( $name->value, 0 ) eq '_' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_char_at($name->value, 0) eq "_") 3 448 451
if ($self->_char_at($name->value, 0) eq "_") 0 0 0
404 0 $self->fail( 'parseFrom: names starting with an underscore cannot be imported',
405 $name->lineno, $name->colno );
406 }
407  
408 0 ▶ if ( $self->skip_symbol('as') ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->skip_symbol('as')) { } 8 440 448
if ($self->skip_symbol('as')) { } 0 0 0
409 0 my $alias = $self->parse_primary;
410 0 $names->add_child(
411 $self->node('Pair')->new( $name->lineno, $name->colno, $name, $alias )
412 );
413 }
414 else {
415 0 $names->add_child($name);
416 }
417  
418 0 $with_context = $self->parse_with_context;
419 }
420  
421 0 return $self->node('FromImport')->new(
422 $from_tok->lineno, $from_tok->colno,
423 $template, $names, $with_context
424 );
425 }
426  
427 1196 ▶sub parse_block {
Subroutine parse_block: called CC=4 SCAR=19.8
Pod undocumented
428 0 ▶ my ($self) = @_;
Subroutine parse_block: not called CC=4 SCAR=19.8
Pod undocumented
429 0 my $tag = $self->peek_token;
430 0 ▶ if ( !$self->skip_symbol('block') ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($self->skip_symbol("block")) 0 1196 1196
unless ($self->skip_symbol("block")) 0 0 0
431 0 $self->fail( 'parseBlock: expected block', $tag->lineno, $tag->colno );
432 }
433  
434 0 my $node = $self->node('Block')->new( $tag->lineno, $tag->colno );
435  
436 0 $node->name( $self->parse_primary );
437 0 ▶ if ( !$node->name->isa( $self->node('Symbol') ) ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($node->name->isa($self->node("Symbol"))) 0 1196 1196
unless ($node->name->isa($self->node("Symbol"))) 0 0 0
438 0 $self->fail( 'parseBlock: variable name expected', $tag->lineno, $tag->colno );
439 }
440  
441 0 $self->advance_after_block_end( $tag->value );
442  
443 0 $node->body( $self->parse_until_blocks('endblock') );
444 0 $self->skip_symbol('endblock');
445 0 $self->skip_symbol( $node->name->value );
446  
447 0 my $tok = $self->peek_token;
448 0 ▶ if ( !$tok ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($tok) 2 1194 1196
unless ($tok) 0 0 0
449 0 $self->fail('parseBlock: expected endblock, got end of file');
450 }
451  
452 0 $self->advance_after_block_end( $tok->value );
453  
454 0 return $node;
455 }
456  
457 578 ▶sub parse_extends {
Subroutine parse_extends: called CC=2 SCAR=10.4
Pod undocumented
458 0 ▶ my ($self) = @_;
Subroutine parse_extends: not called CC=2 SCAR=10.4
Pod undocumented
459 0 my $tag_name = 'extends';
460 0 my $tag = $self->peek_token;
461 0 ▶ if ( !$self->skip_symbol($tag_name) ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($self->skip_symbol($tag_name)) 0 578 578
unless ($self->skip_symbol($tag_name)) 0 0 0
462 0 $self->fail( 'parseTemplateRef: expected ' . $tag_name );
463 }
464  
465 0 my $node = $self->node('Extends')->new( $tag->lineno, $tag->colno );
466 0 $node->template( $self->parse_expression );
467  
468 0 $self->advance_after_block_end( $tag->value );
469 0 return $node;
470 }
471  
472 2667 ▶sub parse_include {
Subroutine parse_include: called CC=4 SCAR=19.7
Pod undocumented
473 0 ▶ my ($self) = @_;
Subroutine parse_include: not called CC=4 SCAR=19.7
Pod undocumented
474 0 my $tag_name = 'include';
475 0 my $tag = $self->peek_token;
476 0 ▶ if ( !$self->skip_symbol($tag_name) ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($self->skip_symbol($tag_name)) 0 2667 2667
unless ($self->skip_symbol($tag_name)) 0 0 0
477 0 $self->fail( 'parseInclude: expected ' . $tag_name );
478 }
479  
480 0 my $node = $self->node('Include')->new( $tag->lineno, $tag->colno );
481 0 $node->template( $self->parse_expression );
482  
483 0 ▶ if ( $self->skip_symbol('ignore') && $self->skip_symbol('missing') ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->skip_symbol("ignore") and $self->skip_symbol("missing")) 12 2655 2667
if ($self->skip_symbol("ignore") and $self->skip_symbol("missing")) 0 0 0
Condition33%2/6
$self->skip_symbol("ignore") and $self->skip_symbol("missing")
!ll&&!rl&&r
2655012
$self->skip_symbol("ignore") and $self->skip_symbol("missing")
!ll&&!rl&&r
000
MC/DC50%1/2
$self->skip_symbol("ignore") and $self->skip_symbol("missing")
$self->skip_symbol("ignore") $self->skip_symbol("missing")
MC/DC0%0/2
$self->skip_symbol("ignore") and $self->skip_symbol("missing")
$self->skip_symbol("ignore") $self->skip_symbol("missing")
Truth table66%2/3
A and B
A= $self->skip_symbol("ignore")B= $self->skip_symbol("missing")
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $self->skip_symbol("ignore")B= $self->skip_symbol("missing")
ABresult
0X0
100
111
484 0 $node->ignoreMissing(true);
485 }
486  
487 0 $self->advance_after_block_end( $tag->value );
488 0 return $node;
489 }
490  
491 2075 ▶sub parse_if {
Subroutine parse_if: called CC=13 SCAR=36.7
Pod undocumented
492 0 ▶ my ($self) = @_;
Subroutine parse_if: not called CC=13 SCAR=36.7
Pod undocumented
493 0 my $tag = $self->peek_token;
494 0 my $node;
495  
496 0 ▶ if ( $self->skip_symbol('if') || $self->skip_symbol('elif') || $self->skip_symbol('elseif') ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($self->skip_symbol('if') or $self->skip_symbol('elif') or $self->skip_symbol('elseif')) { } 2073 2 2075
elsif ($self->skip_symbol('ifAsync')) { } 2 0 2
if ($self->skip_symbol('if') or $self->skip_symbol('elif') or $self->skip_symbol('elseif')) { } 0 0 0
elsif ($self->skip_symbol('ifAsync')) { } 0 0 0
Condition50%6/12
$self->skip_symbol("if") or $self->skip_symbol("elif") or $self->skip_symbol("elseif")
l!l&&r!l&&!r
206942
$self->skip_symbol("if") or $self->skip_symbol("elif")
l!l&&r!l&&!r
206726
$self->skip_symbol("if") or $self->skip_symbol("elif") or $self->skip_symbol("elseif")
l!l&&r!l&&!r
000
$self->skip_symbol("if") or $self->skip_symbol("elif")
l!l&&r!l&&!r
000
MC/DC100%3/3
$self->skip_symbol("if") or $self->skip_symbol("elif") or $self->skip_symbol("elseif")
$self->skip_symbol("if") $self->skip_symbol("elif") $self->skip_symbol("elseif")
MC/DC0%0/3
$self->skip_symbol("if") or $self->skip_symbol("elif") or $self->skip_symbol("elseif")
$self->skip_symbol("if") $self->skip_symbol("elif") $self->skip_symbol("elseif")
Truth table100%4/4
A or B or C
A= $self->skip_symbol("if")B= $self->skip_symbol("elif")C= $self->skip_symbol("elseif")
ABCresult
1XX1
01X1
0011
0000
Truth table0%0/4
A or B or C
A= $self->skip_symbol("if")B= $self->skip_symbol("elif")C= $self->skip_symbol("elseif")
ABCresult
1XX1
01X1
0011
0000
497 0 $node = $self->node('If')->new( $tag->lineno, $tag->colno );
498 }
499 elsif ( $self->skip_symbol('ifAsync') ) {
500 0 $node = $self->node('IfAsync')->new( $tag->lineno, $tag->colno );
501 }
502 else {
503 0 $self->fail( 'parseIf: expected if, elif, or elseif', $tag->lineno, $tag->colno );
504 }
505  
506 0 $node->cond( $self->parse_expression );
507 0 $self->advance_after_block_end( $tag->value );
508  
509 0 $node->body( $self->parse_until_blocks( 'elif', 'elseif', 'else', 'endif' ) );
510 0 my $tok = $self->peek_token;
511  
512 0 ▶ my $val = $tok && $tok->value;
Condition33%2/6
$tok && $tok->value
!ll&&!rl&&r
202067
$tok && $tok->value
!ll&&!rl&&r
000
MC/DC50%1/2
$tok && $tok->value
$tok $tok->value
MC/DC0%0/2
$tok && $tok->value
$tok $tok->value
Truth table66%2/3
A && B
A= $tokB= $tok->value
ABresult
0X0
100
111
Truth table0%0/3
A && B
A= $tokB= $tok->value
ABresult
0X0
100
111
513 0 ▶ if ( defined $val && ( $val eq 'elseif' || $val eq 'elif' ) ) {
Branch: 6 branches
BranchTrueFalseTotal
if (defined $val and $val eq 'elseif' || $val eq 'elif') { } 6 2063 2069
elsif (defined $val and $val eq 'else') { } 40 2023 2063
elsif (defined $val and $val eq 'endif') { } 2021 2 2023
if (defined $val and $val eq 'elseif' || $val eq 'elif') { } 0 0 0
elsif (defined $val and $val eq 'else') { } 0 0 0
elsif (defined $val and $val eq 'endif') { } 0 0 0
Condition50%6/12
defined $val and $val eq "elseif" || $val eq "elif"
!ll&&!rl&&r
220616
$val eq "elseif" or $val eq "elif"
l!l&&r!l&&!r
422061
defined $val and $val eq "elseif" || $val eq "elif"
!ll&&!rl&&r
000
$val eq "elseif" or $val eq "elif"
l!l&&r!l&&!r
000
MC/DC100%3/3
defined $val and $val eq "elseif" || $val eq "elif"
defined $val $val eq "elseif" $val eq "elif"
MC/DC0%0/3
defined $val and $val eq "elseif" || $val eq "elif"
defined $val $val eq "elseif" $val eq "elif"
Truth table100%4/4
A and B or C
A= defined $valB= $val eq "elseif"C= $val eq "elif"
ABCresult
0XX0
1000
11X1
1011
Truth table0%0/4
A and B or C
A= defined $valB= $val eq "elseif"C= $val eq "elif"
ABCresult
0XX0
1000
11X1
1011
514 0 $node->else_( $self->parse_if );
515 }
516 ▶ elsif ( defined $val && $val eq 'else' ) {
Condition50%3/6
defined $val and $val eq "else"
!ll&&!rl&&r
2202140
defined $val and $val eq "else"
!ll&&!rl&&r
000
MC/DC100%2/2
defined $val and $val eq "else"
defined $val $val eq "else"
MC/DC0%0/2
defined $val and $val eq "else"
defined $val $val eq "else"
Truth table100%3/3
A and B
A= defined $valB= $val eq "else"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $valB= $val eq "else"
ABresult
0X0
100
111
517 0 $self->advance_after_block_end;
518 0 $node->else_( $self->parse_until_blocks('endif') );
519 0 $self->advance_after_block_end;
520 }
521 ▶ elsif ( defined $val && $val eq 'endif' ) {
Condition33%2/6
defined $val and $val eq "endif"
!ll&&!rl&&r
202021
defined $val and $val eq "endif"
!ll&&!rl&&r
000
MC/DC50%1/2
defined $val and $val eq "endif"
defined $val $val eq "endif"
MC/DC0%0/2
defined $val and $val eq "endif"
defined $val $val eq "endif"
Truth table66%2/3
A and B
A= defined $valB= $val eq "endif"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $valB= $val eq "endif"
ABresult
0X0
100
111
522 0 $node->else_(undef);
523 0 $self->advance_after_block_end;
524 }
525 else {
526 0 $self->fail('parseIf: expected elif, else, or endif, got end of file');
527 }
528  
529 0 return $node;
530 }
531  
532 2885 ▶sub parse_set {
Subroutine parse_set: called CC=6 SCAR=25.8
Pod undocumented
533 0 ▶ my ($self) = @_;
Subroutine parse_set: not called CC=6 SCAR=25.8
Pod undocumented
534 0 my $tag = $self->peek_token;
535 0 ▶ if ( !$self->skip_symbol('set') ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($self->skip_symbol("set")) 0 2885 2885
unless ($self->skip_symbol("set")) 0 0 0
536 0 $self->fail( 'parseSet: expected set', $tag->lineno, $tag->colno );
537 }
538  
539 0 my $node = $self->node('Set')->new( $tag->lineno, $tag->colno, [] );
540  
541 0 my $target;
542 0 ▶ while ( $target = $self->parse_primary ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($target = $self->parse_primary) 2891 0 2891
if ($target = $self->parse_primary) 0 0 0
543 0 push @{ $node->targets }, $target;
544  
545 0 ▶ if ( !$self->skip( $self->lexer->TOKEN_COMMA ) ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($self->skip($self->lexer->TOKEN_COMMA)) 2884 7 2891
unless ($self->skip($self->lexer->TOKEN_COMMA)) 0 0 0
546 0 last;
547 }
548 }
549  
550 0 ▶ if ( !$self->skip_value( $self->lexer->TOKEN_OPERATOR, '=' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $self->skip_value($self->lexer->TOKEN_OPERATOR, '=')) { } 26 2858 2884
if (not $self->skip_value($self->lexer->TOKEN_OPERATOR, '=')) { } 0 0 0
551 0 ▶ if ( !$self->skip( $self->lexer->TOKEN_BLOCK_END ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $self->skip($self->lexer->TOKEN_BLOCK_END)) { } 0 26 26
if (not $self->skip($self->lexer->TOKEN_BLOCK_END)) { } 0 0 0
552 0 $self->fail( 'parseSet: expected = or block end in set tag',
553 $tag->lineno, $tag->colno );
554 }
555 else {
556 0 $node->body(
557 $self->node('Capture')->new(
558 $tag->lineno, $tag->colno,
559 $self->parse_until_blocks('endset')
560 )
561 );
562 0 $node->value(undef);
563 0 $self->advance_after_block_end;
564 }
565 }
566 else {
567 0 $node->value( $self->parse_expression );
568 0 $self->advance_after_block_end( $tag->value );
569 }
570  
571 0 return $node;
572 }
573  
574 16 ▶sub parse_switch {
Subroutine parse_switch: called CC=8 SCAR=30.9
Pod undocumented
575 0 ▶ my ($self) = @_;
Subroutine parse_switch: not called CC=8 SCAR=30.9
Pod undocumented
576 #
577 # Store the tag names in variables in case someone ever wants to
578 # customize this.
579 #
580 0 my $switch_start = 'switch';
581 0 my $switch_end = 'endswitch';
582 0 my $case_start = 'case';
583 0 my $case_default = 'default';
584  
585 # Get the switch tag.
586 0 my $tag = $self->peek_token;
587  
588 # fail early if we get some unexpected tag.
589 0 ▶ if ( !$self->skip_symbol($switch_start)
Branch: 2 branches
BranchTrueFalseTotal
unless ($self->skip_symbol($switch_start) or $self->skip_symbol($case_start) or $self->skip_symbol($case_default)) 0 16 16
unless ($self->skip_symbol($switch_start) or $self->skip_symbol($case_start) or $self->skip_symbol($case_default)) 0 0 0
Condition16%2/12
$self->skip_symbol($switch_start) or $self->skip_symbol($case_start) or $self->skip_symbol($case_default)
l!l&&r!l&&!r
1600
$self->skip_symbol($switch_start) or $self->skip_symbol($case_start)
l!l&&r!l&&!r
1600
$self->skip_symbol($switch_start) or $self->skip_symbol($case_start) or $self->skip_symbol($case_default)
l!l&&r!l&&!r
000
$self->skip_symbol($switch_start) or $self->skip_symbol($case_start)
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->skip_symbol($switch_start) or $self->skip_symbol($case_start) or $self->skip_symbol($case_default)
$self->skip_symbol($switch_start) $self->skip_symbol($case_start) $self->skip_symbol($case_default)
MC/DC0%0/3
$self->skip_symbol($switch_start) or $self->skip_symbol($case_start) or $self->skip_symbol($case_default)
$self->skip_symbol($switch_start) $self->skip_symbol($case_start) $self->skip_symbol($case_default)
Truth table25%1/4
A or B or C
A= $self->skip_symbol($switch_start)B= $self->skip_symbol($case_start)C= $self->skip_symbol($case_default)
ABCresult
1XX1
01X1
0011
0000
Truth table0%0/4
A or B or C
A= $self->skip_symbol($switch_start)B= $self->skip_symbol($case_start)C= $self->skip_symbol($case_default)
ABCresult
1XX1
01X1
0011
0000
590 && !$self->skip_symbol($case_start)
591 && !$self->skip_symbol($case_default) )
592 {
593 0 $self->fail( 'parseSwitch: expected "switch," "case" or "default"',
594 $tag->lineno, $tag->colno );
595 }
596  
597 # parse the switch expression
598 0 my $expr = $self->parse_expression;
599  
600 # advance until a start of a case, a default case or an endswitch.
601 0 $self->advance_after_block_end($switch_start);
602 0 $self->parse_until_blocks( $case_start, $case_default, $switch_end );
603  
604 # this is the first case. it could also be an endswitch, we'll check.
605 0 my $tok = $self->peek_token;
606  
607 # create new variables for our cases and default case.
608 0 my @cases;
609 my $default_case;
610  
611 # while we're dealing with new cases nodes...
612 0 ▶ do {
Branch: 2 branches
BranchTrueFalseTotal
$tok and $tok->value eq $case_start and do { do { $self->skip_symbol($case_start); my $cond = $self->parse_expression; $self->advance_after_block_end($switch_start); my $body = $self->parse_until_blocks($case_start, $case_default, $switch_end); push @cases, $self->node("Case")->new($tok->{"line"}, $tok->{"col"}, $cond, $body); $tok = $self->peek_token } } 13 16 29
$tok and $tok->value eq $case_start and do { do { $self->skip_symbol($case_start); my $cond = $self->parse_expression; $self->advance_after_block_end($switch_start); my $body = $self->parse_until_blocks($case_start, $case_default, $switch_end); push @cases, $self->node("Case")->new($tok->{"line"}, $tok->{"col"}, $cond, $body); $tok = $self->peek_token } } 0 0 0
Condition33%2/6
$tok and $tok->value eq $case_start
!ll&&!rl&&r
01613
$tok and $tok->value eq $case_start
!ll&&!rl&&r
000
MC/DC50%1/2
$tok and $tok->value eq $case_start
$tok $tok->value eq $case_start
MC/DC0%0/2
$tok and $tok->value eq $case_start
$tok $tok->value eq $case_start
Truth table66%2/3
A and B
A= $tokB= $tok->value eq $case_start
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $tokB= $tok->value eq $case_start
ABresult
0X0
100
111
613 # skip the start symbol and get the case expression
614 0 $self->skip_symbol($case_start);
615 0 my $cond = $self->parse_expression;
616 0 $self->advance_after_block_end($switch_start);
617 # get the body of the case node and add it to the array of cases.
618 0 my $body = $self->parse_until_blocks( $case_start, $case_default, $switch_end );
619 # NOTE: upstream typo -- Case gets tok.line / tok.col, but Token only has
620 # lineno / colno, so both are undefined and JSON.stringify (the oracle)
621 # omits them on the Case node. Preserved 1:1 by reading the same
622 # nonexistent hash slots ($tok->{line}/{col} -> undef), the way Lexer.pm
623 # preserves its this.src typo.
624 0 push @cases, $self->node('Case')->new( $tok->{line}, $tok->{col}, $cond, $body );
625 # get our next case
626 0 $tok = $self->peek_token;
627 } while ( $tok && $tok->value eq $case_start );
628  
629 # we either have a default case or a switch end.
630 0 ▶ if ( $tok->value eq $case_default ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($tok->value eq $case_default) { } 10 6 16
elsif ($tok->value eq $switch_end) { } 6 0 6
if ($tok->value eq $case_default) { } 0 0 0
elsif ($tok->value eq $switch_end) { } 0 0 0
631 0 $self->advance_after_block_end;
632 0 $default_case = $self->parse_until_blocks($switch_end);
633 0 $self->advance_after_block_end;
634 }
635 elsif ( $tok->value eq $switch_end ) {
636 0 $self->advance_after_block_end;
637 }
638 else {
639 # otherwise bail because EOF
640 0 $self->fail('parseSwitch: expected "case," "default" or "endswitch," got EOF.');
641 }
642  
643 # and return the switch node.
644 0 return $self->node('Switch')->new( $tag->lineno, $tag->colno, $expr, \@cases, $default_case );
645 }
646  
647 20022 ▶sub parse_statement {
Subroutine parse_statement: called CC=28 SCAR=50.7
Pod undocumented
648 0 ▶ my ($self) = @_;
Subroutine parse_statement: not called CC=28 SCAR=50.7
Pod undocumented
649 0 my $tok = $self->peek_token;
650 0 my $node;
651  
652 0 ▶ if ( $tok->type ne $self->lexer->TOKEN_SYMBOL ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tok->type ne $self->lexer->TOKEN_SYMBOL) 0 20022 20022
if ($tok->type ne $self->lexer->TOKEN_SYMBOL) 0 0 0
653 0 $self->fail( 'tag name expected', $tok->lineno, $tok->colno );
654 }
655  
656 0 ▶ if ( $self->breakOnBlocks
Branch: 2 branches
BranchTrueFalseTotal
if ($self->breakOnBlocks and $self->lib->index_of($self->breakOnBlocks, $tok->value) != -1) 6426 13596 20022
if ($self->breakOnBlocks and $self->lib->index_of($self->breakOnBlocks, $tok->value) != -1) 0 0 0
Condition50%3/6
$self->breakOnBlocks and $self->lib->index_of($self->breakOnBlocks, $tok->value) != -1
!ll&&!rl&&r
874248546426
$self->breakOnBlocks and $self->lib->index_of($self->breakOnBlocks, $tok->value) != -1
!ll&&!rl&&r
000
MC/DC100%2/2
$self->breakOnBlocks and $self->lib->index_of($self->breakOnBlocks, $tok->value) != -1
$self->breakOnBlocks $self->lib->index_of($self->breakOnBlocks, $tok->value) != -1
MC/DC0%0/2
$self->breakOnBlocks and $self->lib->index_of($self->breakOnBlocks, $tok->value) != -1
$self->breakOnBlocks $self->lib->index_of($self->breakOnBlocks, $tok->value) != -1
Truth table100%3/3
A and B
A= $self->breakOnBlocksB= $self->lib->index_of($self->breakOnBlocks, $tok->value) != -1
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $self->breakOnBlocksB= $self->lib->index_of($self->breakOnBlocks, $tok->value) != -1
ABresult
0X0
100
111
657 && $self->lib->index_of( $self->breakOnBlocks, $tok->value ) != -1 )
658 {
659 0 return undef;
660 }
661  
662 0 my $val = $tok->value;
663 0 ▶ if ( $val eq 'raw' ) { return $self->parse_raw; }
Branch: 28 branches
BranchTrueFalseTotal
if ($val eq 'raw') { } 22 13574 13596
elsif ($val eq 'verbatim') { } 13 13561 13574
elsif ($val eq 'if' or $val eq 'ifAsync') { } 2069 11492 13561
elsif ($val eq 'for' or $val eq 'asyncEach' or $val eq 'asyncAll') { } 1566 9926 11492
elsif ($val eq 'block') { } 1196 8730 9926
elsif ($val eq 'extends') { } 578 8152 8730
elsif ($val eq 'include') { } 2667 5485 8152
elsif ($val eq 'set') { } 2885 2600 5485
elsif ($val eq 'macro') { } 1346 1254 2600
elsif ($val eq 'call') { } 82 1172 1254
elsif ($val eq 'import') { } 669 503 1172
elsif ($val eq 'from') { } 445 58 503
elsif ($val eq 'filter') { } 18 40 58
elsif ($val eq 'switch') { } 16 24 40
if ($val eq 'raw') { } 0 0 0
elsif ($val eq 'verbatim') { } 0 0 0
elsif ($val eq 'if' or $val eq 'ifAsync') { } 0 0 0
elsif ($val eq 'for' or $val eq 'asyncEach' or $val eq 'asyncAll') { } 0 0 0
elsif ($val eq 'block') { } 0 0 0
elsif ($val eq 'extends') { } 0 0 0
elsif ($val eq 'include') { } 0 0 0
elsif ($val eq 'set') { } 0 0 0
elsif ($val eq 'macro') { } 0 0 0
elsif ($val eq 'call') { } 0 0 0
elsif ($val eq 'import') { } 0 0 0
elsif ($val eq 'from') { } 0 0 0
elsif ($val eq 'filter') { } 0 0 0
elsif ($val eq 'switch') { } 0 0 0
664 0 elsif ( $val eq 'verbatim' ) { return $self->parse_raw('verbatim'); }
665 0 ▶ elsif ( $val eq 'if' || $val eq 'ifAsync' ) { return $self->parse_if; }
Condition50%3/6
$val eq "if" or $val eq "ifAsync"
l!l&&r!l&&!r
2067211492
$val eq "if" or $val eq "ifAsync"
l!l&&r!l&&!r
000
MC/DC100%2/2
$val eq "if" or $val eq "ifAsync"
$val eq "if" $val eq "ifAsync"
MC/DC0%0/2
$val eq "if" or $val eq "ifAsync"
$val eq "if" $val eq "ifAsync"
Truth table100%3/3
A or B
A= $val eq "if"B= $val eq "ifAsync"
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $val eq "if"B= $val eq "ifAsync"
ABresult
1X1
011
000
666 0 ▶ elsif ( $val eq 'for' || $val eq 'asyncEach' || $val eq 'asyncAll' ) { return $self->parse_for; }
Condition50%6/12
$val eq "for" or $val eq "asyncEach" or $val eq "asyncAll"
l!l&&r!l&&!r
1510569926
$val eq "for" or $val eq "asyncEach"
l!l&&r!l&&!r
8107009982
$val eq "for" or $val eq "asyncEach" or $val eq "asyncAll"
l!l&&r!l&&!r
000
$val eq "for" or $val eq "asyncEach"
l!l&&r!l&&!r
000
MC/DC100%3/3
$val eq "for" or $val eq "asyncEach" or $val eq "asyncAll"
$val eq "for" $val eq "asyncEach" $val eq "asyncAll"
MC/DC0%0/3
$val eq "for" or $val eq "asyncEach" or $val eq "asyncAll"
$val eq "for" $val eq "asyncEach" $val eq "asyncAll"
Truth table100%4/4
A or B or C
A= $val eq "for"B= $val eq "asyncEach"C= $val eq "asyncAll"
ABCresult
1XX1
01X1
0011
0000
Truth table0%0/4
A or B or C
A= $val eq "for"B= $val eq "asyncEach"C= $val eq "asyncAll"
ABCresult
1XX1
01X1
0011
0000
667 0 elsif ( $val eq 'block' ) { return $self->parse_block; }
668 0 elsif ( $val eq 'extends' ) { return $self->parse_extends; }
669 0 elsif ( $val eq 'include' ) { return $self->parse_include; }
670 0 elsif ( $val eq 'set' ) { return $self->parse_set; }
671 0 elsif ( $val eq 'macro' ) { return $self->parse_macro; }
672 0 elsif ( $val eq 'call' ) { return $self->parse_call; }
673 0 elsif ( $val eq 'import' ) { return $self->parse_import; }
674 0 elsif ( $val eq 'from' ) { return $self->parse_from; }
675 0 elsif ( $val eq 'filter' ) { return $self->parse_filter_statement; }
676 0 elsif ( $val eq 'switch' ) { return $self->parse_switch; }
677 else {
678 0 ▶ if ( @{ $self->extensions } ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@{$self->extensions;}) 19 5 24
if (@{$self->extensions;}) 0 0 0
679 0 for my $ext ( @{ $self->extensions } ) {
680 # ext.tags -- extension representation is k8 (undecided); read `tags`
681 # off a blessed object or a hashref, mirroring how the parser calls
682 # ext.parse below.
683 my $tags =
684 ( blessed($ext) && $ext->can('tags') ) ? $ext->tags
685 : ( ref($ext) eq 'HASH' ) ? $ext->{tags}
686 0 ▶ : undef;
Branch: 4 branches
BranchTrueFalseTotal
builtin::blessed($ext) && $ext->can('tags') ? : 25 0 25
ref $ext eq 'HASH' ? : 0 0 0
builtin::blessed($ext) && $ext->can('tags') ? : 0 0 0
ref $ext eq 'HASH' ? : 0 0 0
Condition16%1/6
builtin::blessed($ext) and $ext->can("tags")
!ll&&!rl&&r
0025
builtin::blessed($ext) and $ext->can("tags")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($ext) and $ext->can("tags")
builtin::blessed($ext) $ext->can("tags")
MC/DC0%0/2
builtin::blessed($ext) and $ext->can("tags")
builtin::blessed($ext) $ext->can("tags")
Truth table33%1/3
A and B
A= builtin::blessed($ext)B= $ext->can("tags")
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= builtin::blessed($ext)B= $ext->can("tags")
ABresult
0X0
100
111
687 0 ▶ if ( $self->lib->index_of( $tags || [], $tok->value ) != -1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->lib->index_of($tags || [], $tok->value) != -1) 19 6 25
if ($self->lib->index_of($tags || [], $tok->value) != -1) 0 0 0
Condition25%1/4
$tags || []
l!l
250
$tags || []
l!l
00
MC/DC0%0/1
$tags || []
$tags
MC/DC0%0/1
$tags || []
$tags
Truth table50%1/2
A
A= $tags
Aresult
11
00
Truth table0%0/2
A
A= $tags
Aresult
11
00
688 0 return $ext->parse( $self, $self->nodes_module, $self->lexer );
689 }
690 }
691 }
692 0 $self->fail( 'unknown block tag: ' . $tok->value, $tok->lineno, $tok->colno );
693 }
694  
695 0 return $node;
696 }
697  
698 35 ▶sub parse_raw {
Subroutine parse_raw: called CC=7 SCAR=26.6
Pod undocumented
699 0 ▶ my ( $self, $tag_name ) = @_;
Subroutine parse_raw: not called CC=7 SCAR=26.6
Pod undocumented
700 0 ▶ $tag_name = $tag_name || 'raw';
Condition50%2/4
$tag_name || 'raw'
l!l
1322
$tag_name || 'raw'
l!l
00
MC/DC100%1/1
$tag_name || 'raw'
$tag_name
MC/DC0%0/1
$tag_name || 'raw'
$tag_name
Truth table100%2/2
A
A= $tag_name
Aresult
11
00
Truth table0%0/2
A
A= $tag_name
Aresult
11
00
701 0 my $end_tag_name = 'end' . $tag_name;
702 # Look for upcoming raw blocks (ignore all other kinds of blocks). JS \s in
703 # the regex maps to the ECMAScript whitespace class (ADR 0005); [\s\S] means
704 # "any char" so its \s definition does not matter. `^`/`$` are not used here.
705 0 my $ws = $self->lib->js_whitespace_class;
706 0 my $raw_block_regex =
707 qr/([\s\S]*?)\{%${ws}*(${tag_name}|${end_tag_name})${ws}*(?=%\})%\}/;
708 0 my $raw_level = 1;
709 0 my $str = '';
710 0 my $matches = undef;
711  
712 # Skip opening raw token
713 # Keep this token to track line and column numbers
714 0 my $begun = $self->advance_after_block_end;
715  
716 # Exit when there's nothing to match
717 # or when we've found the matching "endraw" block
718 0 ▶ while ( ( $matches = $self->tokens->_extract_regex($raw_block_regex) ) && $raw_level > 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($matches = $self->tokens->_extract_regex($raw_block_regex) and $raw_level > 0) 43 35 78
if ($matches = $self->tokens->_extract_regex($raw_block_regex) and $raw_level > 0) 0 0 0
Condition33%2/6
$matches = $self->tokens->_extract_regex($raw_block_regex) and $raw_level > 0
!ll&&!rl&&r
03543
$matches = $self->tokens->_extract_regex($raw_block_regex) and $raw_level > 0
!ll&&!rl&&r
000
MC/DC50%1/2
$matches = $self->tokens->_extract_regex($raw_block_regex) and $raw_level > 0
$matches = $self->tokens->_extract_regex($raw_block_regex) $raw_level > 0
MC/DC0%0/2
$matches = $self->tokens->_extract_regex($raw_block_regex) and $raw_level > 0
$matches = $self->tokens->_extract_regex($raw_block_regex) $raw_level > 0
Truth table66%2/3
A and B
A= $matches = $self->tokens->_extract_regex($raw_block_regex)B= $raw_level > 0
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $matches = $self->tokens->_extract_regex($raw_block_regex)B= $raw_level > 0
ABresult
0X0
100
111
719 0 my $all = $matches->[0];
720 0 my $pre = $matches->[1];
721 0 my $block_name = $matches->[2];
722  
723 # Adjust rawlevel
724 0 ▶ if ( $block_name eq $tag_name ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($block_name eq $tag_name) { } 4 39 43
elsif ($block_name eq $end_tag_name) { } 39 0 39
if ($block_name eq $tag_name) { } 0 0 0
elsif ($block_name eq $end_tag_name) { } 0 0 0
725 0 $raw_level += 1;
726 }
727 elsif ( $block_name eq $end_tag_name ) {
728 0 $raw_level -= 1;
729 }
730  
731 # Add to str
732 0 ▶ if ( $raw_level == 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($raw_level == 0) { } 35 8 43
if ($raw_level == 0) { } 0 0 0
733 # We want to exclude the last "endraw"
734 0 $str .= $pre;
735 # Move tokenizer to beginning of endraw block
736 0 $self->tokens->back_n( length($all) - length($pre) );
737 }
738 else {
739 0 $str .= $all;
740 }
741 }
742  
743 0 return $self->node('Output')->new(
744 $begun->lineno, $begun->colno,
745 [ $self->node('TemplateData')->new( $begun->lineno, $begun->colno, $str ) ]
746 );
747 }
748  
749 59471 ▶sub parse_postfix {
Subroutine parse_postfix: called CC=8 SCAR=29.5
Pod undocumented
750 0 ▶ my ( $self, $node ) = @_;
Subroutine parse_postfix: not called CC=8 SCAR=29.5
Pod undocumented
751 0 my $lookup;
752 0 my $tok = $self->peek_token;
753  
754 0 ▶ while ($tok) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tok) 68058 10 68068
if ($tok) 0 0 0
755 0 ▶ if ( $tok->type eq $self->lexer->TOKEN_LEFT_PAREN ) {
Branch: 6 branches
BranchTrueFalseTotal
if ($tok->type eq $self->lexer->TOKEN_LEFT_PAREN) { } 7092 60966 68058
elsif ($tok->type eq $self->lexer->TOKEN_LEFT_BRACKET) { } 148 60818 60966
elsif ($tok->type eq $self->lexer->TOKEN_OPERATOR and $tok->value eq '.') { } 1360 59458 60818
if ($tok->type eq $self->lexer->TOKEN_LEFT_PAREN) { } 0 0 0
elsif ($tok->type eq $self->lexer->TOKEN_LEFT_BRACKET) { } 0 0 0
elsif ($tok->type eq $self->lexer->TOKEN_OPERATOR and $tok->value eq '.') { } 0 0 0
756 # Function call
757 0 $node = $self->node('FunCall')->new(
758 $tok->lineno, $tok->colno,
759 $node, $self->parse_signature
760 );
761 }
762 elsif ( $tok->type eq $self->lexer->TOKEN_LEFT_BRACKET ) {
763 # Reference
764 0 $lookup = $self->parse_aggregate;
765 0 ▶ if ( @{ $lookup->children } > 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@{$lookup->children;} > 1) 0 148 148
if (@{$lookup->children;} > 1) 0 0 0
766 0 $self->fail('invalid index');
767 }
768  
769 0 $node = $self->node('LookupVal')->new(
770 $tok->lineno, $tok->colno,
771 $node, $lookup->children->[0]
772 );
773 }
774 ▶ elsif ( $tok->type eq $self->lexer->TOKEN_OPERATOR && $tok->value eq '.' ) {
Condition50%3/6
$tok->type eq $self->lexer->TOKEN_OPERATOR and $tok->value eq "."
!ll&&!rl&&r
5094985091360
$tok->type eq $self->lexer->TOKEN_OPERATOR and $tok->value eq "."
!ll&&!rl&&r
000
MC/DC100%2/2
$tok->type eq $self->lexer->TOKEN_OPERATOR and $tok->value eq "."
$tok->type eq $self->lexer->TOKEN_OPERATOR $tok->value eq "."
MC/DC0%0/2
$tok->type eq $self->lexer->TOKEN_OPERATOR and $tok->value eq "."
$tok->type eq $self->lexer->TOKEN_OPERATOR $tok->value eq "."
Truth table100%3/3
A and B
A= $tok->type eq $self->lexer->TOKEN_OPERATORB= $tok->value eq "."
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $tok->type eq $self->lexer->TOKEN_OPERATORB= $tok->value eq "."
ABresult
0X0
100
111
775 # Reference
776 0 $self->next_token;
777 0 my $val = $self->next_token;
778  
779 0 ▶ if ( $val->type ne $self->lexer->TOKEN_SYMBOL ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($val->type ne $self->lexer->TOKEN_SYMBOL) 0 1360 1360
if ($val->type ne $self->lexer->TOKEN_SYMBOL) 0 0 0
780 0 $self->fail( 'expected name as lookup value, got ' . $val->value,
781 $val->lineno, $val->colno );
782 }
783  
784 # Make a literal string because it's not a variable
785 # reference
786 0 $lookup = $self->node('Literal')->new( $val->lineno, $val->colno, $val->value );
787  
788 0 $node = $self->node('LookupVal')->new(
789 $tok->lineno, $tok->colno,
790 $node, $lookup
791 );
792 }
793 else {
794 0 last;
795 }
796  
797 0 $tok = $self->peek_token;
798 }
799  
800 0 return $node;
801 }
802  
803 41551 ▶sub parse_expression {
Subroutine parse_expression: called CC=1 SCAR=1.2
Pod undocumented
804 0 ▶ my ($self) = @_;
Subroutine parse_expression: not called CC=1 SCAR=1.2
Pod undocumented
805 0 my $node = $self->parse_inline_if;
806 0 return $node;
807 }
808  
809 41551 ▶sub parse_inline_if {
Subroutine parse_inline_if: called CC=3 SCAR=14.2
Pod undocumented
810 0 ▶ my ($self) = @_;
Subroutine parse_inline_if: not called CC=3 SCAR=14.2
Pod undocumented
811 0 my $node = $self->parse_or;
812 0 ▶ if ( $self->skip_symbol('if') ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->skip_symbol("if")) 138 41401 41539
if ($self->skip_symbol("if")) 0 0 0
813 0 my $cond_node = $self->parse_or;
814 0 my $body_node = $node;
815 0 $node = $self->node('InlineIf')->new( $node->lineno, $node->colno );
816 0 $node->body($body_node);
817 0 $node->cond($cond_node);
818 0 ▶ if ( $self->skip_symbol('else') ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->skip_symbol('else')) { } 39 99 138
if ($self->skip_symbol('else')) { } 0 0 0
819 0 $node->else_( $self->parse_or );
820 }
821 else {
822 0 $node->else_(undef);
823 }
824 }
825  
826 0 return $node;
827 }
828  
829 41728 ▶sub parse_or {
Subroutine parse_or: called CC=2 SCAR=9.2
Pod undocumented
830 0 ▶ my ($self) = @_;
Subroutine parse_or: not called CC=2 SCAR=9.2
Pod undocumented
831 0 my $node = $self->parse_and;
832 0 ▶ while ( $self->skip_symbol('or') ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->skip_symbol("or")) 18 41716 41734
if ($self->skip_symbol("or")) 0 0 0
833 0 my $node2 = $self->parse_and;
834 0 $node = $self->node('Or')->new( $node->lineno, $node->colno, $node, $node2 );
835 }
836 0 return $node;
837 }
838  
839 41746 ▶sub parse_and {
Subroutine parse_and: called CC=2 SCAR=9.2
Pod undocumented
840 0 ▶ my ($self) = @_;
Subroutine parse_and: not called CC=2 SCAR=9.2
Pod undocumented
841 0 my $node = $self->parse_not;
842 0 ▶ while ( $self->skip_symbol('and') ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->skip_symbol("and")) 12 41734 41746
if ($self->skip_symbol("and")) 0 0 0
843 0 my $node2 = $self->parse_not;
844 0 $node = $self->node('And')->new( $node->lineno, $node->colno, $node, $node2 );
845 }
846 0 return $node;
847 }
848  
849 41854 ▶sub parse_not {
Subroutine parse_not: called CC=2 SCAR=9.2
Pod undocumented
850 0 ▶ my ($self) = @_;
Subroutine parse_not: not called CC=2 SCAR=9.2
Pod undocumented
851 0 my $tok = $self->peek_token;
852 0 ▶ if ( $self->skip_symbol('not') ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->skip_symbol("not")) 96 41758 41854
if ($self->skip_symbol("not")) 0 0 0
853 0 return $self->node('Not')->new( $tok->lineno, $tok->colno, $self->parse_not );
854 }
855 0 return $self->parse_in;
856 }
857  
858 41758 ▶sub parse_in {
Subroutine parse_in: called CC=7 SCAR=26.7
Pod undocumented
859 0 ▶ my ($self) = @_;
Subroutine parse_in: not called CC=7 SCAR=26.7
Pod undocumented
860 0 my $node = $self->parse_is;
861 0 while (1) {
862 # check if the next token is 'not'
863 0 my $tok = $self->next_token;
864 0 ▶ if ( !$tok ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($tok) 5 41792 41797
unless ($tok) 0 0 0
865 0 last;
866 }
867 0 ▶ my $invert = $tok->type eq $self->lexer->TOKEN_SYMBOL && $tok->value eq 'not';
Condition50%3/6
$tok->type eq $self->lexer->TOKEN_SYMBOL && $tok->value eq 'not'
!ll&&!rl&&r
4017216128
$tok->type eq $self->lexer->TOKEN_SYMBOL && $tok->value eq 'not'
!ll&&!rl&&r
000
MC/DC100%2/2
$tok->type eq $self->lexer->TOKEN_SYMBOL && $tok->value eq 'not'
$tok->type eq $self->lexer->TOKEN_SYMBOL $tok->value eq 'not'
MC/DC0%0/2
$tok->type eq $self->lexer->TOKEN_SYMBOL && $tok->value eq 'not'
$tok->type eq $self->lexer->TOKEN_SYMBOL $tok->value eq 'not'
Truth table100%3/3
A && B
A= $tok->type eq $self->lexer->TOKEN_SYMBOLB= $tok->value eq 'not'
ABresult
0X0
100
111
Truth table0%0/3
A && B
A= $tok->type eq $self->lexer->TOKEN_SYMBOLB= $tok->value eq 'not'
ABresult
0X0
100
111
868 # if it wasn't 'not', put it back
869 0 ▶ if ( !$invert ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($invert) 41784 8 41792
unless ($invert) 0 0 0
870 0 $self->push_token($tok);
871 }
872 0 ▶ if ( $self->skip_symbol('in') ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->skip_symbol('in')) { } 51 41741 41792
if ($self->skip_symbol('in')) { } 0 0 0
873 0 my $node2 = $self->parse_is;
874 0 $node = $self->node('In')->new( $node->lineno, $node->colno, $node, $node2 );
875 0 ▶ if ($invert) {
Branch: 2 branches
BranchTrueFalseTotal
if ($invert) 8 43 51
if ($invert) 0 0 0
876 0 $node = $self->node('Not')->new( $node->lineno, $node->colno, $node );
877 }
878 }
879 else {
880 # if we'd found a 'not' but this wasn't an 'in', put back the 'not'
881 0 ▶ if ($invert) {
Branch: 2 branches
BranchTrueFalseTotal
if ($invert) 0 41741 41741
if ($invert) 0 0 0
882 0 $self->push_token($tok);
883 }
884 0 last;
885 }
886 }
887 0 return $node;
888 }
889  
890 # I put this right after "in" in the operator precedence stack. That can
891 # obviously be changed to be closer to Jinja.
892 41809 ▶sub parse_is {
Subroutine parse_is: called CC=3 SCAR=14.2
Pod undocumented
893 0 ▶ my ($self) = @_;
Subroutine parse_is: not called CC=3 SCAR=14.2
Pod undocumented
894 0 my $node = $self->parse_compare;
895 # look for an is
896 0 ▶ if ( $self->skip_symbol('is') ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->skip_symbol("is")) 284 41513 41797
if ($self->skip_symbol("is")) 0 0 0
897 # look for a not
898 0 my $not = $self->skip_symbol('not');
899 # get the next node
900 0 my $node2 = $self->parse_compare;
901 # create an Is node using the next node and the info from our Is node.
902 0 $node = $self->node('Is')->new( $node->lineno, $node->colno, $node, $node2 );
903 # if we have a Not, create a Not node from our Is node.
904 0 ▶ if ($not) {
Branch: 2 branches
BranchTrueFalseTotal
if ($not) 27 257 284
if ($not) 0 0 0
905 0 $node = $self->node('Not')->new( $node->lineno, $node->colno, $node );
906 }
907 }
908 # return the node.
909 0 return $node;
910 }
911  
912 42093 ▶sub parse_compare {
Subroutine parse_compare: called CC=4 SCAR=17.9
Pod undocumented
913 0 ▶ my ($self) = @_;
Subroutine parse_compare: not called CC=4 SCAR=17.9
Pod undocumented
914 0 my @compare_ops = ( '==', '===', '!=', '!==', '<', '>', '<=', '>=' );
915 0 my $expr = $self->parse_concat;
916 0 my @ops;
917  
918 0 while (1) {
919 0 my $tok = $self->next_token;
920  
921 0 ▶ if ( !$tok ) {
Branch: 4 branches
BranchTrueFalseTotal
if (not $tok) { } 5 44061 44066
elsif ($self->lib->index_of(\@compare_ops, $tok->value) != -1) { } 1985 42076 44061
if (not $tok) { } 0 0 0
elsif ($self->lib->index_of(\@compare_ops, $tok->value) != -1) { } 0 0 0
922 0 last;
923 }
924 elsif ( $self->lib->index_of( \@compare_ops, $tok->value ) != -1 ) {
925 0 push @ops,
926 $self->node('CompareOperand')->new(
927 $tok->lineno, $tok->colno,
928 $self->parse_concat, $tok->value
929 );
930 }
931 else {
932 0 $self->push_token($tok);
933 0 last;
934 }
935 }
936  
937 0 ▶ if (@ops) {
Branch: 2 branches
BranchTrueFalseTotal
if (@ops) { } 1979 40102 42081
if (@ops) { } 0 0 0
938 0 return $self->node('Compare')->new( $ops[0]->lineno, $ops[0]->colno, $expr, \@ops );
939 }
940 else {
941 0 return $expr;
942 }
943 }
944  
945 # finds the '~' for string concatenation
946 44078 ▶sub parse_concat {
Subroutine parse_concat: called CC=2 SCAR=9.2
Pod undocumented
947 0 ▶ my ($self) = @_;
Subroutine parse_concat: not called CC=2 SCAR=9.2
Pod undocumented
948 0 my $node = $self->parse_add;
949 0 ▶ while ( $self->skip_value( $self->lexer->TOKEN_TILDE, '~' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->skip_value($self->lexer->TOKEN_TILDE, "~")) 138 44066 44204
if ($self->skip_value($self->lexer->TOKEN_TILDE, "~")) 0 0 0
950 0 my $node2 = $self->parse_add;
951 0 $node = $self->node('Concat')->new( $node->lineno, $node->colno, $node, $node2 );
952 }
953 0 return $node;
954 }
955  
956 44216 ▶sub parse_add {
Subroutine parse_add: called CC=2 SCAR=9.2
Pod undocumented
957 0 ▶ my ($self) = @_;
Subroutine parse_add: not called CC=2 SCAR=9.2
Pod undocumented
958 0 my $node = $self->parse_sub;
959 0 ▶ while ( $self->skip_value( $self->lexer->TOKEN_OPERATOR, '+' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->skip_value($self->lexer->TOKEN_OPERATOR, "+")) 74 44204 44278
if ($self->skip_value($self->lexer->TOKEN_OPERATOR, "+")) 0 0 0
960 0 my $node2 = $self->parse_sub;
961 0 $node = $self->node('Add')->new( $node->lineno, $node->colno, $node, $node2 );
962 }
963 0 return $node;
964 }
965  
966 44290 ▶sub parse_sub {
Subroutine parse_sub: called CC=2 SCAR=9.2
Pod undocumented
967 0 ▶ my ($self) = @_;
Subroutine parse_sub: not called CC=2 SCAR=9.2
Pod undocumented
968 0 my $node = $self->parse_mul;
969 0 ▶ while ( $self->skip_value( $self->lexer->TOKEN_OPERATOR, '-' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->skip_value($self->lexer->TOKEN_OPERATOR, "-")) 1923 44278 46201
if ($self->skip_value($self->lexer->TOKEN_OPERATOR, "-")) 0 0 0
970 0 my $node2 = $self->parse_mul;
971 0 $node = $self->node('Sub')->new( $node->lineno, $node->colno, $node, $node2 );
972 }
973 0 return $node;
974 }
975  
976 46213 ▶sub parse_mul {
Subroutine parse_mul: called CC=2 SCAR=9.2
Pod undocumented
977 0 ▶ my ($self) = @_;
Subroutine parse_mul: not called CC=2 SCAR=9.2
Pod undocumented
978 0 my $node = $self->parse_div;
979 0 ▶ while ( $self->skip_value( $self->lexer->TOKEN_OPERATOR, '*' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->skip_value($self->lexer->TOKEN_OPERATOR, "*")) 63 46201 46264
if ($self->skip_value($self->lexer->TOKEN_OPERATOR, "*")) 0 0 0
980 0 my $node2 = $self->parse_div;
981 0 $node = $self->node('Mul')->new( $node->lineno, $node->colno, $node, $node2 );
982 }
983 0 return $node;
984 }
985  
986 46276 ▶sub parse_div {
Subroutine parse_div: called CC=2 SCAR=9.2
Pod undocumented
987 0 ▶ my ($self) = @_;
Subroutine parse_div: not called CC=2 SCAR=9.2
Pod undocumented
988 0 my $node = $self->parse_floor_div;
989 0 ▶ while ( $self->skip_value( $self->lexer->TOKEN_OPERATOR, '/' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->skip_value($self->lexer->TOKEN_OPERATOR, "/")) 404 46264 46668
if ($self->skip_value($self->lexer->TOKEN_OPERATOR, "/")) 0 0 0
990 0 my $node2 = $self->parse_floor_div;
991 0 $node = $self->node('Div')->new( $node->lineno, $node->colno, $node, $node2 );
992 }
993 0 return $node;
994 }
995  
996 46680 ▶sub parse_floor_div {
Subroutine parse_floor_div: called CC=2 SCAR=9.2
Pod undocumented
997 0 ▶ my ($self) = @_;
Subroutine parse_floor_div: not called CC=2 SCAR=9.2
Pod undocumented
998 0 my $node = $self->parse_mod;
999 0 ▶ while ( $self->skip_value( $self->lexer->TOKEN_OPERATOR, '//' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->skip_value($self->lexer->TOKEN_OPERATOR, "//")) 5 46668 46673
if ($self->skip_value($self->lexer->TOKEN_OPERATOR, "//")) 0 0 0
1000 0 my $node2 = $self->parse_mod;
1001 0 $node = $self->node('FloorDiv')->new( $node->lineno, $node->colno, $node, $node2 );
1002 }
1003 0 return $node;
1004 }
1005  
1006 46685 ▶sub parse_mod {
Subroutine parse_mod: called CC=2 SCAR=9.2
Pod undocumented
1007 0 ▶ my ($self) = @_;
Subroutine parse_mod: not called CC=2 SCAR=9.2
Pod undocumented
1008 0 my $node = $self->parse_pow;
1009 0 ▶ while ( $self->skip_value( $self->lexer->TOKEN_OPERATOR, '%' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->skip_value($self->lexer->TOKEN_OPERATOR, "%")) 38 46673 46711
if ($self->skip_value($self->lexer->TOKEN_OPERATOR, "%")) 0 0 0
1010 0 my $node2 = $self->parse_pow;
1011 0 $node = $self->node('Mod')->new( $node->lineno, $node->colno, $node, $node2 );
1012 }
1013 0 return $node;
1014 }
1015  
1016 46723 ▶sub parse_pow {
Subroutine parse_pow: called CC=2 SCAR=9.2
Pod undocumented
1017 0 ▶ my ($self) = @_;
Subroutine parse_pow: not called CC=2 SCAR=9.2
Pod undocumented
1018 0 my $node = $self->parse_unary;
1019 0 ▶ while ( $self->skip_value( $self->lexer->TOKEN_OPERATOR, '**' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->skip_value($self->lexer->TOKEN_OPERATOR, "**")) 29 46711 46740
if ($self->skip_value($self->lexer->TOKEN_OPERATOR, "**")) 0 0 0
1020 0 my $node2 = $self->parse_unary;
1021 0 $node = $self->node('Pow')->new( $node->lineno, $node->colno, $node, $node2 );
1022 }
1023 0 return $node;
1024 }
1025  
1026 47144 ▶sub parse_unary {
Subroutine parse_unary: called CC=4 SCAR=17.9
Pod undocumented
1027 0 ▶ my ( $self, $no_filters ) = @_;
Subroutine parse_unary: not called CC=4 SCAR=17.9
Pod undocumented
1028 0 my $tok = $self->peek_token;
1029 0 my $node;
1030  
1031 0 ▶ if ( $self->skip_value( $self->lexer->TOKEN_OPERATOR, '-' ) ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($self->skip_value($self->lexer->TOKEN_OPERATOR, '-')) { } 391 46753 47144
elsif ($self->skip_value($self->lexer->TOKEN_OPERATOR, '+')) { } 1 46752 46753
if ($self->skip_value($self->lexer->TOKEN_OPERATOR, '-')) { } 0 0 0
elsif ($self->skip_value($self->lexer->TOKEN_OPERATOR, '+')) { } 0 0 0
1032 0 $node = $self->node('Neg')->new( $tok->lineno, $tok->colno, $self->parse_unary(1) );
1033 }
1034 elsif ( $self->skip_value( $self->lexer->TOKEN_OPERATOR, '+' ) ) {
1035 0 $node = $self->node('Pos')->new( $tok->lineno, $tok->colno, $self->parse_unary(1) );
1036 }
1037 else {
1038 0 $node = $self->parse_primary;
1039 }
1040  
1041 0 ▶ if ( !$no_filters ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($no_filters) 46741 392 47133
unless ($no_filters) 0 0 0
1042 0 $node = $self->parse_filter($node);
1043 }
1044  
1045 0 return $node;
1046 }
1047  
1048 55936 ▶sub parse_primary {
Subroutine parse_primary: called CC=14 SCAR=37.2
Pod undocumented
1049 0 ▶ my ( $self, $no_postfix ) = @_;
Subroutine parse_primary: not called CC=14 SCAR=37.2
Pod undocumented
1050 0 my $tok = $self->next_token;
1051 0 my $val;
1052 0 my $has_val = 0; # JS distinguishes "val was set" (incl. null/false/0/'')
1053 # from "still undefined"; a Perl flag stands in for that.
1054 0 my $node = undef;
1055  
1056 0 ▶ if ( !$tok ) {
Branch: 14 branches
BranchTrueFalseTotal
if (not $tok) { } 2 55934 55936
elsif ($tok->type eq $self->lexer->TOKEN_STRING) { } 9870 46064 55934
elsif ($tok->type eq $self->lexer->TOKEN_INT) { } 13915 32149 46064
elsif ($tok->type eq $self->lexer->TOKEN_FLOAT) { } 353 31796 32149
elsif ($tok->type eq $self->lexer->TOKEN_BOOLEAN) { } 812 30984 31796
elsif ($tok->type eq $self->lexer->TOKEN_NONE) { } 233 30751 30984
elsif ($tok->type eq $self->lexer->TOKEN_REGEX) { } 155 30596 30751
if (not $tok) { } 0 0 0
elsif ($tok->type eq $self->lexer->TOKEN_STRING) { } 0 0 0
elsif ($tok->type eq $self->lexer->TOKEN_INT) { } 0 0 0
elsif ($tok->type eq $self->lexer->TOKEN_FLOAT) { } 0 0 0
elsif ($tok->type eq $self->lexer->TOKEN_BOOLEAN) { } 0 0 0
elsif ($tok->type eq $self->lexer->TOKEN_NONE) { } 0 0 0
elsif ($tok->type eq $self->lexer->TOKEN_REGEX) { } 0 0 0
1057 0 $self->fail('expected expression, got end of file');
1058 }
1059 elsif ( $tok->type eq $self->lexer->TOKEN_STRING ) {
1060 0 $val = $tok->value;
1061 0 $has_val = 1;
1062 }
1063 elsif ( $tok->type eq $self->lexer->TOKEN_INT ) {
1064 # parseInt(tok.value, 10) -- number-literal parsing rides on k4; the lexer
1065 # already guarantees tok.value is pure digits, so 0 + value suffices.
1066 0 $val = 0 + $tok->value;
1067 0 $has_val = 1;
1068 }
1069 elsif ( $tok->type eq $self->lexer->TOKEN_FLOAT ) {
1070 # parseFloat(tok.value) -- see k4 note above.
1071 0 $val = 0 + $tok->value;
1072 0 $has_val = 1;
1073 }
1074 elsif ( $tok->type eq $self->lexer->TOKEN_BOOLEAN ) {
1075 0 ▶ if ( $tok->value eq 'true' ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($tok->value eq 'true') { } 661 151 812
elsif ($tok->value eq 'false') { } 151 0 151
if ($tok->value eq 'true') { } 0 0 0
elsif ($tok->value eq 'false') { } 0 0 0
1076 0 $val = true;
1077 0 $has_val = 1;
1078 }
1079 elsif ( $tok->value eq 'false' ) {
1080 0 $val = false;
1081 0 $has_val = 1;
1082 }
1083 else {
1084 0 $self->fail( 'invalid boolean: ' . $tok->value, $tok->lineno, $tok->colno );
1085 }
1086 }
1087 elsif ( $tok->type eq $self->lexer->TOKEN_NONE ) {
1088 0 $val = undef; # JS null
1089 0 $has_val = 1;
1090 }
1091 elsif ( $tok->type eq $self->lexer->TOKEN_REGEX ) {
1092 # new RegExp(tok.value.body, tok.value.flags). k7 (regex literals) is open:
1093 # the runtime representation (qr// vs object) is undecided. The parser only
1094 # needs a Literal whose AST dump matches the oracle's { regex, flags }
1095 # shape, so it carries the lexer's regex token through as that hashref.
1096 # When k7 lands, this seam and t/corpus.t's Regexp branch take the decided
1097 # representation.
1098 0 $val = { regex => $tok->value->{body}, flags => $tok->value->{flags} };
1099 0 $has_val = 1;
1100 }
1101  
1102 0 ▶ if ($has_val) {
Branch: 4 branches
BranchTrueFalseTotal
if ($has_val) { } 25338 30596 55934
elsif ($tok->type eq $self->lexer->TOKEN_SYMBOL) { } 27145 3451 30596
if ($has_val) { } 0 0 0
elsif ($tok->type eq $self->lexer->TOKEN_SYMBOL) { } 0 0 0
1103 0 $node = $self->node('Literal')->new( $tok->lineno, $tok->colno, $val );
1104 }
1105 elsif ( $tok->type eq $self->lexer->TOKEN_SYMBOL ) {
1106 0 $node = $self->node('Symbol')->new( $tok->lineno, $tok->colno, $tok->value );
1107 }
1108 else {
1109 # See if it's an aggregate type, we need to push the
1110 # current delimiter token back on
1111 0 $self->push_token($tok);
1112 0 $node = $self->parse_aggregate;
1113 }
1114  
1115 0 ▶ if ( !$no_postfix ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($no_postfix) 54586 1346 55932
unless ($no_postfix) 0 0 0
1116 0 $node = $self->parse_postfix($node);
1117 }
1118  
1119 0 ▶ if ($node) {
Branch: 2 branches
BranchTrueFalseTotal
if ($node) { } 55924 6 55930
if ($node) { } 0 0 0
1120 0 return $node;
1121 }
1122 else {
1123 0 die $self->error( 'unexpected token: ' . $tok->value, $tok->lineno, $tok->colno );
1124 }
1125 }
1126  
1127 10481 ▶sub parse_filter_name {
Subroutine parse_filter_name: called CC=2 SCAR=10.9
Pod undocumented
1128 0 ▶ my ($self) = @_;
Subroutine parse_filter_name: not called CC=2 SCAR=10.9
Pod undocumented
1129 0 my $tok = $self->expect( $self->lexer->TOKEN_SYMBOL );
1130 0 my $name = $tok->value;
1131  
1132 0 ▶ while ( $self->skip_value( $self->lexer->TOKEN_OPERATOR, '.' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->skip_value($self->lexer->TOKEN_OPERATOR, ".")) 0 10481 10481
if ($self->skip_value($self->lexer->TOKEN_OPERATOR, ".")) 0 0 0
1133 0 $name .= '.' . $self->expect( $self->lexer->TOKEN_SYMBOL )->value;
1134 }
1135  
1136 0 return $self->node('Symbol')->new( $tok->lineno, $tok->colno, $name );
1137 }
1138  
1139 10481 ▶sub parse_filter_args {
Subroutine parse_filter_args: called CC=2 SCAR=9.2
Pod undocumented
1140 0 ▶ my ( $self, $node ) = @_;
Subroutine parse_filter_args: not called CC=2 SCAR=9.2
Pod undocumented
1141 0 ▶ if ( $self->peek_token->type eq $self->lexer->TOKEN_LEFT_PAREN ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->peek_token->type eq $self->lexer->TOKEN_LEFT_PAREN) 4885 5596 10481
if ($self->peek_token->type eq $self->lexer->TOKEN_LEFT_PAREN) 0 0 0
1142 # Get a FunCall node and add the parameters to the
1143 # filter
1144 0 my $call = $self->parse_postfix($node);
1145 0 return $call->args->children;
1146 }
1147 0 return [];
1148 }
1149  
1150 46741 ▶sub parse_filter {
Subroutine parse_filter: called CC=2 SCAR=9.2
Pod undocumented
1151 0 ▶ my ( $self, $node ) = @_;
Subroutine parse_filter: not called CC=2 SCAR=9.2
Pod undocumented
1152 0 ▶ while ( $self->skip( $self->lexer->TOKEN_PIPE ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->skip($self->lexer->TOKEN_PIPE)) 10463 46740 57203
if ($self->skip($self->lexer->TOKEN_PIPE)) 0 0 0
1153 0 my $name = $self->parse_filter_name;
1154  
1155 $node = $self->node('Filter')->new(
1156 $name->lineno, $name->colno,
1157 $name,
1158 $self->node('NodeList')->new(
1159 $name->lineno, $name->colno,
1160 0 [ $node, @{ $self->parse_filter_args($node) } ]
1161 )
1162 );
1163 }
1164  
1165 0 return $node;
1166 }
1167  
1168 18 ▶sub parse_filter_statement {
Subroutine parse_filter_statement: called CC=2 SCAR=10.2
Pod undocumented
1169 0 ▶ my ($self) = @_;
Subroutine parse_filter_statement: not called CC=2 SCAR=10.2
Pod undocumented
1170 0 my $filter_tok = $self->peek_token;
1171 0 ▶ if ( !$self->skip_symbol('filter') ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($self->skip_symbol("filter")) 0 18 18
unless ($self->skip_symbol("filter")) 0 0 0
1172 0 $self->fail('parseFilterStatement: expected filter');
1173 }
1174  
1175 0 my $name = $self->parse_filter_name;
1176 0 my $args = $self->parse_filter_args($name);
1177  
1178 0 $self->advance_after_block_end( $filter_tok->value );
1179 0 my $body = $self->node('Capture')->new(
1180 $name->lineno, $name->colno,
1181 $self->parse_until_blocks('endfilter')
1182 );
1183 0 $self->advance_after_block_end;
1184  
1185 0 my $node = $self->node('Filter')->new(
1186 $name->lineno, $name->colno,
1187 $name,
1188 $self->node('NodeList')->new(
1189 $name->lineno, $name->colno,
1190 [ $body, @$args ]
1191 )
1192 );
1193  
1194 0 return $self->node('Output')->new( $name->lineno, $name->colno, [$node] );
1195 }
1196  
1197 3599 ▶sub parse_aggregate {
Subroutine parse_aggregate: called CC=11 SCAR=34.1
Pod undocumented
1198 0 ▶ my ($self) = @_;
Subroutine parse_aggregate: not called CC=11 SCAR=34.1
Pod undocumented
1199 0 my $tok = $self->next_token;
1200 0 my $node;
1201  
1202 0 ▶ if ( $tok->type eq $self->lexer->TOKEN_LEFT_PAREN ) {
Branch: 6 branches
BranchTrueFalseTotal
if ($tok->type eq $self->lexer->TOKEN_LEFT_PAREN) { } 571 3028 3599
elsif ($tok->type eq $self->lexer->TOKEN_LEFT_BRACKET) { } 2225 803 3028
elsif ($tok->type eq $self->lexer->TOKEN_LEFT_CURLY) { } 797 6 803
if ($tok->type eq $self->lexer->TOKEN_LEFT_PAREN) { } 0 0 0
elsif ($tok->type eq $self->lexer->TOKEN_LEFT_BRACKET) { } 0 0 0
elsif ($tok->type eq $self->lexer->TOKEN_LEFT_CURLY) { } 0 0 0
1203 0 $node = $self->node('Group')->new( $tok->lineno, $tok->colno );
1204 }
1205 elsif ( $tok->type eq $self->lexer->TOKEN_LEFT_BRACKET ) {
1206 0 $node = $self->node('Array')->new( $tok->lineno, $tok->colno );
1207 }
1208 elsif ( $tok->type eq $self->lexer->TOKEN_LEFT_CURLY ) {
1209 0 $node = $self->node('Dict')->new( $tok->lineno, $tok->colno );
1210 }
1211 else {
1212 0 return undef;
1213 }
1214  
1215 0 while (1) {
1216 0 my $type = $self->peek_token->type;
1217 0 ▶ if ( $type eq $self->lexer->TOKEN_RIGHT_PAREN
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq $self->lexer->TOKEN_RIGHT_PAREN or $type eq $self->lexer->TOKEN_RIGHT_BRACKET or $type eq $self->lexer->TOKEN_RIGHT_CURLY) 3591 6874 10465
if ($type eq $self->lexer->TOKEN_RIGHT_PAREN or $type eq $self->lexer->TOKEN_RIGHT_BRACKET or $type eq $self->lexer->TOKEN_RIGHT_CURLY) 0 0 0
Condition50%6/12
$type eq $self->lexer->TOKEN_RIGHT_PAREN or $type eq $self->lexer->TOKEN_RIGHT_BRACKET or $type eq $self->lexer->TOKEN_RIGHT_CURLY
l!l&&r!l&&!r
27947976874
$type eq $self->lexer->TOKEN_RIGHT_PAREN or $type eq $self->lexer->TOKEN_RIGHT_BRACKET
l!l&&r!l&&!r
57022247671
$type eq $self->lexer->TOKEN_RIGHT_PAREN or $type eq $self->lexer->TOKEN_RIGHT_BRACKET or $type eq $self->lexer->TOKEN_RIGHT_CURLY
l!l&&r!l&&!r
000
$type eq $self->lexer->TOKEN_RIGHT_PAREN or $type eq $self->lexer->TOKEN_RIGHT_BRACKET
l!l&&r!l&&!r
000
MC/DC100%3/3
$type eq $self->lexer->TOKEN_RIGHT_PAREN or $type eq $self->lexer->TOKEN_RIGHT_BRACKET or $type eq $self->lexer->TOKEN_RIGHT_CURLY
$type eq $self->lexer->TOKEN_RIGHT_PAREN $type eq $self->lexer->TOKEN_RIGHT_BRACKET $type eq $self->lexer->TOKEN_RIGHT_CURLY
MC/DC0%0/3
$type eq $self->lexer->TOKEN_RIGHT_PAREN or $type eq $self->lexer->TOKEN_RIGHT_BRACKET or $type eq $self->lexer->TOKEN_RIGHT_CURLY
$type eq $self->lexer->TOKEN_RIGHT_PAREN $type eq $self->lexer->TOKEN_RIGHT_BRACKET $type eq $self->lexer->TOKEN_RIGHT_CURLY
Truth table100%4/4
A or B or C
A= $type eq $self->lexer->TOKEN_RIGHT_PARENB= $type eq $self->lexer->TOKEN_RIGHT_BRACKETC= $type eq $self->lexer->TOKEN_RIGHT_CURLY
ABCresult
1XX1
01X1
0011
0000
Truth table0%0/4
A or B or C
A= $type eq $self->lexer->TOKEN_RIGHT_PARENB= $type eq $self->lexer->TOKEN_RIGHT_BRACKETC= $type eq $self->lexer->TOKEN_RIGHT_CURLY
ABCresult
1XX1
01X1
0011
0000
1218 || $type eq $self->lexer->TOKEN_RIGHT_BRACKET
1219 || $type eq $self->lexer->TOKEN_RIGHT_CURLY )
1220 {
1221 0 $self->next_token;
1222 0 last;
1223 }
1224  
1225 0 ▶ if ( @{ $node->children } > 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@{$node->children;} > 0) 3669 3205 6874
if (@{$node->children;} > 0) 0 0 0
1226 0 ▶ if ( !$self->skip( $self->lexer->TOKEN_COMMA ) ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($self->skip($self->lexer->TOKEN_COMMA)) 0 3669 3669
unless ($self->skip($self->lexer->TOKEN_COMMA)) 0 0 0
1227 0 $self->fail( 'parseAggregate: expected comma after expression',
1228 $tok->lineno, $tok->colno );
1229 }
1230 }
1231  
1232 0 ▶ if ( $node->isa( $self->node('Dict') ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($node->isa($self->node('Dict'))) { } 1155 5719 6874
if ($node->isa($self->node('Dict'))) { } 0 0 0
1233 # TODO: check for errors
1234 0 my $key = $self->parse_primary;
1235  
1236 # We expect a key/value pair for dicts, separated by a
1237 # colon
1238 0 ▶ if ( !$self->skip( $self->lexer->TOKEN_COLON ) ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($self->skip($self->lexer->TOKEN_COLON)) 0 1155 1155
unless ($self->skip($self->lexer->TOKEN_COLON)) 0 0 0
1239 0 $self->fail( 'parseAggregate: expected colon after dict key',
1240 $tok->lineno, $tok->colno );
1241 }
1242  
1243 # TODO: check for errors
1244 0 my $value = $self->parse_expression;
1245 0 $node->add_child(
1246 $self->node('Pair')->new( $key->lineno, $key->colno, $key, $value )
1247 );
1248 }
1249 else {
1250 # TODO: check for errors
1251 0 my $expr = $self->parse_expression;
1252 0 $node->add_child($expr);
1253 }
1254 }
1255  
1256 0 return $node;
1257 }
1258  
1259 8533 ▶sub parse_signature {
Subroutine parse_signature: called CC=13 SCAR=36.0
Pod undocumented
1260 0 ▶ my ( $self, $tolerant, $no_parens ) = @_;
Subroutine parse_signature: not called CC=13 SCAR=36.0
Pod undocumented
1261 0 my $tok = $self->peek_token;
1262 0 ▶ if ( !$no_parens && $tok->type ne $self->lexer->TOKEN_LEFT_PAREN ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $no_parens and $tok->type ne $self->lexer->TOKEN_LEFT_PAREN) 76 8457 8533
if (not $no_parens and $tok->type ne $self->lexer->TOKEN_LEFT_PAREN) 0 0 0
Condition50%3/6
not $no_parens and $tok->type ne $self->lexer->TOKEN_LEFT_PAREN
!ll&&!rl&&r
8844976
not $no_parens and $tok->type ne $self->lexer->TOKEN_LEFT_PAREN
!ll&&!rl&&r
000
MC/DC100%2/2
not $no_parens and $tok->type ne $self->lexer->TOKEN_LEFT_PAREN
not $no_parens $tok->type ne $self->lexer->TOKEN_LEFT_PAREN
MC/DC0%0/2
not $no_parens and $tok->type ne $self->lexer->TOKEN_LEFT_PAREN
not $no_parens $tok->type ne $self->lexer->TOKEN_LEFT_PAREN
Truth table100%3/3
not(A) and B
A= not $no_parensB= $tok->type ne $self->lexer->TOKEN_LEFT_PAREN
ABresult
0X0
100
111
Truth table0%0/3
not(A) and B
A= not $no_parensB= $tok->type ne $self->lexer->TOKEN_LEFT_PAREN
ABresult
0X0
100
111
1263 0 ▶ if ($tolerant) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tolerant) { } 76 0 76
if ($tolerant) { } 0 0 0
1264 0 return undef;
1265 }
1266 else {
1267 0 $self->fail( 'expected arguments', $tok->lineno, $tok->colno );
1268 }
1269 }
1270  
1271 0 ▶ if ( $tok->type eq $self->lexer->TOKEN_LEFT_PAREN ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tok->type eq $self->lexer->TOKEN_LEFT_PAREN) 8449 8 8457
if ($tok->type eq $self->lexer->TOKEN_LEFT_PAREN) 0 0 0
1272 0 $tok = $self->next_token;
1273 }
1274  
1275 0 my $args = $self->node('NodeList')->new( $tok->lineno, $tok->colno );
1276 0 my $kwargs = $self->node('KeywordArgs')->new( $tok->lineno, $tok->colno );
1277 0 my $check_comma = 0;
1278  
1279 0 while (1) {
1280 0 $tok = $self->peek_token;
1281 0 ▶ if ( !$no_parens && $tok->type eq $self->lexer->TOKEN_RIGHT_PAREN ) {
Branch: 4 branches
BranchTrueFalseTotal
if (not $no_parens and $tok->type eq $self->lexer->TOKEN_RIGHT_PAREN) { } 8446 9544 17990
elsif ($no_parens and $tok->type eq $self->lexer->TOKEN_BLOCK_END) { } 8 19068 19076
if (not $no_parens and $tok->type eq $self->lexer->TOKEN_RIGHT_PAREN) { } 0 0 0
elsif ($no_parens and $tok->type eq $self->lexer->TOKEN_BLOCK_END) { } 0 0 0
Condition50%3/6
not $no_parens and $tok->type eq $self->lexer->TOKEN_RIGHT_PAREN
!ll&&!rl&&r
1295328446
not $no_parens and $tok->type eq $self->lexer->TOKEN_RIGHT_PAREN
!ll&&!rl&&r
000
MC/DC100%2/2
not $no_parens and $tok->type eq $self->lexer->TOKEN_RIGHT_PAREN
not $no_parens $tok->type eq $self->lexer->TOKEN_RIGHT_PAREN
MC/DC0%0/2
not $no_parens and $tok->type eq $self->lexer->TOKEN_RIGHT_PAREN
not $no_parens $tok->type eq $self->lexer->TOKEN_RIGHT_PAREN
Truth table100%3/3
not(A) and B
A= not $no_parensB= $tok->type eq $self->lexer->TOKEN_RIGHT_PAREN
ABresult
0X0
100
111
Truth table0%0/3
not(A) and B
A= not $no_parensB= $tok->type eq $self->lexer->TOKEN_RIGHT_PAREN
ABresult
0X0
100
111
1282 0 $self->next_token;
1283 0 last;
1284 }
1285 ▶ elsif ( $no_parens && $tok->type eq $self->lexer->TOKEN_BLOCK_END ) {
Condition50%3/6
$no_parens and $tok->type eq $self->lexer->TOKEN_BLOCK_END
!ll&&!rl&&r
953248
$no_parens and $tok->type eq $self->lexer->TOKEN_BLOCK_END
!ll&&!rl&&r
000
MC/DC100%2/2
$no_parens and $tok->type eq $self->lexer->TOKEN_BLOCK_END
$no_parens $tok->type eq $self->lexer->TOKEN_BLOCK_END
MC/DC0%0/2
$no_parens and $tok->type eq $self->lexer->TOKEN_BLOCK_END
$no_parens $tok->type eq $self->lexer->TOKEN_BLOCK_END
Truth table100%3/3
A and B
A= $no_parensB= $tok->type eq $self->lexer->TOKEN_BLOCK_END
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $no_parensB= $tok->type eq $self->lexer->TOKEN_BLOCK_END
ABresult
0X0
100
111
1286 0 last;
1287 }
1288  
1289 0 ▶ if ( $check_comma && !$self->skip( $self->lexer->TOKEN_COMMA ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($check_comma and not $self->skip($self->lexer->TOKEN_COMMA)) { } 3 9533 9536
if ($check_comma and not $self->skip($self->lexer->TOKEN_COMMA)) { } 0 0 0
Condition50%3/6
$check_comma and not $self->skip($self->lexer->TOKEN_COMMA)
!ll&&!rl&&r
640931243
$check_comma and not $self->skip($self->lexer->TOKEN_COMMA)
!ll&&!rl&&r
000
MC/DC100%2/2
$check_comma and not $self->skip($self->lexer->TOKEN_COMMA)
$check_comma not $self->skip($self->lexer->TOKEN_COMMA)
MC/DC0%0/2
$check_comma and not $self->skip($self->lexer->TOKEN_COMMA)
$check_comma not $self->skip($self->lexer->TOKEN_COMMA)
Truth table100%3/3
A and not(B)
A= $check_commaB= not $self->skip($self->lexer->TOKEN_COMMA)
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= $check_commaB= not $self->skip($self->lexer->TOKEN_COMMA)
ABresult
0X0
100
111
1290 0 $self->fail( 'parseSignature: expected comma after expression',
1291 $tok->lineno, $tok->colno );
1292 }
1293 else {
1294 0 my $arg = $self->parse_expression;
1295  
1296 0 ▶ if ( $self->skip_value( $self->lexer->TOKEN_OPERATOR, '=' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->skip_value($self->lexer->TOKEN_OPERATOR, '=')) { } 1166 8367 9533
if ($self->skip_value($self->lexer->TOKEN_OPERATOR, '=')) { } 0 0 0
1297 0 $kwargs->add_child(
1298 $self->node('Pair')->new( $arg->lineno, $arg->colno, $arg, $self->parse_expression )
1299 );
1300 }
1301 else {
1302 0 $args->add_child($arg);
1303 }
1304 }
1305  
1306 0 $check_comma = 1;
1307 }
1308  
1309 0 ▶ if ( @{ $kwargs->children } ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@{$kwargs->children;}) 884 7570 8454
if (@{$kwargs->children;}) 0 0 0
1310 0 $args->add_child($kwargs);
1311 }
1312  
1313 0 return $args;
1314 }
1315  
1316 6430 ▶sub parse_until_blocks {
Subroutine parse_until_blocks: called CC=1 SCAR=1.2
Pod undocumented
1317 0 ▶ my ( $self, @block_names ) = @_;
Subroutine parse_until_blocks: not called CC=1 SCAR=1.2
Pod undocumented
1318 0 my $prev = $self->breakOnBlocks;
1319 0 $self->breakOnBlocks( \@block_names );
1320  
1321 0 my $ret = $self->parse;
1322  
1323 0 $self->breakOnBlocks($prev);
1324 0 return $ret;
1325 }
1326  
1327 16048 ▶sub parse_nodes {
Subroutine parse_nodes: called CC=17 SCAR=40.7
Pod undocumented
1328 0 ▶ my ($self) = @_;
Subroutine parse_nodes: not called CC=17 SCAR=40.7
Pod undocumented
1329 0 my $tok;
1330 my @buf;
1331  
1332 0 ▶ while ( $tok = $self->next_token ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tok = $self->next_token) 47115 9583 56698
if ($tok = $self->next_token) 0 0 0
1333 0 ▶ if ( $tok->type eq $self->lexer->TOKEN_DATA ) {
Branch: 8 branches
BranchTrueFalseTotal
if ($tok->type eq $self->lexer->TOKEN_DATA) { } 14668 32447 47115
elsif ($tok->type eq $self->lexer->TOKEN_BLOCK_START) { } 20022 12425 32447
elsif ($tok->type eq $self->lexer->TOKEN_VARIABLE_START) { } 12408 17 12425
elsif ($tok->type eq $self->lexer->TOKEN_COMMENT) { } 17 0 17
if ($tok->type eq $self->lexer->TOKEN_DATA) { } 0 0 0
elsif ($tok->type eq $self->lexer->TOKEN_BLOCK_START) { } 0 0 0
elsif ($tok->type eq $self->lexer->TOKEN_VARIABLE_START) { } 0 0 0
elsif ($tok->type eq $self->lexer->TOKEN_COMMENT) { } 0 0 0
1334 0 my $data = $tok->value;
1335 0 my $next_token = $self->peek_token;
1336 0 ▶ my $next_val = $next_token && $next_token->value;
Condition33%2/6
$next_token && $next_token->value
!ll&&!rl&&r
3674010994
$next_token && $next_token->value
!ll&&!rl&&r
000
MC/DC50%1/2
$next_token && $next_token->value
$next_token $next_token->value
MC/DC0%0/2
$next_token && $next_token->value
$next_token $next_token->value
Truth table66%2/3
A && B
A= $next_tokenB= $next_token->value
ABresult
0X0
100
111
Truth table0%0/3
A && B
A= $next_tokenB= $next_token->value
ABresult
0X0
100
111
1337  
1338 # If the last token has "-" we need to trim the
1339 # leading whitespace of the data. This is marked with
1340 # the `dropLeadingWhitespace` variable.
1341 0 ▶ if ( $self->dropLeadingWhitespace ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->dropLeadingWhitespace) 15 14653 14668
if ($self->dropLeadingWhitespace) 0 0 0
1342 # TODO: this could be optimized (don't use regex). JS \s -> the
1343 # ECMAScript whitespace class (ADR 0005); ^ is start of string here.
1344 0 my $ws = $self->lib->js_whitespace_class;
1345 0 $data =~ s/^${ws}*//;
1346 0 $self->dropLeadingWhitespace(0);
1347 }
1348  
1349 # Same for the succeeding block start token
1350 0 ▶ if (
Branch: 2 branches
BranchTrueFalseTotal
if ($next_token and $next_token->type eq $self->lexer->TOKEN_BLOCK_START && $self->_char_at($next_val, length($next_val) - 1) eq "-" || $next_token->type eq $self->lexer->TOKEN_VARIABLE_START && $self->_char_at($next_val, length $self->tokens->tags->{"VARIABLE_START"}) eq "-" || $next_token->type eq $self->lexer->TOKEN_COMMENT && $self->_char_at($next_val, length $self->tokens->tags->{"COMMENT_START"}) eq "-") 16 14652 14668
if ($next_token and $next_token->type eq $self->lexer->TOKEN_BLOCK_START && $self->_char_at($next_val, length($next_val) - 1) eq "-" || $next_token->type eq $self->lexer->TOKEN_VARIABLE_START && $self->_char_at($next_val, length $self->tokens->tags->{"VARIABLE_START"}) eq "-" || $next_token->type eq $self->lexer->TOKEN_COMMENT && $self->_char_at($next_val, length $self->tokens->tags->{"COMMENT_START"}) eq "-") 0 0 0
Condition50%18/36
$next_token and $next_token->type eq $self->lexer->TOKEN_BLOCK_START && $self->_char_at($next_val, length($next_val) - 1) eq "-" || $next_token->type eq $self->lexer->TOKEN_VARIABLE_START && $self->_char_at($next_val, length $self->tokens->tags->{"VARIABLE_START"}) eq "-" || $next_token->type eq $self->lexer->TOKEN_COMMENT && $self->_char_at($next_val, length $self->tokens->tags->{"COMMENT_START"}) eq "-"
!ll&&!rl&&r
36741097816
$next_token->type eq $self->lexer->TOKEN_BLOCK_START and $self->_char_at($next_val, length($next_val) - 1) eq "-" or $next_token->type eq $self->lexer->TOKEN_VARIABLE_START and $self->_char_at($next_val, length $self->tokens->tags->{"VARIABLE_START"}) eq "-" or $next_token->type eq $self->lexer->TOKEN_COMMENT and $self->_char_at($next_val, length $self->tokens->tags->{"COMMENT_START"}) eq "-"
l!l&&r!l&&!r
13310978
$next_token->type eq $self->lexer->TOKEN_BLOCK_START and $self->_char_at($next_val, length($next_val) - 1) eq "-" or $next_token->type eq $self->lexer->TOKEN_VARIABLE_START and $self->_char_at($next_val, length $self->tokens->tags->{"VARIABLE_START"}) eq "-"
l!l&&r!l&&!r
10310981
$next_token->type eq $self->lexer->TOKEN_BLOCK_START and $self->_char_at($next_val, length($next_val) - 1) eq "-"
!ll&&!rl&&r
7316366810
$next_token->type eq $self->lexer->TOKEN_VARIABLE_START and $self->_char_at($next_val, length $self->tokens->tags->{"VARIABLE_START"}) eq "-"
!ll&&!rl&&r
367673053
$next_token->type eq $self->lexer->TOKEN_COMMENT and $self->_char_at($next_val, length $self->tokens->tags->{"COMMENT_START"}) eq "-"
!ll&&!rl&&r
1097353
$next_token and $next_token->type eq $self->lexer->TOKEN_BLOCK_START && $self->_char_at($next_val, length($next_val) - 1) eq "-" || $next_token->type eq $self->lexer->TOKEN_VARIABLE_START && $self->_char_at($next_val, length $self->tokens->tags->{"VARIABLE_START"}) eq "-" || $next_token->type eq $self->lexer->TOKEN_COMMENT && $self->_char_at($next_val, length $self->tokens->tags->{"COMMENT_START"}) eq "-"
!ll&&!rl&&r
000
$next_token->type eq $self->lexer->TOKEN_BLOCK_START and $self->_char_at($next_val, length($next_val) - 1) eq "-" or $next_token->type eq $self->lexer->TOKEN_VARIABLE_START and $self->_char_at($next_val, length $self->tokens->tags->{"VARIABLE_START"}) eq "-" or $next_token->type eq $self->lexer->TOKEN_COMMENT and $self->_char_at($next_val, length $self->tokens->tags->{"COMMENT_START"}) eq "-"
l!l&&r!l&&!r
000
$next_token->type eq $self->lexer->TOKEN_BLOCK_START and $self->_char_at($next_val, length($next_val) - 1) eq "-" or $next_token->type eq $self->lexer->TOKEN_VARIABLE_START and $self->_char_at($next_val, length $self->tokens->tags->{"VARIABLE_START"}) eq "-"
l!l&&r!l&&!r
000
$next_token->type eq $self->lexer->TOKEN_BLOCK_START and $self->_char_at($next_val, length($next_val) - 1) eq "-"
!ll&&!rl&&r
000
$next_token->type eq $self->lexer->TOKEN_VARIABLE_START and $self->_char_at($next_val, length $self->tokens->tags->{"VARIABLE_START"}) eq "-"
!ll&&!rl&&r
000
$next_token->type eq $self->lexer->TOKEN_COMMENT and $self->_char_at($next_val, length $self->tokens->tags->{"COMMENT_START"}) eq "-"
!ll&&!rl&&r
000
MC/DC85%6/7
$next_token and $next_token->type eq $self->lexer->TOKEN_BLOCK_START && $self->_char_at($next_val, length($next_val) - 1) eq "-" || $next_token->type eq $self->lexer->TOKEN_VARIABLE_START && $self->_char_at($next_val, length $self->tokens->tags->{"VARIABLE_START"}) eq "-" || $next_token->type eq $self->lexer->TOKEN_COMMENT && $self->_char_at($next_val, length $self->tokens->tags->{"COMMENT_START"}) eq "-"
$next_token $next_token->type eq $self->lexer->TOKEN_BLOCK_START $self->_char_at($next_val, length($next_val) - 1) eq "-" $next_token->type eq $self->lexer->TOKEN_VARIABLE_START $self->_char_at($next_val, length $self->tokens->tags->{"VARIABLE_START"}) eq "-" $next_token->type eq $self->lexer->TOKEN_COMMENT $self->_char_at($next_val, length $self->tokens->tags->{"COMMENT_START"}) eq "-"
MC/DC0%0/7
$next_token and $next_token->type eq $self->lexer->TOKEN_BLOCK_START && $self->_char_at($next_val, length($next_val) - 1) eq "-" || $next_token->type eq $self->lexer->TOKEN_VARIABLE_START && $self->_char_at($next_val, length $self->tokens->tags->{"VARIABLE_START"}) eq "-" || $next_token->type eq $self->lexer->TOKEN_COMMENT && $self->_char_at($next_val, length $self->tokens->tags->{"COMMENT_START"}) eq "-"
$next_token $next_token->type eq $self->lexer->TOKEN_BLOCK_START $self->_char_at($next_val, length($next_val) - 1) eq "-" $next_token->type eq $self->lexer->TOKEN_VARIABLE_START $self->_char_at($next_val, length $self->tokens->tags->{"VARIABLE_START"}) eq "-" $next_token->type eq $self->lexer->TOKEN_COMMENT $self->_char_at($next_val, length $self->tokens->tags->{"COMMENT_START"}) eq "-"
Truth table43%7/16
A and B and C or D and E or F and G
A= $next_tokenB= $next_token->type eq $self->lexer->TOKEN_BLOCK_STARTC= $self->_char_at($next_val, length($next_val) - 1) eq "-"D= $next_token->type eq $self->lexer->TOKEN_VARIABLE_STARTE= $self->_char_at($next_val, length $self->tokens->tags->{"VARIABLE_START"}) eq "-"F= $next_token->type eq $self->lexer->TOKEN_COMMENTG= $self->_char_at($next_val, length $self->tokens->tags->{"COMMENT_START"}) eq "-"
ABCDEFGresult
0XXXXXX0
10X0X0X0
10X0X100
10X100X0
10X10100
1100X0X0
1100X100
110100X0
11010100
111XXXX1
10X11XX1
11011XX1
10X0X111
10X10111
1100X111
11010111
Truth table0%0/16
A and B and C or D and E or F and G
A= $next_tokenB= $next_token->type eq $self->lexer->TOKEN_BLOCK_STARTC= $self->_char_at($next_val, length($next_val) - 1) eq "-"D= $next_token->type eq $self->lexer->TOKEN_VARIABLE_STARTE= $self->_char_at($next_val, length $self->tokens->tags->{"VARIABLE_START"}) eq "-"F= $next_token->type eq $self->lexer->TOKEN_COMMENTG= $self->_char_at($next_val, length $self->tokens->tags->{"COMMENT_START"}) eq "-"
ABCDEFGresult
0XXXXXX0
10X0X0X0
10X0X100
10X100X0
10X10100
1100X0X0
1100X100
110100X0
11010100
111XXXX1
10X11XX1
11011XX1
10X0X111
10X10111
1100X111
11010111
1351 $next_token
1352 && ( ( $next_token->type eq $self->lexer->TOKEN_BLOCK_START
1353 && $self->_char_at( $next_val, length($next_val) - 1 ) eq '-' )
1354 || ( $next_token->type eq $self->lexer->TOKEN_VARIABLE_START
1355 && $self->_char_at( $next_val, length( $self->tokens->tags->{VARIABLE_START} ) ) eq '-' )
1356 || ( $next_token->type eq $self->lexer->TOKEN_COMMENT
1357 && $self->_char_at( $next_val, length( $self->tokens->tags->{COMMENT_START} ) ) eq '-' ) )
1358 )
1359 {
1360 # TODO: this could be optimized (don't use regex). JS \s -> the
1361 # ECMAScript whitespace class (ADR 0005); $ is end of string here.
1362 0 my $ws = $self->lib->js_whitespace_class;
1363 0 $data =~ s/${ws}*$//;
1364 }
1365  
1366 0 push @buf,
1367 $self->node('Output')->new(
1368 $tok->lineno, $tok->colno,
1369 [ $self->node('TemplateData')->new( $tok->lineno, $tok->colno, $data ) ]
1370 );
1371 }
1372 elsif ( $tok->type eq $self->lexer->TOKEN_BLOCK_START ) {
1373 0 $self->dropLeadingWhitespace(0);
1374 0 my $n = $self->parse_statement;
1375 0 ▶ if ( !$n ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($n) 6426 13566 19992
unless ($n) 0 0 0
1376 0 last;
1377 }
1378 0 push @buf, $n;
1379 }
1380 elsif ( $tok->type eq $self->lexer->TOKEN_VARIABLE_START ) {
1381 0 my $e = $self->parse_expression;
1382 0 $self->dropLeadingWhitespace(0);
1383 0 $self->advance_after_variable_end;
1384 0 push @buf, $self->node('Output')->new( $tok->lineno, $tok->colno, [$e] );
1385 }
1386 elsif ( $tok->type eq $self->lexer->TOKEN_COMMENT ) {
1387 $self->dropLeadingWhitespace(
1388 $self->_char_at(
1389 $tok->value,
1390 0 ▶ length( $tok->value ) - length( $self->tokens->tags->{COMMENT_END} ) - 1
Branch: 2 branches
BranchTrueFalseTotal
$self->_char_at($tok->value, length($tok->value) - length($self->tokens->tags->{'COMMENT_END'}) - 1) eq '-' ? : 3 14 17
$self->_char_at($tok->value, length($tok->value) - length($self->tokens->tags->{'COMMENT_END'}) - 1) eq '-' ? : 0 0 0
1391 ) eq '-' ? 1 : 0
1392 );
1393 }
1394 else {
1395 # Ignore comments, otherwise this should be an error
1396 0 $self->fail( 'Unexpected token at top-level: ' . $tok->type,
1397 $tok->lineno, $tok->colno );
1398 }
1399 }
1400  
1401 0 return \@buf;
1402 }
1403  
1404 6430 ▶sub parse {
Subroutine parse: called CC=1 SCAR=1.2
Pod undocumented
1405 0 ▶ my ($self) = @_;
Subroutine parse: not called CC=1 SCAR=1.2
Pod undocumented
1406 0 return $self->node('NodeList')->new( 0, 0, $self->parse_nodes );
1407 }
1408  
1409 9618 ▶sub parse_as_root {
Subroutine parse_as_root: called CC=1 SCAR=1.2
Pod undocumented
1410 0 ▶ my ($self) = @_;
Subroutine parse_as_root: not called CC=1 SCAR=1.2
Pod undocumented
1411 0 return $self->node('Root')->new( 0, 0, $self->parse_nodes );
1412 }
1413  
1414 19 1;
1415  
1416 __END__
« blib/lib/Text/Nunjucks/Nodes.pm ↑ Summary blib/lib/Text/Nunjucks/Runtime/Regex.pm »