blib/lib/JavaScript/Beautifier.pm

filter: Statementstmt 97.7% 469 / 480 Branchbran 93.7% 287 / 306 Conditioncond 88.8% 224 / 252 MC/DCmcdc 72.1% 96 / 133 Subroutinesub 100% 17 / 17 Podpod 7.6% 1 / 13 totaltotal 91.0% 1094 / 1201 SCAR 55.3
CC
242
Cov
94%
js_beautify
123.1
get_next_token
92.1
is_ternary_op
14.0
CRAP 252.2
↑ Summary Build »
1 package JavaScript::Beautifier;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '0.20';
7 2 our $AUTHORITY = 'cpan:FAYLAND';
8  
9 2 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use vars qw/@EXPORT_OK/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 @EXPORT_OK = qw/js_beautify/;
12  
13 2 my ( @input, @output, @modes );
14 2 my ( $token_text, $last_type, $last_text, $last_last_text, $last_word, $current_mode, $indent_string, $parser_pos, $in_case, $prefix, $token_type, $do_block_just_closed, $var_line, $var_line_tainted, $if_line_flag, $wanted_newline, $just_added_newline );
15  
16 2 my @whitespace = split('', "\n\r\t ");
17 2 my @wordchar = split('', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$');
18 2 my @digits = split('', '0123456789');
19 # <!-- is a special case (ok, it's a minor hack actually)
20 2 my @punct = split(' ', '+ - * / % & ++ -- = += -= *= /= %= == === != !== > < >= <= >> << >>> >>>= >>= <<= && &= | || ! !! , : ? ^ ^= |= ::');
21 # words which should always start on new line.
22 2 my @line_starter = split(',', 'continue,try,throw,return,var,if,switch,case,default,for,while,break,function');
23  
24 2 my ( $opt_indent_level, $opt_indent_size, $opt_indent_character, $opt_preserve_newlines, $opt_space_after_anon_function );
25  
26 sub js_beautify {
27 278 ▶ my ( $js_source_code, $opts ) = @_;
Subroutine js_beautify: called CC=122 SCAR=48.1
Pod documented
28  
29 278 ▶ $opt_indent_size = $opts->{indent_size} || 4;
Condition50%1/2
$opts->{'indent_size'} || 4
l!l
2780
MC/DC0%0/1
$opts->{'indent_size'} || 4
$opts->{'indent_size'}
Truth table50%1/2
A
A= $opts->{'indent_size'}
Aresult
11
00
30 278 ▶ $opt_indent_character = $opts->{indent_character} || ' ';
Condition50%1/2
$opts->{'indent_character'} || ' '
l!l
2780
MC/DC0%0/1
$opts->{'indent_character'} || ' '
$opts->{'indent_character'}
Truth table50%1/2
A
A= $opts->{'indent_character'}
Aresult
11
00
31 278 ▶ $opt_preserve_newlines = exists $opts->{preserve_newlines} ? $opts->{preserve_newlines} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'preserve_newlines'} ? : 278 0 278
32 278 ▶ $opt_indent_level = $opts->{indent_level} ||= 0;
Condition50%1/2
$opts->{"indent_level"} ||= 0
l!l
0278
MC/DC0%0/1
$opts->{"indent_level"} ||= 0
$opts->{"indent_level"}
Truth table50%1/2
A
A= $opts->{"indent_level"}
Aresult
11
00
33 278 ▶ $opt_space_after_anon_function = exists $opts->{space_after_anon_function} ? $opts->{space_after_anon_function} : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'space_after_anon_function'} ? : 278 0 278
34  
35 # -------------------------------------
36 278 $just_added_newline = 0;
37 278 $indent_string = '';
38 278 ▶ while ( $opt_indent_size-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt_indent_size--) 1103 278 1381
39 1103 $indent_string .= $opt_indent_character;
40 }
41 278 @input = split('', $js_source_code);
42  
43 278 $last_word = ''; # last 'TK_WORD' passed
44 278 $last_type = 'TK_START_EXPR'; # last token type
45 278 $last_text = ''; # last token text
46 278 $last_last_text = ''; # pre-last token text
47 278 @output = ();
48  
49 278 $do_block_just_closed = 0;
50 278 $var_line = 0;
51 278 $var_line_tainted = 0;
52  
53 # states showing if we are currently in expression (i.e. "if" case) - 'EXPRESSION', or in usual block (like, procedure), 'BLOCK'.
54 # some formatting depends on that.
55 278 $current_mode = 'BLOCK';
56 278 @modes = ( $current_mode );
57  
58 278 $parser_pos = 0; # parser position
59 278 $in_case = 0; # flag for parser that case/default has been processed, and next colon needs special attention
60 278 while ( 1 ) {
61 3427 my $t = get_next_token($parser_pos);
62 3427 $token_text = $t->[0];
63 3427 $token_type = $t->[1];
64 3427 ▶ if ( $token_type eq 'TK_EOF' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type eq "TK_EOF") 278 3149 3427
65 278 last;
66 }
67  
68 3149 ▶ if ( $token_type eq 'TK_START_EXPR' ) {
Branch: 11 branches
BranchTrueFalseTotal
if ($token_type eq 'TK_START_EXPR') { } 326 2823 3149
elsif ($token_type eq 'TK_END_EXPR') { } 315 2508 2823
elsif ($token_type eq 'TK_START_BLOCK') { } 253 2255 2508
elsif ($token_type eq 'TK_END_BLOCK') { } 251 2004 2255
elsif ($token_type eq 'TK_WORD') { } 1110 894 2004
elsif ($token_type eq 'TK_SEMICOLON') { } 288 606 894
elsif ($token_type eq 'TK_STRING') { } 84 522 606
elsif ($token_type eq 'TK_OPERATOR') { } 441 81 522
elsif ($token_type eq 'TK_BLOCK_COMMENT') { } 2 79 81
elsif ($token_type eq 'TK_COMMENT') { } 34 45 79
elsif ($token_type eq 'TK_UNKNOWN') { } 45 0 45
69 326 $var_line = 0;
70  
71 326 ▶ if ( $token_text eq '[' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_text eq '[') { } 76 250 326
72 76 ▶ if ( $last_type eq 'TK_WORD' || $last_text eq ')' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_type eq "TK_WORD" or $last_text eq ")") 24 52 76
Condition100%3/3
$last_type eq "TK_WORD" or $last_text eq ")"
l!l&&r!l&&!r
22252
MC/DC100%2/2
$last_type eq "TK_WORD" or $last_text eq ")"
$last_type eq "TK_WORD" $last_text eq ")"
Truth table100%3/3
A or B
A= $last_type eq "TK_WORD"B= $last_text eq ")"
ABresult
1X1
011
000
73 # this is array index specifier, break immediately
74 # a[x], fn()[x]
75 24 set_mode('(EXPRESSION)');
76 24 print_token();
77 24 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
78 }
79 52 ▶ if ( $current_mode eq '[EXPRESSION]' || $current_mode eq '[INDENTED-EXPRESSION]' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_mode eq '[EXPRESSION]' or $current_mode eq '[INDENTED-EXPRESSION]') { } 30 22 52
Condition100%3/3
$current_mode eq "[EXPRESSION]" or $current_mode eq "[INDENTED-EXPRESSION]"
l!l&&r!l&&!r
161422
MC/DC100%2/2
$current_mode eq "[EXPRESSION]" or $current_mode eq "[INDENTED-EXPRESSION]"
$current_mode eq "[EXPRESSION]" $current_mode eq "[INDENTED-EXPRESSION]"
Truth table100%3/3
A or B
A= $current_mode eq "[EXPRESSION]"B= $current_mode eq "[INDENTED-EXPRESSION]"
ABresult
1X1
011
000
80 30 ▶ if ( $last_last_text eq ']' && $last_text eq ',' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($last_last_text eq ']' and $last_text eq ',') { } 16 14 30
elsif ($last_text eq '[') { } 10 4 14
Condition66%2/3
$last_last_text eq "]" and $last_text eq ","
!ll&&!rl&&r
14016
MC/DC50%1/2
$last_last_text eq "]" and $last_text eq ","
$last_last_text eq "]" $last_text eq ","
Truth table66%2/3
A and B
A= $last_last_text eq "]"B= $last_text eq ","
ABresult
0X0
100
111
81 # ], [ goes to new line
82 16 indent();
83 16 print_newline();
84 16 set_mode('[INDENTED-EXPRESSION]');
85 } elsif ($last_text eq '[') {
86 10 indent();
87 10 print_newline();
88 10 set_mode('[INDENTED-EXPRESSION]');
89 } else {
90 4 set_mode('[EXPRESSION]');
91 }
92 } else {
93 22 set_mode('[EXPRESSION]');
94 }
95 } else {
96 250 set_mode('(EXPRESSION)');
97 }
98  
99 302 ▶ if ( $last_text eq ';' || $last_type eq 'TK_START_BLOCK' ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($last_text eq ';' or $last_type eq 'TK_START_BLOCK') { } 12 290 302
elsif ($last_type eq 'TK_END_EXPR' or $last_type eq 'TK_START_EXPR') { } 20 270 290
elsif ($last_type ne 'TK_WORD' and $last_type ne 'TK_OPERATOR') { } 6 264 270
elsif ($last_word eq 'function') { } 16 248 264
elsif (grep {$last_word eq $_;} @line_starter) { } 67 181 248
Condition100%3/3
$last_text eq ";" or $last_type eq "TK_START_BLOCK"
l!l&&r!l&&!r
210290
MC/DC100%2/2
$last_text eq ";" or $last_type eq "TK_START_BLOCK"
$last_text eq ";" $last_type eq "TK_START_BLOCK"
Truth table100%3/3
A or B
A= $last_text eq ";"B= $last_type eq "TK_START_BLOCK"
ABresult
1X1
011
000
100 12 print_newline();
101 ▶ } elsif ( $last_type eq 'TK_END_EXPR' || $last_type eq 'TK_START_EXPR' ) {
Condition100%3/3
$last_type eq "TK_END_EXPR" or $last_type eq "TK_START_EXPR"
l!l&&r!l&&!r
416270
MC/DC100%2/2
$last_type eq "TK_END_EXPR" or $last_type eq "TK_START_EXPR"
$last_type eq "TK_END_EXPR" $last_type eq "TK_START_EXPR"
Truth table100%3/3
A or B
A= $last_type eq "TK_END_EXPR"B= $last_type eq "TK_START_EXPR"
ABresult
1X1
011
000
102 # do nothing on (( and )( and ][ and ]( ..
103 ▶ } elsif ( $last_type ne 'TK_WORD' && $last_type ne 'TK_OPERATOR' ) {
Condition100%3/3
$last_type ne "TK_WORD" and $last_type ne "TK_OPERATOR"
!ll&&!rl&&r
224406
MC/DC100%2/2
$last_type ne "TK_WORD" and $last_type ne "TK_OPERATOR"
$last_type ne "TK_WORD" $last_type ne "TK_OPERATOR"
Truth table100%3/3
A and B
A= $last_type ne "TK_WORD"B= $last_type ne "TK_OPERATOR"
ABresult
0X0
100
111
104 6 print_space();
105 } elsif ( $last_word eq 'function' ) {
106 # function() vs function ()
107 16 ▶ if ( $opt_space_after_anon_function ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt_space_after_anon_function) 8 8 16
108 8 print_space();
109 }
110 3224 } elsif ( grep { $last_word eq $_ } @line_starter ) {
111 67 print_space();
112 }
113 302 print_token();
114 302 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
115 } elsif ( $token_type eq 'TK_END_EXPR' ) {
116 315 ▶ if ( $token_text eq ']' && $current_mode eq '[INDENTED-EXPRESSION]' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_text eq "]" and $current_mode eq "[INDENTED-EXPRESSION]") 26 289 315
Condition100%3/3
$token_text eq "]" and $current_mode eq "[INDENTED-EXPRESSION]"
!ll&&!rl&&r
2395026
MC/DC100%2/2
$token_text eq "]" and $current_mode eq "[INDENTED-EXPRESSION]"
$token_text eq "]" $current_mode eq "[INDENTED-EXPRESSION]"
Truth table100%3/3
A and B
A= $token_text eq "]"B= $current_mode eq "[INDENTED-EXPRESSION]"
ABresult
0X0
100
111
117 26 unindent();
118 }
119 315 restore_mode();
120 315 print_token();
121 315 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
122 } elsif ( $token_type eq 'TK_START_BLOCK' ) {
123 253 ▶ if ( $last_word eq 'do' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_word eq 'do') { } 10 243 253
124 10 set_mode('DO_BLOCK');
125 } else {
126 243 set_mode('BLOCK');
127 }
128 253 ▶ if ( $last_type ne 'TK_OPERATOR' && $last_type ne 'TK_START_EXPR' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_type ne "TK_OPERATOR" and $last_type ne "TK_START_EXPR") 86 167 253
Condition100%3/3
$last_type ne "TK_OPERATOR" and $last_type ne "TK_START_EXPR"
!ll&&!rl&&r
1015786
MC/DC100%2/2
$last_type ne "TK_OPERATOR" and $last_type ne "TK_START_EXPR"
$last_type ne "TK_OPERATOR" $last_type ne "TK_START_EXPR"
Truth table100%3/3
A and B
A= $last_type ne "TK_OPERATOR"B= $last_type ne "TK_START_EXPR"
ABresult
0X0
100
111
129 86 ▶ if ( $last_type eq 'TK_START_BLOCK' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_type eq 'TK_START_BLOCK') { } 19 67 86
130 19 print_newline();
131 } else {
132 67 print_space();
133 }
134 }
135 253 print_token();
136 253 indent();
137 253 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
138 } elsif ( $token_type eq 'TK_END_BLOCK' ) {
139 251 ▶ if ( $last_type eq 'TK_START_BLOCK' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_type eq 'TK_START_BLOCK') { } 22 229 251
140 # nothing
141 22 ▶ if ($just_added_newline) {
Branch: 1 branch
BranchTrueFalseTotal
if ($just_added_newline) { } 4 18 22
142 4 remove_indent();
143 # {
144 #
145 # }
146 } else {
147 # {}
148 18 trim_output();
149 }
150 22 unindent();
151 } else {
152 229 unindent();
153 229 print_newline();
154 }
155 251 print_token();
156 251 restore_mode();
157 251 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
158 } elsif ( $token_type eq 'TK_WORD' ) {
159 # no, it's not you. even I have problems understanding how this works
160 # and what does what.
161 1110 ▶ if ( $do_block_just_closed ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($do_block_just_closed) 10 1100 1110
162 10 print_space();
163 10 print_token();
164 10 print_space();
165 10 $do_block_just_closed = 0;
166 10 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
167 }
168 1100 ▶ if ( $token_text eq 'case' || $token_text eq 'default' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_text eq "case" or $token_text eq "default") 10 1090 1100
Condition100%3/3
$token_text eq "case" or $token_text eq "default"
l!l&&r!l&&!r
821090
MC/DC100%2/2
$token_text eq "case" or $token_text eq "default"
$token_text eq "case" $token_text eq "default"
Truth table100%3/3
A or B
A= $token_text eq "case"B= $token_text eq "default"
ABresult
1X1
011
000
169 10 ▶ if ( $last_text eq ':' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_text eq ':') { } 2 8 10
170 # switch cases following one another
171 2 remove_indent();
172 } else {
173 # case statement starts in the same line where switch
174 8 unindent();
175 8 print_newline();
176 8 indent();
177 }
178 10 print_token();
179 10 $in_case = 1;
180 10 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
181 }
182 1090 $prefix = 'NONE';
183 1090 ▶ if ( $last_type eq 'TK_END_BLOCK' ) {
Branch: 7 branches
BranchTrueFalseTotal
if ($last_type eq 'TK_END_BLOCK') { } 49 1041 1090
elsif ($last_type eq 'TK_SEMICOLON' and $current_mode eq 'BLOCK' || $current_mode eq 'DO_BLOCK') { } 48 993 1041
elsif ($last_type eq 'TK_SEMICOLON' and is_expression($current_mode)) { } 6 987 993
elsif ($last_type eq 'TK_STRING') { } 7 980 987
elsif ($last_type eq 'TK_WORD') { } 100 880 980
elsif ($last_type eq 'TK_START_BLOCK') { } 179 701 880
elsif ($last_type eq 'TK_END_EXPR') { } 67 634 701
184 49 ▶ if ( not (grep { lc($token_text) eq $_ } ('else', 'catch', 'finally')) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not grep({lc $token_text eq $_;} 'else', 'catch', 'finally')) { } 37 12 49
185 37 $prefix = 'NEWLINE';
186 } else {
187 12 $prefix = 'SPACE';
188 12 print_space();
189 }
190 ▶ } elsif ( $last_type eq 'TK_SEMICOLON' && ( $current_mode eq 'BLOCK' || $current_mode eq 'DO_BLOCK' ) ) {
Condition83%5/6
$last_type eq "TK_SEMICOLON" and $current_mode eq "BLOCK" || $current_mode eq "DO_BLOCK"
!ll&&!rl&&r
987648
$current_mode eq "BLOCK" or $current_mode eq "DO_BLOCK"
l!l&&r!l&&!r
4806
MC/DC66%2/3
$last_type eq "TK_SEMICOLON" and $current_mode eq "BLOCK" || $current_mode eq "DO_BLOCK"
$last_type eq "TK_SEMICOLON" $current_mode eq "BLOCK" $current_mode eq "DO_BLOCK"
Truth table75%3/4
A and B or C
A= $last_type eq "TK_SEMICOLON"B= $current_mode eq "BLOCK"C= $current_mode eq "DO_BLOCK"
ABCresult
0XX0
1000
11X1
1011
191 48 $prefix = 'NEWLINE';
192 ▶ } elsif ( $last_type eq 'TK_SEMICOLON' && is_expression($current_mode) ) {
Condition66%2/3
$last_type eq "TK_SEMICOLON" and is_expression($current_mode)
!ll&&!rl&&r
98706
MC/DC50%1/2
$last_type eq "TK_SEMICOLON" and is_expression($current_mode)
$last_type eq "TK_SEMICOLON" is_expression($current_mode)
Truth table66%2/3
A and B
A= $last_type eq "TK_SEMICOLON"B= is_expression($current_mode)
ABresult
0X0
100
111
193 6 $prefix = 'SPACE';
194 } elsif ( $last_type eq 'TK_STRING') {
195 7 $prefix = 'NEWLINE';
196 } elsif ( $last_type eq 'TK_WORD' ) {
197 100 $prefix = 'SPACE';
198 } elsif ( $last_type eq 'TK_START_BLOCK') {
199 179 $prefix = 'NEWLINE';
200 } elsif ( $last_type eq 'TK_END_EXPR' ) {
201 67 print_space();
202 67 $prefix = 'NEWLINE';
203 }
204  
205 1090 ▶ if ( $last_type ne 'TK_END_BLOCK' && (grep { lc($token_text) eq $_ } ('else', 'catch', 'finally')) ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($last_type ne 'TK_END_BLOCK' and grep {lc $token_text eq $_;} 'else', 'catch', 'finally') { } 6 1084 1090
elsif (grep {$token_text eq $_;} @line_starter or $prefix eq 'NEWLINE') { } 420 664 1084
elsif ($prefix eq 'SPACE') { } 108 556 664
Condition100%3/3
$last_type ne "TK_END_BLOCK" and grep {lc $token_text eq $_;} "else", "catch", "finally"
!ll&&!rl&&r
4910356
MC/DC100%2/2
$last_type ne "TK_END_BLOCK" and grep {lc $token_text eq $_;} "else", "catch", "finally"
$last_type ne "TK_END_BLOCK" grep {lc $token_text eq $_;} "else", "catch", "finally"
Truth table100%3/3
A and B
A= $last_type ne "TK_END_BLOCK"B= grep {lc $token_text eq $_;} "else", "catch", "finally"
ABresult
0X0
100
111
206 6 print_newline();
207 14092 ▶ } elsif ( (grep { $token_text eq $_ } @line_starter) || $prefix eq 'NEWLINE' ) {
Condition100%3/3
grep {$token_text eq $_;} @line_starter or $prefix eq "NEWLINE"
l!l&&r!l&&!r
151269664
MC/DC100%2/2
grep {$token_text eq $_;} @line_starter or $prefix eq "NEWLINE"
grep {$token_text eq $_;} @line_starter $prefix eq "NEWLINE"
Truth table100%3/3
A or B
A= grep {$token_text eq $_;} @line_starterB= $prefix eq "NEWLINE"
ABresult
1X1
011
000
208 420 ▶ if ( $last_text eq 'else' ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($last_text eq 'else') { } 4 416 420
elsif ($last_type eq 'TK_START_EXPR' || $last_text eq '=' || $last_text eq ',' and $token_text eq 'function') { } 19 397 416
elsif ($last_text eq 'return' or $last_text eq 'throw') { } 0 397 397
elsif ($last_type ne 'TK_END_EXPR') { } 334 63 397
209 # no need to force newline on else break
210 4 print_space();
211 ▶ } elsif ( ( $last_type eq 'TK_START_EXPR' || $last_text eq '=' || $last_text eq ',' ) && $token_text eq 'function' ) {
Condition100%9/9
$last_type eq "TK_START_EXPR" || $last_text eq "=" || $last_text eq "," and $token_text eq "function"
!ll&&!rl&&r
3475019
$last_type eq "TK_START_EXPR" or $last_text eq "=" or $last_text eq ","
l!l&&r!l&&!r
654347
$last_type eq "TK_START_EXPR" or $last_text eq "="
l!l&&r!l&&!r
614351
MC/DC100%4/4
$last_type eq "TK_START_EXPR" || $last_text eq "=" || $last_text eq "," and $token_text eq "function"
$last_type eq "TK_START_EXPR" $last_text eq "=" $last_text eq "," $token_text eq "function"
Truth table71%5/7
A or B or C and D
A= $last_type eq "TK_START_EXPR"B= $last_text eq "="C= $last_text eq ","D= $token_text eq "function"
ABCDresult
000X0
1XX00
01X00
00100
1XX11
01X11
00111
212 # no need to force newline on 'function': (function
213 # DONOTHING
214 ▶ } elsif ( $last_text eq 'return' || $last_text eq 'throw' ) {
Condition33%1/3
$last_text eq "return" or $last_text eq "throw"
l!l&&r!l&&!r
00397
MC/DC0%0/2
$last_text eq "return" or $last_text eq "throw"
$last_text eq "return" $last_text eq "throw"
Truth table33%1/3
A or B
A= $last_text eq "return"B= $last_text eq "throw"
ABresult
1X1
011
000
215 # no newline between 'return nnn'
216 0 print_space();
217 } elsif ( $last_type ne 'TK_END_EXPR' ) {
218 334 ▶ if ( ($last_type ne 'TK_START_EXPR' || $token_text ne 'var') && $last_text ne ':' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_type ne "TK_START_EXPR" || $token_text ne "var" and $last_text ne ":") 307 27 334
Condition100%6/6
$last_type ne "TK_START_EXPR" || $token_text ne "var" and $last_text ne ":"
!ll&&!rl&&r
216307
$last_type ne "TK_START_EXPR" or $token_text ne "var"
l!l&&r!l&&!r
2842921
MC/DC100%3/3
$last_type ne "TK_START_EXPR" || $token_text ne "var" and $last_text ne ":"
$last_type ne "TK_START_EXPR" $token_text ne "var" $last_text ne ":"
Truth table80%4/5
A or B and C
A= $last_type ne "TK_START_EXPR"B= $token_text ne "var"C= $last_text ne ":"
ABCresult
00X0
1X00
0100
1X11
0111
219 # no need to force newline on 'var': for (var x = 0...)
220 307 ▶ if ( $token_text eq 'if' && $last_word eq 'else' && $last_text ne '{' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_text eq 'if' and $last_word eq 'else' and $last_text ne '{') { } 0 307 307
Condition83%5/6
$token_text eq "if" and $last_word eq "else" and $last_text ne "{"
!ll&&!rl&&r
30520
$token_text eq "if" and $last_word eq "else"
!ll&&!rl&&r
262432
MC/DC0%0/3
$token_text eq "if" and $last_word eq "else" and $last_text ne "{"
$token_text eq "if" $last_word eq "else" $last_text ne "{"
Truth table75%3/4
A and B and C
A= $token_text eq "if"B= $last_word eq "else"C= $last_text ne "{"
ABCresult
0XX0
10X0
1100
1111
221 # no newline for } else if {
222 0 print_space();
223 } else {
224 307 print_newline();
225 }
226 }
227 } else {
228 63 ▶ if ( (grep { $token_text eq $_ } @line_starter) && $last_text ne ')' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$token_text eq $_;} @line_starter and $last_text ne ")") 2 61 63
Condition100%3/3
grep {$token_text eq $_;} @line_starter and $last_text ne ")"
!ll&&!rl&&r
5922
MC/DC100%2/2
grep {$token_text eq $_;} @line_starter and $last_text ne ")"
grep {$token_text eq $_;} @line_starter $last_text ne ")"
Truth table100%3/3
A and B
A= grep {$token_text eq $_;} @line_starterB= $last_text ne ")"
ABresult
0X0
100
111
229 2 print_newline();
230 }
231 }
232 } elsif ( $prefix eq 'SPACE' ) {
233 108 print_space();
234 }
235 1090 print_token();
236 1090 $last_word = $token_text;
237 1090 ▶ if ( $token_text eq 'var' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_text eq "var") 34 1056 1090
238 34 $var_line = 1;
239 34 $var_line_tainted = 0;
240 }
241 1090 ▶ if ( $token_text eq 'if' || $token_text eq 'else' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_text eq "if" or $token_text eq "else") 65 1025 1090
Condition100%3/3
$token_text eq "if" or $token_text eq "else"
l!l&&r!l&&!r
51141025
MC/DC100%2/2
$token_text eq "if" or $token_text eq "else"
$token_text eq "if" $token_text eq "else"
Truth table100%3/3
A or B
A= $token_text eq "if"B= $token_text eq "else"
ABresult
1X1
011
000
242 65 $if_line_flag = 1;
243 }
244 1090 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
245 } elsif ( $token_type eq 'TK_SEMICOLON' ) {
246 288 print_token();
247 288 $var_line = 0;
248 288 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
249 } elsif ( $token_type eq 'TK_STRING' ) {
250 84 ▶ if ( $last_type eq 'TK_START_BLOCK' || $last_type eq 'TK_END_BLOCK' || $last_type eq 'TK_SEMICOLON' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($last_type eq 'TK_START_BLOCK' or $last_type eq 'TK_END_BLOCK' or $last_type eq 'TK_SEMICOLON') { } 10 74 84
elsif ($last_type eq 'TK_WORD') { } 0 74 74
Condition100%6/6
$last_type eq "TK_START_BLOCK" or $last_type eq "TK_END_BLOCK" or $last_type eq "TK_SEMICOLON"
l!l&&r!l&&!r
8274
$last_type eq "TK_START_BLOCK" or $last_type eq "TK_END_BLOCK"
l!l&&r!l&&!r
6276
MC/DC100%3/3
$last_type eq "TK_START_BLOCK" or $last_type eq "TK_END_BLOCK" or $last_type eq "TK_SEMICOLON"
$last_type eq "TK_START_BLOCK" $last_type eq "TK_END_BLOCK" $last_type eq "TK_SEMICOLON"
Truth table100%4/4
A or B or C
A= $last_type eq "TK_START_BLOCK"B= $last_type eq "TK_END_BLOCK"C= $last_type eq "TK_SEMICOLON"
ABCresult
1XX1
01X1
0011
0000
251 10 print_newline();
252 } elsif ( $last_type eq 'TK_WORD' ) {
253 0 print_space();
254 }
255 84 print_token();
256 84 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
257 } elsif ( $token_type eq 'TK_OPERATOR' ) {
258 441 my $start_delim = 1;
259 441 my $end_delim = 1;
260 441 ▶ if ( $var_line && $token_text ne ',' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var_line and $token_text ne ",") 52 389 441
Condition100%3/3
$var_line and $token_text ne ","
!ll&&!rl&&r
3612852
MC/DC100%2/2
$var_line and $token_text ne ","
$var_line $token_text ne ","
Truth table100%3/3
A and B
A= $var_lineB= $token_text ne ","
ABresult
0X0
100
111
261 52 $var_line_tainted = 1;
262 52 ▶ if ( $token_text eq ':' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_text eq ":") 2 50 52
263 2 $var_line = 0;
264 }
265 }
266 441 ▶ if ($var_line && $token_text eq ',' && is_expression($current_mode) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var_line and $token_text eq "," and is_expression($current_mode)) 10 431 441
Condition100%6/6
$var_line and $token_text eq "," and is_expression($current_mode)
!ll&&!rl&&r
4131810
$var_line and $token_text eq ","
!ll&&!rl&&r
3635028
MC/DC100%3/3
$var_line and $token_text eq "," and is_expression($current_mode)
$var_line $token_text eq "," is_expression($current_mode)
Truth table100%4/4
A and B and C
A= $var_lineB= $token_text eq ","C= is_expression($current_mode)
ABCresult
0XX0
10X0
1100
1111
267 # do not break on comma, for(var a = 1, b = 2)
268 10 $var_line_tainted = 0;
269 }
270 441 ▶ if ( $token_text eq ':' && $in_case ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_text eq ":" and $in_case) 10 431 441
Condition100%3/3
$token_text eq ":" and $in_case
!ll&&!rl&&r
3735810
MC/DC100%2/2
$token_text eq ":" and $in_case
$token_text eq ":" $in_case
Truth table100%3/3
A and B
A= $token_text eq ":"B= $in_case
ABresult
0X0
100
111
271 10 print_token(); # colon really asks for separate treatment
272 10 print_newline();
273 10 $in_case = 0;
274 10 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
275 }
276 431 ▶ if ( $token_text eq '::' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_text eq "::") 2 429 431
277 # no spaces around exotic namespacing syntax operator
278 2 print_token();
279 2 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
280 }
281  
282 429 ▶ if ( $token_text eq ',' ) {
Branch: 8 branches
BranchTrueFalseTotal
if ($token_text eq ',') { } 130 299 429
elsif ($token_text eq '--' or $token_text eq '++') { } 16 283 299
elsif ($token_text eq '!' || $token_text eq '+' || $token_text eq '-' and $last_text eq 'return' || $last_text eq 'case') { } 8 275 283
elsif ($token_text eq '!' || $token_text eq '+' || $token_text eq '-' and $last_type eq 'TK_START_EXPR') { } 6 269 275
elsif ($last_type eq 'TK_OPERATOR') { } 11 258 269
elsif ($last_type eq 'TK_END_EXPR') { } 8 250 258
elsif ($token_text eq '.') { } 0 250 250
elsif ($token_text eq ':') { } 56 194 250
283 130 ▶ if ($var_line) {
Branch: 2 branches
BranchTrueFalseTotal
if ($var_line) { } 28 102 130
elsif ($last_type eq 'TK_END_BLOCK') { } 4 98 102
284 28 ▶ if ( $var_line_tainted ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var_line_tainted) { } 6 22 28
285 6 print_token();
286 6 print_newline();
287 6 $var_line_tainted = 0;
288 } else {
289 22 print_token();
290 22 print_space();
291 }
292 } elsif ( $last_type eq 'TK_END_BLOCK' ) {
293 4 print_token();
294 4 print_newline();
295 } else {
296 98 ▶ if ( $current_mode eq 'BLOCK' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_mode eq 'BLOCK') { } 18 80 98
297 18 print_token();
298 18 print_newline();
299 } else {
300 # EXPR or DO_BLOCK
301 80 print_token();
302 80 print_space();
303 }
304 }
305 130 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
306 ▶ } elsif ( $token_text eq '--' || $token_text eq '++' ) { # unary operators special case
Condition100%3/3
$token_text eq "--" or $token_text eq "++"
l!l&&r!l&&!r
412283
MC/DC100%2/2
$token_text eq "--" or $token_text eq "++"
$token_text eq "--" $token_text eq "++"
Truth table100%3/3
A or B
A= $token_text eq "--"B= $token_text eq "++"
ABresult
1X1
011
000
307 16 ▶ if ( $last_text eq ';' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_text eq ';') { } 6 10 16
308 6 ▶ if ( $current_mode eq 'BLOCK') {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_mode eq 'BLOCK') { } 4 2 6
309 # { foo; --i }
310 4 print_newline();
311 4 $start_delim = 1;
312 4 $end_delim = 0;
313 } else {
314 # space for (;; ++i)
315 2 $start_delim = 1;
316 2 $end_delim = 0;
317 }
318 } else {
319 10 ▶ if ($last_text eq '{') {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_text eq "{") 4 6 10
320 # {--i
321 4 print_newline();
322 }
323 10 $start_delim = 0;
324 10 $end_delim = 0;
325 }
326 ▶ } elsif ( ( $token_text eq '!' || $token_text eq '+' || $token_text eq '-' ) && ($last_text eq 'return' || $last_text eq 'case') ) {
Condition100%12/12
$token_text eq "!" || $token_text eq "+" || $token_text eq "-" and $last_text eq "return" || $last_text eq "case"
!ll&&!rl&&r
257188
$token_text eq "!" or $token_text eq "+" or $token_text eq "-"
l!l&&r!l&&!r
1412257
$token_text eq "!" or $token_text eq "+"
l!l&&r!l&&!r
86269
$last_text eq "return" or $last_text eq "case"
l!l&&r!l&&!r
4418
MC/DC80%4/5
$token_text eq "!" || $token_text eq "+" || $token_text eq "-" and $last_text eq "return" || $last_text eq "case"
$token_text eq "!" $token_text eq "+" $token_text eq "-" $last_text eq "return" $last_text eq "case"
Truth table80%8/10
A or B or C and D or E
A= $token_text eq "!"B= $token_text eq "+"C= $token_text eq "-"D= $last_text eq "return"E= $last_text eq "case"
ABCDEresult
000XX0
1XX000
01X000
001000
1XX1X1
1XX011
01X1X1
01X011
0011X1
001011
327 8 $start_delim = 1;
328 8 $end_delim = 0;
329 ▶ } elsif ( ( $token_text eq '!' || $token_text eq '+' || $token_text eq '-' ) && $last_type eq 'TK_START_EXPR' ) {
Condition100%9/9
$token_text eq "!" || $token_text eq "+" || $token_text eq "-" and $last_type eq "TK_START_EXPR"
!ll&&!rl&&r
257126
$token_text eq "!" or $token_text eq "+" or $token_text eq "-"
l!l&&r!l&&!r
108257
$token_text eq "!" or $token_text eq "+"
l!l&&r!l&&!r
46265
MC/DC100%4/4
$token_text eq "!" || $token_text eq "+" || $token_text eq "-" and $last_type eq "TK_START_EXPR"
$token_text eq "!" $token_text eq "+" $token_text eq "-" $last_type eq "TK_START_EXPR"
Truth table100%7/7
A or B or C and D
A= $token_text eq "!"B= $token_text eq "+"C= $token_text eq "-"D= $last_type eq "TK_START_EXPR"
ABCDresult
000X0
1XX00
01X00
00100
1XX11
01X11
00111
330 # special case handling: if (!a)
331 6 $start_delim = 0;
332 6 $end_delim = 0;
333 } elsif ( $last_type eq 'TK_OPERATOR' ) {
334 11 $start_delim = 0;
335 11 $end_delim = 0;
336 } elsif ( $last_type eq 'TK_END_EXPR' ) {
337 8 $start_delim = 1;
338 8 $end_delim = 1;
339 } elsif ( $token_text eq '.' ) {
340 # decimal digits or object.property
341 0 $start_delim = 0;
342 0 $end_delim = 0;
343 } elsif ( $token_text eq ':' ) {
344 56 ▶ if (is_ternary_op()) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_ternary_op()) { } 18 38 56
345 18 $start_delim = 1;
346 } else {
347 38 $start_delim = 0;
348 }
349 }
350 299 ▶ if ( $start_delim ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start_delim) 234 65 299
351 234 print_space();
352 }
353 299 print_token();
354 299 ▶ if ( $end_delim ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($end_delim) 258 41 299
355 258 print_space();
356 }
357 299 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
358 } elsif ($token_type eq 'TK_BLOCK_COMMENT') {
359 2 print_newline();
360 2 print_token();
361 2 print_newline();
362 2 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
363 } elsif ($token_type eq 'TK_COMMENT') {
364 # print_newline();
365 34 print_space();
366 34 print_token();
367 34 print_newline();
368 34 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
369 } elsif ($token_type eq 'TK_UNKNOWN') {
370 45 print_token();
371 45 $last_last_text = $last_text;$last_type = $token_type;$last_text = $token_text;next;
372 }
373 0 $last_type = $token_type;
374 0 $last_text = $token_text;
375 }
376  
377 278 my $output = join('', @output);
378 278 $output =~ s/\n+$//;
379 278 return $output;
380 }
381  
382 sub trim_output {
383 981 ▶ while ( scalar @output && ( $output[ scalar @output - 1 ] eq ' ' || $output[ scalar @output - 1 ] eq $indent_string ) ) {
Subroutine trim_output: called CC=4 SCAR=13.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @output and $output[scalar @output - 1] eq " " || $output[scalar @output - 1] eq $indent_string) 205 981 1186
Condition100%6/6
scalar @output and $output[scalar @output - 1] eq " " || $output[scalar @output - 1] eq $indent_string
!ll&&!rl&&r
29952205
$output[scalar @output - 1] eq " " or $output[scalar @output - 1] eq $indent_string
l!l&&r!l&&!r
22183952
MC/DC100%3/3
scalar @output and $output[scalar @output - 1] eq " " || $output[scalar @output - 1] eq $indent_string
scalar @output $output[scalar @output - 1] eq " " $output[scalar @output - 1] eq $indent_string
Truth table100%4/4
A and B or C
A= scalar @outputB= $output[scalar @output - 1] eq " "C= $output[scalar @output - 1] eq $indent_string
ABCresult
0XX0
1000
11X1
1011
384 205 pop @output;
385 }
386 }
387 sub print_newline {
388 963 ▶ my ( $ignore_repeated ) = @_;
Subroutine print_newline: called CC=6 SCAR=17.9
Pod undocumented
389 963 ▶ $ignore_repeated = 1 unless defined $ignore_repeated;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ignore_repeated 943 20 963
390 963 $if_line_flag = 0;
391 963 trim_output();
392  
393 963 ▶ if ( not scalar @output ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @output) 29 934 963
394 29 return; # no newline on start of file
395 }
396  
397 934 ▶ if ( $output[ scalar @output - 1 ] ne "\n" || ! $ignore_repeated ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($output[scalar @output - 1] ne "\n" or not $ignore_repeated) 758 176 934
Condition100%3/3
$output[scalar @output - 1] ne "\n" or not $ignore_repeated
l!l&&r!l&&!r
74810176
MC/DC100%2/2
$output[scalar @output - 1] ne "\n" or not $ignore_repeated
$output[scalar @output - 1] ne "\n" not $ignore_repeated
Truth table100%3/3
A or not(B)
A= $output[scalar @output - 1] ne "\n"B= not $ignore_repeated
ABresult
1X1
011
000
398 758 $just_added_newline = 1;
399 758 push @output, "\n";
400 }
401 934 foreach my $i ( 0 .. $opt_indent_level - 1 ) {
402 788 push @output, $indent_string;
403 }
404 }
405  
406 sub print_space {
407 987 ▶ my $last_output = ' ';
Subroutine print_space: called CC=5 SCAR=16.1
Pod undocumented
408 987 ▶ $last_output = $output[ scalar @output - 1 ] if scalar @output;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @output 979 8 987
409 987 ▶ if ( $last_output ne ' ' && $last_output ne "\n" && $last_output ne $indent_string ) { # prevent occassional duplicate space
Branch: 1 branch
BranchTrueFalseTotal
if ($last_output ne " " and $last_output ne "\n" and $last_output ne $indent_string) 875 112 987
Condition100%6/6
$last_output ne " " and $last_output ne "\n" and $last_output ne $indent_string
!ll&&!rl&&r
3478875
$last_output ne " " and $last_output ne "\n"
!ll&&!rl&&r
2014953
MC/DC100%3/3
$last_output ne " " and $last_output ne "\n" and $last_output ne $indent_string
$last_output ne " " $last_output ne "\n" $last_output ne $indent_string
Truth table100%4/4
A and B and C
A= $last_output ne " "B= $last_output ne "\n"C= $last_output ne $indent_string
ABCresult
0XX0
10X0
1100
1111
410 875 push @output, ' ';
411 }
412 }
413  
414 sub print_token {
415 3149 ▶ $just_added_newline = 0;
Subroutine print_token: called CC=1 SCAR=0.0
Pod undocumented
416 3149 push @output, $token_text;
417 }
418 sub indent {
419 287 ▶ $opt_indent_level++;
Subroutine indent: called CC=1 SCAR=0.0
Pod undocumented
420 }
421 sub unindent {
422 285 ▶ if ( $opt_indent_level ) {
Subroutine unindent: called CC=2 SCAR=7.2
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if ($opt_indent_level) 285 0 285
423 285 $opt_indent_level--;
424 }
425 }
426 sub remove_indent {
427 6 ▶ if ( scalar @output && $output[ scalar @output - 1 ] eq $indent_string ) {
Subroutine remove_indent: called CC=3 SCAR=13.1
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @output and $output[scalar @output - 1] eq $indent_string) 6 0 6
Condition33%1/3
scalar @output and $output[scalar @output - 1] eq $indent_string
!ll&&!rl&&r
006
MC/DC0%0/2
scalar @output and $output[scalar @output - 1] eq $indent_string
scalar @output $output[scalar @output - 1] eq $indent_string
Truth table33%1/3
A and B
A= scalar @outputB= $output[scalar @output - 1] eq $indent_string
ABresult
0X0
100
111
428 6 pop @output;
429 }
430 }
431 sub set_mode {
432 579 ▶ my $mode = shift;
Subroutine set_mode: called CC=1 SCAR=0.0
Pod undocumented
433 579 push @modes, $current_mode;
434 579 $current_mode = $mode;
435 }
436 sub is_expression {
437 34 ▶ my $mode = shift;
Subroutine is_expression: called CC=4 SCAR=14.9
Pod undocumented
438 34 ▶ return ($mode eq '[EXPRESSION]' || $mode eq '[INDENTED-EXPRESSION]' || $mode eq '(EXPRESSION)') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$mode eq '[EXPRESSION]' || $mode eq '[INDENTED-EXPRESSION]' || $mode eq '(EXPRESSION)' ? : 16 18 34
Condition50%3/6
$mode eq "[EXPRESSION]" or $mode eq "[INDENTED-EXPRESSION]" or $mode eq "(EXPRESSION)"
l!l&&r!l&&!r
01618
$mode eq "[EXPRESSION]" or $mode eq "[INDENTED-EXPRESSION]"
l!l&&r!l&&!r
0034
MC/DC33%1/3
$mode eq "[EXPRESSION]" or $mode eq "[INDENTED-EXPRESSION]" or $mode eq "(EXPRESSION)"
$mode eq "[EXPRESSION]" $mode eq "[INDENTED-EXPRESSION]" $mode eq "(EXPRESSION)"
Truth table50%2/4
A or B or C
A= $mode eq "[EXPRESSION]"B= $mode eq "[INDENTED-EXPRESSION]"C= $mode eq "(EXPRESSION)"
ABCresult
1XX1
01X1
0011
0000
439 }
440 sub restore_mode {
441 566 ▶ $do_block_just_closed = ( $current_mode eq 'DO_BLOCK' ) ? 1 : 0;
Subroutine restore_mode: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$current_mode eq 'DO_BLOCK' ? : 10 556 566
442 566 $current_mode = pop @modes;
443 }
444  
445 # Walk backwards from the colon to find a '?' (colon is part of a ternary op)
446 # or a '{' (colon is part of a class literal). Along the way, keep track of
447 # the blocks and expressions we pass so we only trigger on those chars in our
448 # own level, and keep track of the colons so we only trigger on the matching '?'.
449 sub is_ternary_op {
450 56 ▶ my $level = 0;
Subroutine is_ternary_op: called CC=14 SCAR=26.4
Pod undocumented
451 56 my $colon_count = 0;
452 56 foreach my $o (reverse @output) {
453 574 ▶ if ( $o eq ':' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($o eq ':') { } 42 532 574
elsif ($o eq '?') { } 32 500 532
elsif ($o eq '{') { } 42 458 500
454 42 ▶ if ( $level == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level == 0) 34 8 42
455 34 $colon_count++;
456 }
457 42 next;
458 } elsif ( $o eq '?' ) {
459 32 ▶ if ( $level == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level == 0) 32 0 32
460 32 ▶ if ( $colon_count == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($colon_count == 0) { } 18 14 32
461 18 return 1;
462 } else {
463 14 $colon_count--;
464 }
465 }
466 14 next;
467 } elsif ( $o eq '{' ) {
468 42 ▶ if ( $level == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level == 0) 38 4 42
469 38 return 0;
470 }
471 4 $level--;
472 4 next;
473 }
474 458 ▶ if ( $o eq '(' or $o eq '[' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($o eq '(' or $o eq '[') { } 6 452 458
elsif ($o eq ')' or $o eq ']' or $o eq '}') { } 10 442 452
Condition66%2/3
$o eq "(" or $o eq "["
l!l&&r!l&&!r
06452
MC/DC50%1/2
$o eq "(" or $o eq "["
$o eq "(" $o eq "["
Truth table66%2/3
A or B
A= $o eq "("B= $o eq "["
ABresult
1X1
011
000
475 6 $level--;
476 6 next;
477 ▶ } elsif ( $o eq ')' or $o eq ']' or $o eq '}' ) {
Condition83%5/6
$o eq ")" or $o eq "]" or $o eq "}"
l!l&&r!l&&!r
64442
$o eq ")" or $o eq "]"
l!l&&r!l&&!r
06446
MC/DC66%2/3
$o eq ")" or $o eq "]" or $o eq "}"
$o eq ")" $o eq "]" $o eq "}"
Truth table75%3/4
A or B or C
A= $o eq ")"B= $o eq "]"C= $o eq "}"
ABCresult
1XX1
01X1
0011
0000
478 10 $level++;
479 10 next;
480 }
481 }
482 }
483  
484 sub get_next_token {
485 3437 ▶ my $n_newlines = 0;
Subroutine get_next_token: called CC=89 SCAR=45.2
Pod undocumented
486  
487 3437 ▶ if ( $parser_pos >= scalar @input ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser_pos >= scalar @input) 278 3159 3437
488 278 return ['', 'TK_EOF'];
489 }
490  
491 3159 my $c = $input[$parser_pos];
492 3159 $parser_pos++;
493  
494 3159 ▶ while ( grep { $_ eq $c } @whitespace ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq $c;} @whitespace) 818 3159 3977
495 818 ▶ if ( $parser_pos >= scalar @input ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser_pos >= scalar @input) 0 818 818
496 0 return ['', 'TK_EOF'];
497 }
498 818 ▶ if ( $c eq "\n" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "\n") 336 482 818
499 336 $n_newlines += 1;
500 }
501 818 $c = $input[$parser_pos];
502 818 $parser_pos++;
503 };
504 3159 $wanted_newline = 0;
505 3159 ▶ if ( $opt_preserve_newlines ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt_preserve_newlines) 3155 4 3159
506 3155 ▶ if ( $n_newlines > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n_newlines > 1) 10 3145 3155
507 10 foreach my $i ( 0 .. 1 ) {
508 20 ▶ my $flag = ( $i == 0 ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$i == 0 ? : 10 10 20
509 20 print_newline( $flag );
510 }
511 }
512 3155 ▶ $wanted_newline = ($n_newlines == 1) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$n_newlines == 1 ? : 315 2840 3155
513 }
514 3159 ▶ if ( grep { $c eq $_ } @wordchar ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$c eq $_;} @wordchar) 1118 2041 3159
515 1118 ▶ if ( $parser_pos < scalar @input ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser_pos < scalar @input) 1099 19 1118
516 1099 ▶ while ( grep { $input[$parser_pos] eq $_ } @wordchar ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$input[$parser_pos] eq $_;} @wordchar) 1760 1088 2848
517 1760 $c .= $input[$parser_pos];
518 1760 $parser_pos++;
519 1760 ▶ if ( $parser_pos == scalar @input ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser_pos == scalar @input) 11 1749 1760
520 11 last;
521 }
522 }
523 }
524  
525 # small and surprisingly unugly hack for 1E-10 representation
526 1118 ▶ if ( $parser_pos != scalar @input && $c =~ /^[0-9]+[Ee]$/ && ($input[$parser_pos] eq '-' || $input[$parser_pos] eq '+') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser_pos != scalar @input and $c =~ /^[0-9]+[Ee]$/ and $input[$parser_pos] eq "-" || $input[$parser_pos] eq "+") 10 1108 1118
Condition88%8/9
$parser_pos != scalar @input and $c =~ /^[0-9]+[Ee]$/ and $input[$parser_pos] eq "-" || $input[$parser_pos] eq "+"
!ll&&!rl&&r
110828
$parser_pos != scalar @input and $c =~ /^[0-9]+[Ee]$/
!ll&&!rl&&r
30107810
$input[$parser_pos] eq "-" or $input[$parser_pos] eq "+"
l!l&&r!l&&!r
820
MC/DC50%2/4
$parser_pos != scalar @input and $c =~ /^[0-9]+[Ee]$/ and $input[$parser_pos] eq "-" || $input[$parser_pos] eq "+"
$parser_pos != scalar @input $c =~ /^[0-9]+[Ee]$/ $input[$parser_pos] eq "-" $input[$parser_pos] eq "+"
Truth table60%3/5
A and B and C or D
A= $parser_pos != scalar @inputB= $c =~ /^[0-9]+[Ee]$/C= $input[$parser_pos] eq "-"D= $input[$parser_pos] eq "+"
ABCDresult
0XXX0
10XX0
11000
111X1
11011
527 10 my $sign = $input[$parser_pos];
528 10 $parser_pos++;
529 10 my $t = get_next_token($parser_pos);
530 10 $c .= $sign . $t->[0];
531 10 return [$c, 'TK_WORD'];
532 }
533 1108 ▶ if ( $c eq 'in' ) { # hack for 'in' operator
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "in") 4 1104 1108
534 4 return [$c, 'TK_OPERATOR'];
535 }
536 1104 ▶ if ( $wanted_newline && $last_type ne 'TK_OPERATOR' && not $if_line_flag ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wanted_newline and $last_type ne "TK_OPERATOR" and not $if_line_flag) 222 882 1104
Condition100%6/6
$wanted_newline and $last_type ne "TK_OPERATOR" and not $if_line_flag
!ll&&!rl&&r
84834222
$wanted_newline and $last_type ne "TK_OPERATOR"
!ll&&!rl&&r
8462256
MC/DC100%3/3
$wanted_newline and $last_type ne "TK_OPERATOR" and not $if_line_flag
$wanted_newline $last_type ne "TK_OPERATOR" not $if_line_flag
Truth table100%4/4
A and B and not(C)
A= $wanted_newlineB= $last_type ne "TK_OPERATOR"C= not $if_line_flag
ABCresult
0XX0
10X0
1100
1111
537 222 print_newline();
538 }
539 1104 return [$c, 'TK_WORD'];
540 }
541 2041 ▶ if ( $c eq '(' || $c eq '[' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "(" or $c eq "[") 326 1715 2041
Condition100%3/3
$c eq "(" or $c eq "["
l!l&&r!l&&!r
250761715
MC/DC100%2/2
$c eq "(" or $c eq "["
$c eq "(" $c eq "["
Truth table100%3/3
A or B
A= $c eq "("B= $c eq "["
ABresult
1X1
011
000
542 326 return [$c, 'TK_START_EXPR'];
543 }
544 1715 ▶ if ( $c eq ')' || $c eq ']' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq ")" or $c eq "]") 315 1400 1715
Condition100%3/3
$c eq ")" or $c eq "]"
l!l&&r!l&&!r
239761400
MC/DC100%2/2
$c eq ")" or $c eq "]"
$c eq ")" $c eq "]"
Truth table100%3/3
A or B
A= $c eq ")"B= $c eq "]"
ABresult
1X1
011
000
545 315 return [$c, 'TK_END_EXPR'];
546 }
547 1400 ▶ if ( $c eq '{' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "{") 253 1147 1400
548 253 return [$c, 'TK_START_BLOCK'];
549 }
550 1147 ▶ if ( $c eq '}' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "}") 251 896 1147
551 251 return [$c, 'TK_END_BLOCK'];
552 }
553 896 ▶ if ( $c eq ';' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq ";") 288 608 896
554 288 return [$c, 'TK_SEMICOLON'];
555 }
556 608 ▶ if ( $c eq '/' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "/") 49 559 608
557 49 my $comment;
558 # peek for comment /* ... */
559 49 ▶ if ( $input[$parser_pos] eq '*' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input[$parser_pos] eq "*") 2 47 49
560 2 $parser_pos++;
561 2 ▶ if ( $parser_pos < scalar @input ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser_pos < scalar @input) 2 0 2
562 2 ▶ while (not ( $input[$parser_pos] eq '*' && $input[$parser_pos+1] && $input[$parser_pos+1] eq '/') && $parser_pos < scalar @input ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $input[$parser_pos] eq "*" && $input[$parser_pos + 1] && $input[$parser_pos + 1] eq "/" and $parser_pos < scalar @input) 14 2 16
Condition66%6/9
not $input[$parser_pos] eq "*" && $input[$parser_pos + 1] && $input[$parser_pos + 1] eq "/" and $parser_pos < scalar @input
!ll&&!rl&&r
2014
$input[$parser_pos] eq '*' && $input[$parser_pos + 1] && $input[$parser_pos + 1] eq '/'
!ll&&!rl&&r
1402
$input[$parser_pos] eq "*" and $input[$parser_pos + 1]
!ll&&!rl&&r
1402
MC/DC25%1/4
not $input[$parser_pos] eq "*" && $input[$parser_pos + 1] && $input[$parser_pos + 1] eq "/" and $parser_pos < scalar @input
$input[$parser_pos] eq "*" $input[$parser_pos + 1] $input[$parser_pos + 1] eq '/' $parser_pos < scalar @input
Truth table28%2/7
not(A and B && C) and D
A= $input[$parser_pos] eq "*"B= $input[$parser_pos + 1]C= $input[$parser_pos + 1] eq '/'D= $parser_pos < scalar @input
ABCDresult
111X0
0XX00
10X00
11000
0XX11
10X11
11011
563 14 $comment .= $input[$parser_pos];
564 14 $parser_pos++;
565 14 ▶ if ( $parser_pos >= scalar @input ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser_pos >= scalar @input) 0 14 14
566 0 last;
567 }
568 }
569 }
570 2 $parser_pos += 2;
571 2 return ['/*' . $comment . '*/', 'TK_BLOCK_COMMENT'];
572 }
573 # peek for comment // ...
574 47 ▶ if ( $input[$parser_pos] eq '/' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input[$parser_pos] eq "/") 21 26 47
575 21 $comment = $c;
576 21 ▶ while ( $input[$parser_pos] ne "\x0d" && $input[$parser_pos] ne "\x0a" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input[$parser_pos] ne "\r" and $input[$parser_pos] ne "\n") 193 20 213
Condition66%2/3
$input[$parser_pos] ne "\r" and $input[$parser_pos] ne "\n"
!ll&&!rl&&r
020193
MC/DC50%1/2
$input[$parser_pos] ne "\r" and $input[$parser_pos] ne "\n"
$input[$parser_pos] ne "\r" $input[$parser_pos] ne "\n"
Truth table66%2/3
A and B
A= $input[$parser_pos] ne "\r"B= $input[$parser_pos] ne "\n"
ABresult
0X0
100
111
577 193 $comment .= $input[$parser_pos];
578 193 $parser_pos++;
579 193 ▶ if ( $parser_pos >= scalar @input ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser_pos >= scalar @input) 1 192 193
580 1 last;
581 }
582 }
583 21 $parser_pos++;
584 21 ▶ if ($wanted_newline) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wanted_newline) 12 9 21
585 12 print_newline();
586 }
587 21 return [$comment, 'TK_COMMENT'];
588 }
589 }
590 585 ▶ if ( $c eq "'" || # string
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "'" or $c eq "\"" or $c eq "/" and $last_type eq "TK_WORD" && $last_text eq "return" || ($last_type eq "TK_START_EXPR" || $last_type eq "TK_START_BLOCK" || $last_type eq "TK_END_BLOCK" || $last_type eq "TK_OPERATOR" || $last_type eq "TK_EOF" || $last_type eq "TK_SEMICOLON")) 46 501 547
Condition90%27/30
$c eq "'" or $c eq "\"" or $c eq "/" and $last_type eq "TK_WORD" && $last_text eq "return" || ($last_type eq "TK_START_EXPR" || $last_type eq "TK_START_BLOCK" || $last_type eq "TK_END_BLOCK" || $last_type eq "TK_OPERATOR" || $last_type eq "TK_EOF" || $last_type eq "TK_SEMICOLON")
l!l&&r!l&&!r
62282241
$c eq "'" or $c eq "\""
l!l&&r!l&&!r
1844523
$c eq "/" and $last_type eq "TK_WORD" && $last_text eq "return" || ($last_type eq "TK_START_EXPR" || $last_type eq "TK_START_BLOCK" || $last_type eq "TK_END_BLOCK" || $last_type eq "TK_OPERATOR" || $last_type eq "TK_EOF" || $last_type eq "TK_SEMICOLON")
!ll&&!rl&&r
4971115
$last_type eq "TK_WORD" and $last_text eq "return" or ($last_type eq "TK_START_EXPR" or $last_type eq "TK_START_BLOCK" or $last_type eq "TK_END_BLOCK" or $last_type eq "TK_OPERATOR" or $last_type eq "TK_EOF" or $last_type eq "TK_SEMICOLON")
l!l&&r!l&&!r
01511
$last_type eq "TK_WORD" and $last_text eq "return"
!ll&&!rl&&r
2240
$last_type eq "TK_START_EXPR" or $last_type eq "TK_START_BLOCK" or $last_type eq "TK_END_BLOCK" or $last_type eq "TK_OPERATOR" or $last_type eq "TK_EOF" or $last_type eq "TK_SEMICOLON"
l!l&&r!l&&!r
2024
$last_type eq "TK_START_EXPR" or $last_type eq "TK_START_BLOCK" or $last_type eq "TK_END_BLOCK" or $last_type eq "TK_OPERATOR" or $last_type eq "TK_EOF"
l!l&&r!l&&!r
2006
$last_type eq "TK_START_EXPR" or $last_type eq "TK_START_BLOCK" or $last_type eq "TK_END_BLOCK" or $last_type eq "TK_OPERATOR"
l!l&&r!l&&!r
1556
$last_type eq "TK_START_EXPR" or $last_type eq "TK_START_BLOCK" or $last_type eq "TK_END_BLOCK"
l!l&&r!l&&!r
13211
$last_type eq "TK_START_EXPR" or $last_type eq "TK_START_BLOCK"
l!l&&r!l&&!r
9413
MC/DC18%2/11
$c eq "'" or $c eq "\"" or $c eq "/" and $last_type eq "TK_WORD" && $last_text eq "return" || ($last_type eq "TK_START_EXPR" || $last_type eq "TK_START_BLOCK" || $last_type eq "TK_END_BLOCK" || $last_type eq "TK_OPERATOR" || $last_type eq "TK_EOF" || $last_type eq "TK_SEMICOLON")
$c eq "'" $c eq "\"" $c eq "/" $last_type eq "TK_WORD" $last_text eq "return" $last_type eq "TK_START_EXPR" $last_type eq "TK_START_BLOCK" $last_type eq "TK_END_BLOCK" $last_type eq "TK_OPERATOR" $last_type eq "TK_EOF" $last_type eq "TK_SEMICOLON"
Truth table22%4/18
A or B or C and D and E or F or G or H or I or J or K
A= $c eq "'"B= $c eq "\""C= $c eq "/"D= $last_type eq "TK_WORD"E= $last_text eq "return"F= $last_type eq "TK_START_EXPR"G= $last_type eq "TK_START_BLOCK"H= $last_type eq "TK_END_BLOCK"I= $last_type eq "TK_OPERATOR"J= $last_type eq "TK_EOF"K= $last_type eq "TK_SEMICOLON"
ABCDEFGHIJKresult
1XXXXXXXXXX1
01XXXXXXXXX1
00111XXXXXX1
0010X1XXXXX1
0010X01XXXX1
0010X001XXX1
0010X0001XX1
0010X00001X1
0010X0000011
001101XXXXX1
0011001XXXX1
00110001XXX1
001100001XX1
0011000001X1
001100000011
000XXXXXXXX0
0010X0000000
001100000000
591 $c eq '"' || # string
592 ($c eq '/' &&
593 (( $last_type eq 'TK_WORD' && $last_text eq 'return') ||
594 ( $last_type eq 'TK_START_EXPR' || $last_type eq 'TK_START_BLOCK' || $last_type eq 'TK_END_BLOCK' || $last_type eq 'TK_OPERATOR' || $last_type eq 'TK_EOF' || $last_type eq 'TK_SEMICOLON')))) { # regexp
595 84 my $sep = $c;
596 84 my $esc = 0;
597 84 my $resulting_string = $c;
598 84 ▶ if ( $parser_pos < scalar @input ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser_pos < scalar @input) 84 0 84
599 84 ▶ if ( $sep eq '/') {
Branch: 1 branch
BranchTrueFalseTotal
if ($sep eq '/') { } 22 62 84
600 # handle regexp separately...
601 22 my $in_char_class = 0;
602 22 ▶ while ( $esc || $in_char_class || $input[$parser_pos] ne $sep ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($esc or $in_char_class or $input[$parser_pos] ne $sep) 90 20 110
Condition100%6/6
$esc or $in_char_class or $input[$parser_pos] ne $sep
l!l&&r!l&&!r
297020
$esc or $in_char_class
l!l&&r!l&&!r
92090
MC/DC100%3/3
$esc or $in_char_class or $input[$parser_pos] ne $sep
$esc $in_char_class $input[$parser_pos] ne $sep
Truth table100%4/4
A or B or C
A= $escB= $in_char_classC= $input[$parser_pos] ne $sep
ABCresult
1XX1
01X1
0011
0000
603 99 $resulting_string .= $input[$parser_pos];
604 99 ▶ if ( not $esc ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $esc) { } 90 9 99
605 90 ▶ $esc = ( $input[$parser_pos] eq '\\' ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$input[$parser_pos] eq '\\' ? : 9 81 90
606 90 ▶ if ( $input[$parser_pos] eq '[' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($input[$parser_pos] eq '[') { } 5 85 90
elsif ($input[$parser_pos] eq ']') { } 4 81 85
607 5 $in_char_class = 1;
608 } elsif ( $input[$parser_pos] eq ']' ) {
609 4 $in_char_class = 0;
610 }
611 } else {
612 9 $esc = 0;
613 }
614 99 $parser_pos++;
615 99 ▶ if ( $parser_pos >= scalar @input ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser_pos >= scalar @input) 2 97 99
616 # incomplete string/rexp when end-of-file reached.
617 # bail out with what had been received so far.
618 2 return [$resulting_string, 'TK_STRING'];
619 }
620 }
621  
622 } else {
623 # and handle string also separately
624 62 ▶ while ( $esc || $input[$parser_pos] ne $sep ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($esc or $input[$parser_pos] ne $sep) 86 62 148
Condition66%2/3
$esc or $input[$parser_pos] ne $sep
l!l&&r!l&&!r
08662
MC/DC50%1/2
$esc or $input[$parser_pos] ne $sep
$esc $input[$parser_pos] ne $sep
Truth table66%2/3
A or B
A= $escB= $input[$parser_pos] ne $sep
ABresult
1X1
011
000
625 86 $resulting_string .= $input[$parser_pos];
626 86 ▶ if ( not $esc ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $esc) { } 86 0 86
627 86 ▶ $esc = ( $input[$parser_pos] eq '\\' ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$input[$parser_pos] eq '\\' ? : 0 86 86
628 } else {
629 0 $esc = 0;
630 }
631 86 $parser_pos++;
632 86 ▶ if ( $parser_pos >= scalar @input ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser_pos >= scalar @input) 0 86 86
633 # incomplete string/rexp when end-of-file reached.
634 # bail out with what had been received so far.
635 0 return [$resulting_string, 'TK_STRING'];
636 }
637 }
638 }
639 }
640 82 $parser_pos++;
641 82 $resulting_string .= $sep;
642 82 ▶ if ( $sep eq '/' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sep eq "/") 20 62 82
643 # regexps may have modifiers /regexp/MOD , so fetch those, too
644 20 ▶ while ( $parser_pos < scalar @input && (grep { $input[$parser_pos] eq $_ } @wordchar) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser_pos < scalar @input and grep {$input[$parser_pos] eq $_;} @wordchar) 16 20 36
Condition100%3/3
$parser_pos < scalar @input and grep {$input[$parser_pos] eq $_;} @wordchar
!ll&&!rl&&r
21816
MC/DC100%2/2
$parser_pos < scalar @input and grep {$input[$parser_pos] eq $_;} @wordchar
$parser_pos < scalar @input grep {$input[$parser_pos] eq $_;} @wordchar
Truth table100%3/3
A and B
A= $parser_pos < scalar @inputB= grep {$input[$parser_pos] eq $_;} @wordchar
ABresult
0X0
100
111
645 16 $resulting_string .= $input[$parser_pos];
646 16 $parser_pos++;
647 }
648 }
649 82 return [$resulting_string, 'TK_STRING'];
650 }
651  
652 501 ▶ if ($c eq '#') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "#") 14 487 501
653 # Spidermonkey-specific sharp variables for circular references
654 # https://developer.mozilla.org/En/Sharp_variables_in_JavaScript
655 # http://mxr.mozilla.org/mozilla-central/source/js/src/jsscan.cpp around line 1935
656 14 my $sharp = '#';
657 14 ▶ if ($parser_pos < scalar @input && (grep { $input[$parser_pos] eq $_ } @digits) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser_pos < scalar @input and grep {$input[$parser_pos] eq $_;} @digits) 13 1 14
Condition66%2/3
$parser_pos < scalar @input and grep {$input[$parser_pos] eq $_;} @digits
!ll&&!rl&&r
1013
MC/DC50%1/2
$parser_pos < scalar @input and grep {$input[$parser_pos] eq $_;} @digits
$parser_pos < scalar @input grep {$input[$parser_pos] eq $_;} @digits
Truth table66%2/3
A and B
A= $parser_pos < scalar @inputB= grep {$input[$parser_pos] eq $_;} @digits
ABresult
0X0
100
111
658 13 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$parser_pos < scalar @input and $c ne "#" and $c ne "=" and do { do { $c = $input[$parser_pos]; $sharp .= $c; $parser_pos += 1 } } 22 13 35
Condition100%6/6
$parser_pos < scalar @input and $c ne "#" and $c ne "="
!ll&&!rl&&r
7622
$parser_pos < scalar @input and $c ne "#"
!ll&&!rl&&r
1628
MC/DC100%3/3
$parser_pos < scalar @input and $c ne "#" and $c ne "="
$parser_pos < scalar @input $c ne "#" $c ne "="
Truth table100%4/4
A and B and C
A= $parser_pos < scalar @inputB= $c ne "#"C= $c ne "="
ABCresult
0XX0
10X0
1100
1111
659 35 $c = $input[$parser_pos];
660 35 $sharp .= $c;
661 35 $parser_pos += 1;
662 } while ($parser_pos < scalar @input && $c ne '#' && $c ne '=');
663 13 ▶ if ($c eq '#') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq '#') { } 6 7 13
664 6 return [$sharp, 'TK_WORD'];
665 } else {
666 7 return [$sharp, 'TK_OPERATOR'];
667 }
668 }
669 }
670  
671 488 ▶ if ($c eq '<' && $parser_pos + 2 < scalar @input && join('', @input[$parser_pos-1 .. $parser_pos+2]) eq '<!--') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "<" and $parser_pos + 2 < scalar @input and join("", @input[$parser_pos - 1 .. $parser_pos + 2]) eq "<!--") 7 481 488
Condition100%6/6
$c eq "<" and $parser_pos + 2 < scalar @input and join("", @input[$parser_pos - 1 .. $parser_pos + 2]) eq "<!--"
!ll&&!rl&&r
469127
$c eq "<" and $parser_pos + 2 < scalar @input
!ll&&!rl&&r
468119
MC/DC100%3/3
$c eq "<" and $parser_pos + 2 < scalar @input and join("", @input[$parser_pos - 1 .. $parser_pos + 2]) eq "<!--"
$c eq "<" $parser_pos + 2 < scalar @input join("", @input[$parser_pos - 1 .. $parser_pos + 2]) eq "<!--"
Truth table100%4/4
A and B and C
A= $c eq "<"B= $parser_pos + 2 < scalar @inputC= join("", @input[$parser_pos - 1 .. $parser_pos + 2]) eq "<!--"
ABCresult
0XX0
10X0
1100
1111
672 7 $parser_pos += 3;
673 7 return ['<!--', 'TK_COMMENT'];
674 }
675 481 ▶ if ($c eq '-' && $parser_pos + 1 < scalar @input && join('', @input[$parser_pos-1 .. $parser_pos+1]) eq '-->') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "-" and $parser_pos + 1 < scalar @input and join("", @input[$parser_pos - 1 .. $parser_pos + 1]) eq "-->") 6 475 481
Condition83%5/6
$c eq "-" and $parser_pos + 1 < scalar @input and join("", @input[$parser_pos - 1 .. $parser_pos + 1]) eq "-->"
!ll&&!rl&&r
459166
$c eq "-" and $parser_pos + 1 < scalar @input
!ll&&!rl&&r
459022
MC/DC66%2/3
$c eq "-" and $parser_pos + 1 < scalar @input and join("", @input[$parser_pos - 1 .. $parser_pos + 1]) eq "-->"
$c eq "-" $parser_pos + 1 < scalar @input join("", @input[$parser_pos - 1 .. $parser_pos + 1]) eq "-->"
Truth table75%3/4
A and B and C
A= $c eq "-"B= $parser_pos + 1 < scalar @inputC= join("", @input[$parser_pos - 1 .. $parser_pos + 1]) eq "-->"
ABCresult
0XX0
10X0
1100
1111
676 6 $parser_pos += 2;
677 6 ▶ if ($wanted_newline) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wanted_newline) 6 0 6
678 6 print_newline();
679 }
680 6 return ['-->', 'TK_COMMENT'];
681 }
682  
683 475 ▶ if ( grep { $c eq $_ } @punct ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$c eq $_;} @punct) 430 45 475
684 430 ▶ while ( $parser_pos < scalar @input && (grep { $c . $input[$parser_pos] eq $_ } @punct) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser_pos < scalar @input and grep {$c . $input[$parser_pos] eq $_;} @punct) 46 430 476
Condition66%2/3
$parser_pos < scalar @input and grep {$c . $input[$parser_pos] eq $_;} @punct
!ll&&!rl&&r
043046
MC/DC50%1/2
$parser_pos < scalar @input and grep {$c . $input[$parser_pos] eq $_;} @punct
$parser_pos < scalar @input grep {$c . $input[$parser_pos] eq $_;} @punct
Truth table66%2/3
A and B
A= $parser_pos < scalar @inputB= grep {$c . $input[$parser_pos] eq $_;} @punct
ABresult
0X0
100
111
685 46 $c .= $input[$parser_pos];
686 46 $parser_pos++;
687 46 ▶ last if ( $parser_pos >= scalar @input );
Branch: 1 branch
BranchTrueFalseTotal
if $parser_pos >= scalar @input 0 46 46
688 }
689 430 return [$c, 'TK_OPERATOR'];
690 }
691 45 return [$c, 'TK_UNKNOWN'];
692 }
693  
694 2 1;
695 __END__
↑ Summary Build »