blib/script/marpa_r2_html_fmt

filter: Statementstmt 80.6% 238 / 295 Branchbran 69.8% 95 / 136 Conditioncond 61.5% 16 / 26 MC/DCmcdc 41.1% 7 / 17 Subroutinesub 86.6% 13 / 15 Podpod n/a totaltotal 75.4% 369 / 489 SCAR 50.5
CC
77
Cov
76%
post_process
93.5
do_pre
16.0
do_default
14.0
CRAP 155.3
« blib/lib/Marpa/R2/HTML/Config/Compile.pm ↑ Summary blib/lib/Marpa/R2/Thin/Trace.pm »
1 #!/usr/local/bin/perl
2 # Copyright 2022 Jeffrey Kegler
3 # This file is part of Marpa::R2. Marpa::R2 is free software: you can
4 # redistribute it and/or modify it under the terms of the GNU Lesser
5 # General Public License as published by the Free Software Foundation,
6 # either version 3 of the License, or (at your option) any later version.
7 #
8 # Marpa::R2 is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser
14 # General Public License along with Marpa::R2. If not, see
15 # http://www.gnu.org/licenses/.
16  
17 13 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 13 ▶use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 13 ▶use Marpa::R2::HTML;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 13 ▶use Fatal qw(open close);
Subroutine BEGIN: called CC=1 SCAR=0.0
23 13 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 sub usage
26 {
27 0 ▶ say {*STDERR} "$PROGRAM_NAME html_fmt [uri|file]" or die "say failed: $ERRNO";
Subroutine usage: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
say {*STDERR;} "$main::PROGRAM_NAME html_fmt [uri|file]" or die "say failed: $main::ERRNO" 0 0 0
28 0 exit 1;
29 }
30  
31 13 my $help_flag = 0;
32 13 my $allowed_avoid_whitespace_flags = { map { ( $_, 1) } qw(comment yes no) };
33 13 my $avoid_whitespace_flag = 'yes';
34 13 local $main::ADDED_TAG_COMMENT_FLAG = 1;
35 13 my $ws_ok_before_end_tag_flag = 0;
36 13 my $ws_ok_after_start_tag_flag = 1;
37 13 my $dump_config_flag = 0;
38 13 my $dump_AHFA_flag = 0;
39 13 my $trace_terminals_flag = 0;
40 13 my $trace_cruft_flag = 0;
41 13 my $trace_values_flag = 0;
42 13 my $compile_flag;
43 13 ▶usage()
Branch: 1 branch
BranchTrueFalseTotal
unless &Getopt::Long::GetOptions("help", \$help_flag, "avoid-whitespace=s", \$avoid_whitespace_flag, "ws-ok-before-end-tag!", \$ws_ok_before_end_tag_flag, "ws-ok-after-start-tag!", \$ws_ok_after_start_tag_flag, "added-tag-comment!", \$main::ADDED_TAG_COMMENT_FLAG, "dump-config", \$dump_config_flag, "dump-AHFA", \$dump_AHFA_flag, "compile=s", \$compile_flag, "trace-terminals", \$trace_terminals_flag, "trace-cruft", \$trace_cruft_flag, "trace-values", \$trace_values_flag) 0 13 13
44 if not Getopt::Long::GetOptions(
45 'help' => \$help_flag,
46 'avoid-whitespace=s' => \$avoid_whitespace_flag,
47 'ws-ok-before-end-tag!' => \$ws_ok_before_end_tag_flag,
48 'ws-ok-after-start-tag!' => \$ws_ok_after_start_tag_flag,
49 'added-tag-comment!' => \$main::ADDED_TAG_COMMENT_FLAG,
50  
51 # undocumented
52 'dump-config' => \$dump_config_flag,
53 'dump-AHFA' => \$dump_AHFA_flag,
54 'compile=s' => \$compile_flag,
55 'trace-terminals' => \$trace_terminals_flag,
56 'trace-cruft' => \$trace_cruft_flag,
57 'trace-values' => \$trace_values_flag,
58 );
59 13 ▶usage() if $help_flag or scalar @ARGV > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $help_flag or scalar @ARGV > 1 0 13 13
Condition33%1/3
$help_flag or scalar @ARGV > 1
l!l&&r!l&&!r
0013
MC/DC0%0/2
$help_flag or scalar @ARGV > 1
$help_flag scalar @ARGV > 1
Truth table33%1/3
A or B
A= $help_flagB= scalar @ARGV > 1
ABresult
1X1
011
000
60  
61 13 ▶if ( not $allowed_avoid_whitespace_flags->{$avoid_whitespace_flag} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($allowed_avoid_whitespace_flags->{$avoid_whitespace_flag}) 0 13 13
62 die "Bad avoid-whitespace flag\n",
63 'avoid-whitespace must be one of the following: ', join q{ },
64 0 keys %{$allowed_avoid_whitespace_flags};
65 }
66  
67 13 my $locator = shift;
68 13 my $document;
69 GET_DOCUMENT: {
70 13 ▶ if ( not defined $locator ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $locator) 0 13 13
71 0 local $RS = undef;
72 ## no critic(InputOutput::ProhibitExplicitStdin)
73 0 $document = <STDIN>;
74 0 last GET_DOCUMENT;
75 }
76 13 ▶ if ( $locator =~ /\A [[:alnum:]]+ [:] /xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($locator =~ /\A [[:alnum:]]+ [:] /msx) 0 13 13
77 0 require WWW::Mechanize;
78 0 my $mech = WWW::Mechanize->new( autocheck => 1 );
79 0 $mech->get($locator);
80 0 $document = $mech->content;
81 0 undef $mech;
82 0 last GET_DOCUMENT;
83 } ## end if ( $locator =~ /\A [[:alnum:]]+ [:] /xms )
84 {
85 13 local $RS = undef;
86 13 open my $fh, q{<}, $locator;
87 13 $document = <$fh>;
88 13 close $fh;
89 }
90 } ## end GET_DOCUMENT:
91  
92 sub post_process {
93 13 ▶ my ($value) = @_;
Subroutine post_process: called CC=56 SCAR=45.4
94 13 my @text_pieces = ();
95 13 DATUM: for my $line_data ( map { @{$_} } @{$value} ) {
96 287 my ( $type, $indent ) = @{$line_data};
97 287 ▶ if ( $type eq 'text' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "text") 56 231 287
98 56 my $text = $line_data->[2];
99 56 my $has_trailing_ws = $text =~ s/ \s+ \z//xms;
100 56 ▶ if ( $text =~ s/ \A \s+ //xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ s/ \A \s+ //msx) 2 54 56
101 2 push @text_pieces, [ 'whitespace', $indent ];
102 }
103 56 my @lines = grep { $_ =~ /\S/xms } split /\n/xms, $text;
104 56 for my $line_no ( 0 .. $#lines ) {
105 41 my $line = $lines[$line_no];
106 41 $line =~ s/\A[ \t]+//xms;
107 41 $line =~ s/[ \t]+\z//xms;
108 41 $line =~ s/[ \t]+/ /xms;
109 41 ▶ push @text_pieces, [ 'whitespace', $indent ] if $line_no;
Branch: 1 branch
BranchTrueFalseTotal
if $line_no 2 39 41
110 41 push @text_pieces, [ 'text', $indent, $line ];
111 } ## end for my $line_no ( 0 .. $#lines )
112 56 ▶ push @text_pieces, [ 'whitespace', $indent ] if $has_trailing_ws;
Branch: 1 branch
BranchTrueFalseTotal
if $has_trailing_ws 32 24 56
113 56 next DATUM;
114 } ## end if ( $type eq 'text' )
115 231 ▶ if ( $type eq 'msg: missing start tag' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "msg: missing start tag") 14 217 231
116 14 my $location = $line_data->[2];
117 14 my $tagname = $line_data->[3];
118 GIVEN_LOCATION: {
119 14 ▶ if ( $location eq 'preceeding' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($location eq "preceeding") 14 0 14
120 14 push @text_pieces,
121 [
122 'html_fmt comment',
123 $indent + 1,
124 'Preceeding start tag is replacement for a missing one'
125 ];
126 14 last GIVEN_LOCATION;
127 } ## end if ( $location eq 'preceeding' )
128 0 ▶ if ( $location eq 'following pre' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($location eq "following pre") 0 0 0
129 0 push @text_pieces,
130 [
131 'html_fmt comment',
132 $indent,
133 "Inside following <pre>, a start tag is missing: <$tagname>"
134 ];
135 0 last GIVEN_LOCATION;
136 } ## end if ( $location eq 'following pre' )
137 Carp::croak(
138 0 "Internal error: unprovided-for missing start tag location: $_"
139 );
140 } ## end GIVEN_LOCATION:
141 14 next DATUM;
142 } ## end if ( $type eq 'msg: missing start tag' )
143 217 ▶ if ( $type eq 'msg: missing end tag' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "msg: missing end tag") 21 196 217
144 21 my $location = $line_data->[2];
145 21 my $tagname = $line_data->[3];
146 GIVEN_LOCATION: {
147 21 ▶ if ( $location eq 'following' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($location eq "following") 21 0 21
148 21 push @text_pieces,
149 [
150 'html_fmt comment',
151 $indent + 1,
152 'Following end tag is replacement for a missing one'
153 ];
154 21 last GIVEN_LOCATION;
155 } ## end if ( $location eq 'following' )
156 0 ▶ if ( $location eq 'following pre' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($location eq "following pre") 0 0 0
157 0 push @text_pieces,
158 [
159 'html_fmt comment',
160 $indent,
161 "Inside following <pre>, an end tag is missing: </$tagname>"
162 ];
163 0 last GIVEN_LOCATION;
164 } ## end if ( $location eq 'following pre' )
165 Carp::croak(
166 0 "Internal error: unprovided-for missing end tag location: $_"
167 );
168 } ## end GIVEN_LOCATION:
169 21 next DATUM;
170 } ## end if ( $type eq 'msg: missing end tag' )
171 196 ▶ if ( $type eq 'msg: missing pre end tag' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "msg: missing pre end tag") 2 194 196
172 2 push @text_pieces,
173 [
174 'html_fmt comment',
175 $indent,
176 'An missing end tag was added to close the preceding <pre> element'
177 ];
178 2 next DATUM;
179 } ## end if ( $type eq 'msg: missing pre end tag' )
180 194 ▶ if ( $type eq 'msg: missing pre start tag' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "msg: missing pre start tag") 0 194 194
181 0 push @text_pieces,
182 [
183 'html_fmt comment',
184 $indent,
185 'A missing start tag was added in front of the following <pre> element'
186 ];
187 0 next DATUM;
188 } ## end if ( $type eq 'msg: missing pre start tag' )
189 194 ▶ if ( $type eq 'msg: cruft' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "msg: cruft") 9 185 194
190 9 my $location = $line_data->[2];
191 9 my $cruft = $line_data->[3];
192 9 my $token_type = $line_data->[4];
193 9 ▶ my $node_desc =
Branch: 3 branches
BranchTrueFalseTotal
$token_type eq 'S' ? : 3 6 9
$token_type eq 'E' ? : 4 2 6
$token_type eq 'T' ? : 2 0 2
194 $token_type eq 'S' ? 'start tag'
195 : $token_type eq 'E' ? 'end tag'
196 : $token_type eq 'T' ? 'text'
197 : 'node';
198 GIVEN_LOCATION: {
199 9 ▶ if ( $location eq 'following' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($location eq "following") 9 0 9
200 9 push @text_pieces,
201 [
202 'html_fmt comment',
203 $indent,
204 "Next $node_desc is cruft"
205 ];
206 9 last GIVEN_LOCATION;
207 } ## end if ( $location eq 'following' )
208 0 ▶ if ( $location eq 'following pre' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($location eq "following pre") 0 0 0
209  
210 # Make sure the cruft quoted inside
211 # the HTML comment does not
212 # disrupt the comment.
213 0 ( my $safe_cruft = $cruft ) =~ s/--/- -/xms;
214 0 push @text_pieces,
215 [
216 'html_fmt comment',
217 $indent,
218 qq{Inside the following <pre>, $node_desc is cruft:\n$safe_cruft}
219 ];
220 0 last GIVEN_LOCATION;
221 } ## end if ( $location eq 'following pre' )
222 Carp::croak(
223 0 "Internal error: unprovided-for cruft location: $_");
224 } ## end GIVEN_LOCATION:
225 9 next DATUM;
226 } ## end if ( $type eq 'msg: cruft' )
227 185 push @text_pieces, [ $type, $indent, $line_data->[2] ];
228 } ## end for my $line_data ( map { @{$_} } @{$value} )
229 13 my @ws_unsafe;
230 13 $ws_unsafe[ scalar @text_pieces ] = 0; # size the array
231 13 $ws_unsafe[0] = 0;
232 13 my $last_non_comment_ix = scalar @text_pieces;
233 13 my $safe_after_piece = 0;
234 13 my $first_body_tag;
235 my $last_body_tag;
236 13 TEXT_PIECE: for my $text_piece_ix ( 0 .. $#text_pieces ) {
237 308 my ( $type, $indent, $text ) = @{ $text_pieces[$text_piece_ix] };
238 308 my $safe_before_piece = 0;
239 WHITESPACE_BY_TYPE: {
240  
241 # If a comment, after-piece is whatever current value
242 # of $safe_after_piece,
243 # leave before as-is
244 308 ▶ last WHITESPACE_BY_TYPE if $type eq 'html_fmt comment';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "html_fmt comment" 46 262 308
245 262 ▶ last WHITESPACE_BY_TYPE if $type eq 'comment';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "comment" 3 259 262
246 259 ▶ if ( $type eq 'whitespace' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "whitespace") 36 223 259
247  
248 # Safe before and after other whitespace
249 36 $safe_before_piece = $safe_after_piece = 1;
250 36 last WHITESPACE_BY_TYPE;
251 } ## end if ( $type eq 'whitespace' )
252 223 ▶ if ( $type eq 'end tag' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "end tag") 85 138 223
253  
254 85 ▶ if ( $text =~ /\A [^[:alnum:]]+ body [^[:alnum:]]+ \z /xmsi )
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /\A [^[:alnum:]]+ body [^[:alnum:]]+ \z /imsx) 12 73 85
255 {
256 12 $last_body_tag = $text_piece_ix;
257 }
258  
259 # Unsafe after an end tag, but safe before it
260 85 $safe_before_piece = $ws_ok_before_end_tag_flag;
261 85 $safe_after_piece = 0;
262 85 last WHITESPACE_BY_TYPE;
263 } ## end if ( $type eq 'end tag' )
264 138 ▶ if ( $type eq 'start tag' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "start tag") 83 55 138
265  
266 83 ▶ if ( not defined $first_body_tag
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $first_body_tag and $text =~ /\A [^[:alnum:]]+ body [^[:alnum:]]+ \z /imsx) 12 71 83
Condition100%3/3
not defined $first_body_tag and $text =~ /\A [^[:alnum:]]+ body [^[:alnum:]]+ \z /imsx
!ll&&!rl&&r
442712
MC/DC100%2/2
not defined $first_body_tag and $text =~ /\A [^[:alnum:]]+ body [^[:alnum:]]+ \z /imsx
not defined $first_body_tag $text =~ /\A [^[:alnum:]]+ body [^[:alnum:]]+ \z /imsx
Truth table100%3/3
not(A) and B
A= not defined $first_body_tagB= $text =~ /\A [^[:alnum:]]+ body [^[:alnum:]]+ \z /imsx
ABresult
0X0
100
111
267 and $text
268 =~ /\A [^[:alnum:]]+ body [^[:alnum:]]+ \z /xmsi )
269 {
270 12 $first_body_tag = $text_piece_ix;
271 } ## end if ( not defined $first_body_tag and $text =~ ...)
272  
273 # Leave safe status as-is before start tag
274 # Whitespace safe after a start tag
275 83 $safe_after_piece = $ws_ok_after_start_tag_flag;
276 83 last WHITESPACE_BY_TYPE;
277 } ## end if ( $type eq 'start tag' )
278 55 ▶ if ( $type eq 'text' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "text") 41 14 55
279  
280 # Leave safe status as-is before text
281 # Whitespace not safe after text
282 41 $safe_after_piece = 0;
283 41 last WHITESPACE_BY_TYPE;
284 } ## end if ( $type eq 'text' )
285 # Blocks can occur inline, etc.
286 # So with everything else, be conservative.
287 # Whitespace is unsafe after, and left as-is before.
288 14 $safe_after_piece = 0;
289 } ## end WHITESPACE_BY_TYPE:
290 308 ▶ $ws_unsafe[ $text_piece_ix + 1 ] = $safe_after_piece ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$safe_after_piece ? : 145 163 308
291 308 ▶ if ($safe_before_piece) {
Branch: 1 branch
BranchTrueFalseTotal
if ($safe_before_piece) 36 272 308
292 36 for my $ix ( $last_non_comment_ix + 1 .. $text_piece_ix ) {
293 41 $ws_unsafe[$ix] = 0;
294 }
295 }
296 308 ▶ if ( $type ne 'comment' and $type ne 'html_fmt comment' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type ne "comment" and $type ne "html_fmt comment") 259 49 308
Condition100%3/3
$type ne "comment" and $type ne "html_fmt comment"
!ll&&!rl&&r
346259
MC/DC100%2/2
$type ne "comment" and $type ne "html_fmt comment"
$type ne "comment" $type ne "html_fmt comment"
Truth table100%3/3
A and B
A= $type ne "comment"B= $type ne "html_fmt comment"
ABresult
0X0
100
111
297 259 $last_non_comment_ix = $text_piece_ix;
298 }
299 } ## end TEXT_PIECE: for my $text_piece_ix ( 0 .. $#text_pieces )
300  
301 # Whitespace safe before the body
302 13 ▶ $first_body_tag //= -1;
Condition100%2/2
$first_body_tag //= -1
l!l
121
MC/DC100%1/1
$first_body_tag //= -1
$first_body_tag
Truth table100%2/2
A
A= $first_body_tag
Aresult
11
00
303 13 ▶ for (
Branch: 1 branch
BranchTrueFalseTotal
if ($text_piece_ix <= $first_body_tag) 63 13 76
304 my $text_piece_ix = 0;
305 $text_piece_ix <= $first_body_tag;
306 $text_piece_ix++
307 )
308 {
309 63 $ws_unsafe[$text_piece_ix] = 0;
310 } ## end for ( my $text_piece_ix = 0; $text_piece_ix <= $first_body_tag...)
311  
312 # Whitespace safe after the body,
313 # or at least at the EOF if no end tag
314 13 ▶ $last_body_tag //= $#text_pieces;
Condition66%2/3
$last_body_tag //= $#text_pieces
l!l&&r!l&&!r
1210
MC/DC0%0/2
$last_body_tag //= $#text_pieces
$last_body_tag $#text_pieces
Truth table66%2/3
A //= B
A= $last_body_tagB= $#text_pieces
ABresult
1X1
011
000
315 13 ▶ for (
Branch: 1 branch
BranchTrueFalseTotal
if ($text_piece_ix > $last_body_tag) 28 13 41
316 my $text_piece_ix = scalar @text_pieces;
317 $text_piece_ix > $last_body_tag;
318 $text_piece_ix--
319 )
320 {
321 28 $ws_unsafe[$text_piece_ix] = 0;
322 } ## end for ( my $text_piece_ix = scalar @text_pieces; $text_piece_ix...)
323  
324 13 my @output = ();
325 CREATE_OUTPUT: {
326 13 ▶ if ( $avoid_whitespace_flag eq 'comment' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($avoid_whitespace_flag eq "comment") 0 13 13
327 0 TEXT_PIECE: for my $text_piece_ix ( 0 .. $#text_pieces ) {
328 my ( $type, $indent, $text ) =
329 0 @{ $text_pieces[$text_piece_ix] };
330 0 ▶ next TEXT_PIECE if $type eq 'whitespace';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "whitespace" 0 0 0
331 0 ▶ my $suffix = $ws_unsafe[ $text_piece_ix + 1 ] ? '<!--' : q{};
Branch: 1 branch
BranchTrueFalseTotal
$ws_unsafe[$text_piece_ix + 1] ? : 0 0 0
332 0 my $indentation = q{ } x $indent;
333 0 ▶ if ( $type eq 'html_fmt comment' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "html_fmt comment") 0 0 0
334 0 push @output,
335 $indentation
336 . ' html_fmt: '
337 . $text . ' -->'
338 . $suffix;
339 0 next TEXT_PIECE;
340 } ## end if ( $type eq 'html_fmt comment' )
341 0 ▶ if ( $ws_unsafe[$text_piece_ix] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ws_unsafe[$text_piece_ix]) 0 0 0
342 0 $indentation =
343 $indentation
344 . ' html_fmt: this comment is to avoid introducing whitespace'
345 . "\n"
346 . $indentation . '-->';
347 } ## end if ( $ws_unsafe[$text_piece_ix] )
348 0 ▶ if ( $type eq 'text' and $text =~ /\S/xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "text" and $text =~ /\S/msx) 0 0 0
Condition0%0/3
$type eq "text" and $text =~ /\S/msx
!ll&&!rl&&r
000
MC/DC0%0/2
$type eq "text" and $text =~ /\S/msx
$type eq "text" $text =~ /\S/msx
Truth table0%0/3
A and B
A= $type eq "text"B= $text =~ /\S/msx
ABresult
0X0
100
111
349 0 push @output, $indentation . $text . $suffix;
350 0 next TEXT_PIECE;
351 }
352 0 push @output, $indentation . $text . $suffix;
353 } ## end TEXT_PIECE: for my $text_piece_ix ( 0 .. $#text_pieces )
354 0 last CREATE_OUTPUT;
355 } ## end if ( $avoid_whitespace_flag eq 'comment' )
356 {
357 # $avoid_whitespace eq 'yes' or $avoid_whitespace eq 'no'
358 13 my $avoid_whitespace_is_yes = $avoid_whitespace_flag ne 'no';
359 13 TEXT_PIECE: for my $text_piece_ix ( 0 .. $#text_pieces ) {
360 my ( $type, $indent, $text ) =
361 308 @{ $text_pieces[$text_piece_ix] };
362 308 ▶ next TEXT_PIECE if $type eq 'whitespace';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "whitespace" 36 272 308
363 272 ▶ if ( $avoid_whitespace_is_yes and $ws_unsafe[$text_piece_ix] )
Branch: 1 branch
BranchTrueFalseTotal
if ($avoid_whitespace_is_yes and $ws_unsafe[$text_piece_ix]) 95 177 272
Condition66%2/3
$avoid_whitespace_is_yes and $ws_unsafe[$text_piece_ix]
!ll&&!rl&&r
017795
MC/DC50%1/2
$avoid_whitespace_is_yes and $ws_unsafe[$text_piece_ix]
$avoid_whitespace_is_yes $ws_unsafe[$text_piece_ix]
Truth table66%2/3
A and B
A= $avoid_whitespace_is_yesB= $ws_unsafe[$text_piece_ix]
ABresult
0X0
100
111
364 {
365 95 my $indentation = q{ } x ($indent);
366 95 ▶ if ( $type eq 'html_fmt comment' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "html_fmt comment") 19 76 95
367 19 $text =
368 qq{<!--\n}
369 . $indentation
370 . ' html_fmt: '
371 . $text . "\n"
372 . $indentation . ' -->';
373 } ## end if ( $type eq 'html_fmt comment' )
374 95 $output[-1] .= $text;
375 95 next TEXT_PIECE;
376 } ## end if ( $avoid_whitespace_is_yes and $ws_unsafe[...])
377 177 my $indentation = q{ } x $indent;
378 177 ▶ if ( $type eq 'text' and $text =~ /\S/xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "text" and $text =~ /\S/msx) 39 138 177
Condition66%2/3
$type eq "text" and $text =~ /\S/msx
!ll&&!rl&&r
138039
MC/DC50%1/2
$type eq "text" and $text =~ /\S/msx
$type eq "text" $text =~ /\S/msx
Truth table66%2/3
A and B
A= $type eq "text"B= $text =~ /\S/msx
ABresult
0X0
100
111
379 39 push @output, $indentation . $text;
380 39 next TEXT_PIECE;
381 }
382 138 ▶ if ( $type eq 'html_fmt comment' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "html_fmt comment") 27 111 138
383 27 push @output,
384 $indentation . '<!-- html_fmt: ' . $text . ' -->';
385 27 next TEXT_PIECE;
386 }
387 111 push @output, $indentation . $text;
388 } ## end TEXT_PIECE: for my $text_piece_ix ( 0 .. $#text_pieces )
389 13 last CREATE_OUTPUT;
390 }
391 } ## end CREATE_OUTPUT:
392 13 return join "\n", @output, q{};
393 } ## end sub post_process
394  
395 sub do_pre {
396 2 ▶ my @new_line_data = ();
Subroutine do_pre: called CC=8 SCAR=27.7
397 2 my $start_tag = Marpa::R2::HTML::start_tag();
398 2 my $end_tag = Marpa::R2::HTML::end_tag();
399  
400 CHILD:
401 2 for my $value ( @{ Marpa::R2::HTML::values() } ) {
402 0 for my $line_data ( @{$value} ) {
403 0 ▶ if ( $line_data->[0] =~ /\A msg [:] /xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line_data->[0] =~ /\A msg [:] /msx) 0 0 0
404 push @new_line_data,
405 [
406 $line_data->[0], 0,
407 0 'following pre', @{$line_data}[ 3 .. $#{$line_data} ]
408 ];
409 } ## end if ( $line_data->[0] =~ /\A msg [:] /xms )
410 } ## end for my $line_data ( @{$value} )
411 } ## end CHILD: for my $value ( @{ Marpa::R2::HTML::values() } )
412  
413 2 ▶ if ( not defined $start_tag ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $start_tag) 0 2 2
414 0 ▶ push @new_line_data, [ 'msg: missing pre start tag', 0 ]
Branch: 1 branch
BranchTrueFalseTotal
if $main::ADDED_TAG_COMMENT_FLAG 0 0 0
415 if $main::ADDED_TAG_COMMENT_FLAG;
416 0 push @new_line_data, [ 'start tag', 0, '<pre>' ];
417 }
418  
419 2 my $original = Marpa::R2::HTML::original();
420 2 push @new_line_data, [ 'pre', 0, $original ];
421  
422 2 ▶ if ( not defined $end_tag ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $end_tag) 2 0 2
423 2 ▶ push @new_line_data, [ 'end tag', 0, '</pre>' ]
Branch: 1 branch
BranchTrueFalseTotal
if $main::ADDED_TAG_COMMENT_FLAG 2 0 2
424 if $main::ADDED_TAG_COMMENT_FLAG;
425 2 push @new_line_data, [ 'msg: missing pre end tag', 0 ];
426 }
427 2 return \@new_line_data;
428 } ## end sub do_pre
429  
430 sub do_cruft {
431 9 ▶ my $literal = Marpa::R2::HTML::literal();
Subroutine do_cruft: called CC=1 SCAR=0.0
432 9 my @new_line_data = ( [ 'msg: cruft', 0, 'following', $literal, Marpa::R2::HTML::token_type() ] );
433 9 push @new_line_data, [ 'cruft', 0, $literal ];
434 9 return \@new_line_data;
435 } ## end sub do_cruft
436  
437 sub do_comment {
438 3 ▶ my $literal = Marpa::R2::HTML::literal();
Subroutine do_comment: called CC=1 SCAR=0.0
439 3 return [ [ 'comment', 0, $literal ] ];
440 }
441  
442 sub do_default {
443 86 ▶ my $tagname = Marpa::R2::HTML::tagname();
Subroutine do_default: called CC=14 SCAR=26.4
444 86 my @new_line_data = ();
445  
446 86 my $start_tag = Marpa::R2::HTML::start_tag();
447 86 my $end_tag = Marpa::R2::HTML::end_tag();
448 86 my $is_empty_element = Marpa::R2::HTML::is_empty_element();
449 86 ▶ if ($is_empty_element) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_empty_element) 3 83 86
450 3 ▶ if ( defined $start_tag ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $start_tag) { } 2 1 3
451 2 push @new_line_data, [ 'empty element', 0, $start_tag ];
452 }
453 else {
454 1 push @new_line_data, [ 'empty element', 0, '<' . $tagname . '>' ];
455 1 ▶ push @new_line_data,
Branch: 1 branch
BranchTrueFalseTotal
if $main::ADDED_TAG_COMMENT_FLAG 0 1 1
456 [ 'msg: empty element missing start tag', 0, 'preceeding', $tagname ]
457 if $main::ADDED_TAG_COMMENT_FLAG;
458 } ## end else [ if ( defined $start_tag ) ]
459 3 return \@new_line_data;
460 }
461  
462 {
463 83 my $tag_type = 'start tag';
464 83 ▶ if ( defined $start_tag ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $start_tag) { } 35 48 83
465 35 push @new_line_data, [ $tag_type, 0, $start_tag ];
466 }
467 else {
468 48 push @new_line_data, [ $tag_type, 0, '<' . $tagname . '>' ];
469 48 ▶ push @new_line_data,
Branch: 1 branch
BranchTrueFalseTotal
if $main::ADDED_TAG_COMMENT_FLAG 14 34 48
470 [ 'msg: missing start tag', 0, 'preceeding', $tagname ]
471 if $main::ADDED_TAG_COMMENT_FLAG;
472 } ## end else [ if ( defined $start_tag ) ]
473 }
474  
475 83 my @descendant_data = @{ Marpa::R2::HTML::descendants('value,original') };
476 83 ▶ my $first_content_child = defined $start_tag ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $start_tag ? : 35 48 83
477 83 ▶ my $last_content_child = $#descendant_data - ( defined $end_tag ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
defined $end_tag ? : 9 74 83
478 CHILD:
479 83 for my $descendant_data_ix ( $first_content_child .. $last_content_child )
480 {
481 143 my ( $value, $original ) = @{ $descendant_data[$descendant_data_ix] };
482 143 ▶ if ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 87 56 143
483 87 for my $line_data ( @{$value} ) {
484 520 my ( $type, $indent, @data ) = @{$line_data};
485 520 push @new_line_data, [ $type, $indent + 1, @data ];
486 }
487 87 next CHILD;
488 } ## end if ( defined $value )
489 56 push @new_line_data, [ 'text', 1, $original ];
490 } ## end CHILD: for my $descendant_data_ix ( $first_content_child .. ...)
491  
492 83 ▶ if ( not $is_empty_element ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_empty_element) 83 0 83
493 83 ▶ if ( defined $end_tag ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $end_tag) { } 9 74 83
494 9 push @new_line_data, [ 'end tag', 0, $end_tag ];
495 }
496 else {
497 74 ▶ push @new_line_data,
Branch: 1 branch
BranchTrueFalseTotal
if $main::ADDED_TAG_COMMENT_FLAG 21 53 74
498 [ 'msg: missing end tag', 0, 'following', $tagname ]
499 if $main::ADDED_TAG_COMMENT_FLAG;
500 74 push @new_line_data, [ 'end tag', 0, '</' . $tagname . '>' ];
501 } ## end else [ if ( defined $end_tag ) ]
502 } ## end if ( not $is_empty_element )
503  
504 83 return \@new_line_data;
505 } ## end sub do_default
506  
507 my %html_args = (
508 'script' => sub {
509 0 ▶ return [ [ 'script', 0, Marpa::R2::HTML::original() ] ];
Subroutine __ANON__: not called CC=1 SCAR=6.9
510 },
511 ':CRUFT' => \&do_cruft,
512 ':COMMENT' => \&do_comment,
513 'pre' => \&do_pre,
514 q{*} => \&do_default,
515 13 ▶ ':TOP' => sub { return Marpa::R2::HTML::values(); }
Subroutine __ANON__: called CC=1 SCAR=0.0
516 13 );
517  
518 13 my %flags = (
519 trace_terminals => $trace_terminals_flag,
520 trace_cruft => $trace_cruft_flag,
521 trace_values => $trace_values_flag,
522 dump_config => $dump_config_flag,
523 dump_AHFA => $dump_AHFA_flag,
524 );
525 13 ▶if (defined $compile_flag) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $compile_flag) 10 3 13
526 10 open my $fh, q{<}, $compile_flag;
527 10 my $source = join q{}, <$fh>;
528 10 close $fh;
529 10 $flags{compile} = \$source;
530 }
531  
532 13 my $value_ref = Marpa::R2::HTML::html( \$document, \%html_args, \\%flags );
533 13 ▶die 'Internal error: no parse' if not defined $value_ref;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value_ref 0 13 13
534 13 ▶if ($dump_config_flag or $dump_AHFA_flag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dump_config_flag or $dump_AHFA_flag) 0 13 13
Condition33%1/3
$dump_config_flag or $dump_AHFA_flag
l!l&&r!l&&!r
0013
MC/DC0%0/2
$dump_config_flag or $dump_AHFA_flag
$dump_config_flag $dump_AHFA_flag
Truth table33%1/3
A or B
A= $dump_config_flagB= $dump_AHFA_flag
ABresult
1X1
011
000
535 0 print ${$value_ref};
536 0 exit 0;
537 }
538  
539 13 ▶print post_process($value_ref) or die "print failed: $ERRNO";
Branch: 1 branch
BranchTrueFalseTotal
print post_process($value_ref) or die "print failed: $main::ERRNO" 0 13 13
540  
541 13 exit 0;
542  
543 # vim: set expandtab shiftwidth=4:
« blib/lib/Marpa/R2/HTML/Config/Compile.pm ↑ Summary blib/lib/Marpa/R2/Thin/Trace.pm »