blib/lib/Marpa/R2/HTML/Config/Compile.pm

filter: Statementstmt 89.5% 402 / 449 Branchbran 67.1% 98 / 146 Conditioncond 63.8% 23 / 36 MC/DCmcdc 40.9% 9 / 22 Subroutinesub 88.4% 23 / 26 Podpod 0.0% 0 / 13 totaltotal 80.2% 555 / 692 SCAR 51.6
CC
112
Cov
83%
compile
74.7
do_ruby_statement
13.2
die_on_read_problem
12.0
CRAP 174.9
« blib/lib/Marpa/R2/SLG.pm ↑ Summary blib/script/marpa_r2_html_fmt »
1 # Copyright 2022 Jeffrey Kegler
2 # This file is part of Marpa::R2. Marpa::R2 is free software: you can
3 # redistribute it and/or modify it under the terms of the GNU Lesser
4 # General Public License as published by the Free Software Foundation,
5 # either version 3 of the License, or (at your option) any later version.
6 #
7 # Marpa::R2 is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 # Lesser General Public License for more details.
11 #
12 # You should have received a copy of the GNU Lesser
13 # General Public License along with Marpa::R2. If not, see
14 # http://www.gnu.org/licenses/.
15  
16 package Marpa::R2::HTML::Config::Compile;
17  
18 11 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 11 ▶use vars qw($VERSION $STRING_VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
23 11 $VERSION = '13.003_000';
24 11 $STRING_VERSION = $VERSION;
25 ## no critic(BuiltinFunctions::ProhibitStringyEval)
26 11 $VERSION = eval $VERSION;
27 ## use critic
28  
29 11 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 11 ▶use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 11 ▶use Marpa::R2::HTML::Config::Core;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 11 ▶use Marpa::R2::Thin::Trace;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 # Indexes into the symbol table
36 11 ▶use constant CONTEXT_CLOSED => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 11 ▶use constant CONTENTS_CLOSED => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 11 ▶use constant CONTEXT => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 11 ▶use constant CONTENTS => 3;
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 sub do_is_included_statement {
42 110 ▶ my ( $self, $external_element, undef, undef, undef, $external_group ) = @_;
Subroutine do_is_included_statement: called CC=6 SCAR=18.7
Pod undocumented
43 110 my $tag = $external_element;
44 110 $tag =~ s/\A [<] \s* //xms;
45 110 $tag =~ s/\s* [>] \z //xms;
46 110 my $element = 'ELE_' . $tag;
47 110 ( my $group_name = $external_group ) =~ s/\A [%] //xms;
48 110 my $group = 'GRP_' . $group_name;
49  
50 110 my $symbol_table = $self->{symbol_table};
51 110 ▶ my $element_entry = $symbol_table->{$element} //= [];
Condition50%1/2
$symbol_table->{$element} //= []
l!l
1100
MC/DC0%0/1
$symbol_table->{$element} //= []
$symbol_table->{$element}
Truth table50%1/2
A
A= $symbol_table->{$element}
Aresult
11
00
52 110 my $group_entry = $symbol_table->{$group};
53  
54 # For now, new groups cannot be defined
55 110 ▶ Carp::croak(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $group_entry 0 110 110
56 qq{Group "$group" does not exist\n},
57 qq{ Problem was in this line: }, $Marpa::R2::HTML::Config::Compile::LINE
58 ) if not defined $group_entry;
59  
60 110 my $closed_reason = $element_entry->[CONTEXT_CLOSED];
61 110 ▶ if ($closed_reason) {
Branch: 1 branch
BranchTrueFalseTotal
if ($closed_reason) 0 110 110
62 0 Carp::croak(
63 qq{Context of "$element" cannot be changed:\n},
64 qq{ Reason: $closed_reason\n},
65 qq{ Problem was in this line: }, $Marpa::R2::HTML::Config::Compile::LINE
66 );
67 } ## end if ($closed_reason)
68 110 $closed_reason = $group_entry->[CONTENTS_CLOSED];
69 110 ▶ if ($closed_reason) {
Branch: 1 branch
BranchTrueFalseTotal
if ($closed_reason) 0 110 110
70 0 Carp::croak(
71 qq{Contents of "$group" cannot be changed:\n},
72 qq{ Reason: $closed_reason\n},
73 qq{ Problem was in this line: }, $Marpa::R2::HTML::Config::Compile::LINE
74 );
75 } ## end if ($closed_reason)
76  
77 # If this is the first, it sets the primary group
78 110 my $primary_group_by_tag = $self->{primary_group_by_tag};
79 110 ▶ $primary_group_by_tag->{$tag} //= $group;
Condition33%1/3
$primary_group_by_tag->{$tag} //= $group
l!l&&r!l&&!r
01100
MC/DC0%0/2
$primary_group_by_tag->{$tag} //= $group
$primary_group_by_tag->{$tag} $group
Truth table33%1/3
A //= B
A= $primary_group_by_tag->{$tag}B= $group
ABresult
1X1
011
000
80 110 push @{ $element_entry->[CONTEXT] }, $group;
81  
82 110 return;
83  
84 } ## end sub do_is_included
85  
86 sub do_is_a_included_statement {
87 853 ▶ my ( $self, $external_element, undef, undef, $external_flow, undef, undef, $external_group ) = @_;
Subroutine do_is_a_included_statement: called CC=10 SCAR=24.4
Pod undocumented
88 853 my $tag = $external_element;
89 853 $tag =~ s/\A [<] \s* //xms;
90 853 $tag =~ s/\s* [>] \z //xms;
91 853 ( my $flow_name = $external_flow ) =~ s/\A [*] //xms;
92 853 ( my $group_name = $external_group ) =~ s/\A [%] //xms;
93 853 my $flow = 'FLO_' . $flow_name;
94 853 my $group = 'GRP_' . $group_name;
95 853 my $element = 'ELE_' . $tag;
96 853 my $symbol_table = $self->{symbol_table};
97 853 ▶ my $element_entry = $symbol_table->{$element} //= [];
Condition50%1/2
$symbol_table->{$element} //= []
l!l
0853
MC/DC0%0/1
$symbol_table->{$element} //= []
$symbol_table->{$element}
Truth table50%1/2
A
A= $symbol_table->{$element}
Aresult
11
00
98 853 my $group_entry = $symbol_table->{$group};
99 853 my $flow_entry = $symbol_table->{$flow};
100  
101 # For now, new flows and groups cannot be defined
102 853 ▶ Carp::croak(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $group_entry 0 853 853
103 qq{Group "$group" does not exist\n},
104 qq{ Problem was in this line: }, $Marpa::R2::HTML::Config::Compile::LINE
105 ) if not defined $group_entry;
106 853 ▶ Carp::croak(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $flow_entry 0 853 853
107 qq{Flow "$flow" does not exist\n},
108 qq{ Problem was in this line: }, $Marpa::R2::HTML::Config::Compile::LINE
109 ) if not defined $flow_entry;
110  
111 853 my $closed_reason = $element_entry->[CONTEXT_CLOSED];
112 853 ▶ if ($closed_reason) {
Branch: 1 branch
BranchTrueFalseTotal
if ($closed_reason) 0 853 853
113 0 Carp::croak(
114 qq{Context of "$element" cannot be changed:\n},
115 qq{ Reason: $closed_reason\n},
116 qq{ Problem was in this line: }, $Marpa::R2::HTML::Config::Compile::LINE
117 );
118 } ## end if ($closed_reason)
119 853 $closed_reason = $element_entry->[CONTENTS_CLOSED];
120 853 ▶ if ($closed_reason) {
Branch: 1 branch
BranchTrueFalseTotal
if ($closed_reason) 0 853 853
121 0 Carp::croak(
122 qq{Contents of "$element" cannot be changed:\n},
123 qq{ Reason: $closed_reason\n},
124 qq{ Problem was in this line: }, $Marpa::R2::HTML::Config::Compile::LINE
125 );
126 } ## end if ($closed_reason)
127 853 $closed_reason = $flow_entry->[CONTEXT_CLOSED];
128 853 ▶ if ($closed_reason) {
Branch: 1 branch
BranchTrueFalseTotal
if ($closed_reason) 0 853 853
129 0 Carp::croak(
130 qq{Context of "$flow" cannot be changed:\n},
131 qq{ Reason: $closed_reason\n},
132 qq{ Problem was in this line: }, $Marpa::R2::HTML::Config::Compile::LINE
133 );
134 } ## end if ($closed_reason)
135 853 $closed_reason = $group_entry->[CONTENTS_CLOSED];
136 853 ▶ if ($closed_reason) {
Branch: 1 branch
BranchTrueFalseTotal
if ($closed_reason) 0 853 853
137 0 Carp::croak(
138 qq{Contents of "$group" cannot be changed:\n},
139 qq{ Reason: $closed_reason\n},
140 qq{ Problem was in this line: }, $Marpa::R2::HTML::Config::Compile::LINE
141 );
142 } ## end if ($closed_reason)
143  
144 Carp::croak(
145 853 ▶ qq{Contents of "$element" are already being defined:\n},
Branch: 1 branch
BranchTrueFalseTotal
if defined $element_entry->[3] 0 853 853
146 qq{ Problem was in this line: },
147 $Marpa::R2::HTML::Config::Compile::LINE
148 ) if defined $element_entry->[CONTENTS];
149 853 ▶ Carp::croak(
Branch: 1 branch
BranchTrueFalseTotal
if defined $element_entry->[2] 0 853 853
150 qq{Context of "$element" is already being defined:\n},
151 qq{ Problem was in this line: },
152 $Marpa::R2::HTML::Config::Compile::LINE
153 ) if defined $element_entry->[CONTEXT];
154  
155 # Always sets the primary group
156 853 my $primary_group_by_tag = $self->{primary_group_by_tag};
157 853 $primary_group_by_tag->{$tag} = $group;
158 853 $element_entry->[CONTENTS] = $flow;
159 853 $element_entry->[CONTEXT] = $group;
160 853 $element_entry->[CONTEXT_CLOSED] = $element_entry->[CONTENTS_CLOSED] =
161 'Element is already fully defined';
162  
163 853 return;
164 } ## end sub do_is_a_included
165  
166 sub do_is_statement {
167  
168 132 ▶ my ( $self, $external_element, undef, $external_flow ) = @_;
Subroutine do_is_statement: called CC=6 SCAR=18.3
Pod undocumented
169 132 my $tag = $external_element;
170 132 $tag =~ s/\A [<] \s* //xms;
171 132 $tag =~ s/\s* [>] \z //xms;
172 132 ( my $flow_name = $external_flow ) =~ s/\A [*] //xms;
173 132 my $flow = 'FLO_' . $flow_name;
174 132 my $element = 'ELE_' . $tag;
175 132 my $symbol_table = $self->{symbol_table};
176 132 ▶ my $element_entry = $symbol_table->{$element} //= [];
Condition100%2/2
$symbol_table->{$element} //= []
l!l
22110
MC/DC100%1/1
$symbol_table->{$element} //= []
$symbol_table->{$element}
Truth table100%2/2
A
A= $symbol_table->{$element}
Aresult
11
00
177 132 my $flow_entry = $symbol_table->{$flow};
178  
179 # For now, new flows cannot be defined
180 132 ▶ Carp::croak(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $flow_entry 0 132 132
181 qq{Flow "$flow" does not exist\n},
182 qq{ Problem was in this line: },
183 $Marpa::R2::HTML::Config::Compile::LINE
184 ) if not defined $flow_entry;
185  
186 132 my $closed_reason = $element_entry->[CONTENTS_CLOSED];
187 132 ▶ if ($closed_reason) {
Branch: 1 branch
BranchTrueFalseTotal
if ($closed_reason) 0 132 132
188 0 Carp::croak(
189 qq{Contents of "$element" cannot be changed:\n},
190 qq{ Reason: $closed_reason\n},
191 qq{ Problem was in this line: },
192 $Marpa::R2::HTML::Config::Compile::LINE
193 );
194 } ## end if ($closed_reason)
195 132 $closed_reason = $flow_entry->[CONTEXT_CLOSED];
196 132 ▶ if ($closed_reason) {
Branch: 1 branch
BranchTrueFalseTotal
if ($closed_reason) 0 132 132
197 0 Carp::croak(
198 qq{Context of "$flow" cannot be changed:\n},
199 qq{ Reason: $closed_reason\n},
200 qq{ Problem was in this line: },
201 $Marpa::R2::HTML::Config::Compile::LINE
202 );
203 } ## end if ($closed_reason)
204  
205 Carp::croak(
206 132 ▶ qq{Contents of "$element" are already being defined:\n},
Branch: 1 branch
BranchTrueFalseTotal
if defined $element_entry->[3] 0 132 132
207 qq{ Problem was in this line: },
208 $Marpa::R2::HTML::Config::Compile::LINE
209 ) if defined $element_entry->[CONTENTS];
210  
211 132 $element_entry->[CONTENTS] = $flow;
212 132 $element_entry->[CONTENTS_CLOSED] =
213 'Contents of Element are already defined';
214  
215 132 return;
216 } ## end sub do_is
217  
218 sub problem_in_rule {
219 0 ▶ my ($string) = @_;
Subroutine problem_in_rule: not called CC=1 SCAR=6.9
Pod undocumented
220 0 Marpa::R2::Context::bail( [ 'rule', $string, Marpa::R2::Context::location() ] );
221 }
222  
223 sub do_contains_statement {
224 187 ▶ my ( $self, $external_element, undef, $external_contents ) = @_;
Subroutine do_contains_statement: called CC=10 SCAR=23.5
Pod undocumented
225  
226 # Production is Element with custom flow
227 187 my $tag = $external_element;
228 187 $tag =~ s/\A [<] \s* //xms;
229 187 $tag =~ s/\s* [>] \z //xms;
230 187 my $element_symbol = 'ELE_' . $tag;
231 187 my $symbol_table = $self->{symbol_table};
232 187 ▶ my $element_entry = $symbol_table->{$element_symbol} //= [];
Condition100%2/2
$symbol_table->{$element_symbol} //= []
l!l
11176
MC/DC100%1/1
$symbol_table->{$element_symbol} //= []
$symbol_table->{$element_symbol}
Truth table100%2/2
A
A= $symbol_table->{$element_symbol}
Aresult
11
00
233 187 my $closed_reason = $element_entry->[CONTENTS_CLOSED];
234 187 ▶ if ($closed_reason) {
Branch: 1 branch
BranchTrueFalseTotal
if ($closed_reason) 0 187 187
235 0 Carp::croak(
236 qq{Contents of "$element_symbol" cannot be changed:\n},
237 qq{ Reason: $closed_reason\n},
238 qq{ Problem was in this line: },
239 $Marpa::R2::HTML::Config::Compile::LINE
240 );
241 } ## end if ($closed_reason)
242  
243 187 my @contents = ();
244  
245 CONTAINED_SYMBOL:
246 187 for my $external_content_symbol (@{$external_contents}) {
247 297 my $content_symbol;
248 297 ▶ if ( $external_content_symbol =~ /\A [<] (\w+) [>] \z/xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($external_content_symbol =~ /\A [<] (\w+) [>] \z/msx) 264 33 297
249 264 $content_symbol = 'ELE_' . $1;
250 }
251 297 ▶ if ( $external_content_symbol =~ /\A [%] (\w+) \z/xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($external_content_symbol =~ /\A [%] (\w+) \z/msx) 33 264 297
252 33 $content_symbol = 'GRP_' . $1;
253 }
254 297 ▶ $content_symbol //= $external_content_symbol;
Condition33%1/3
$content_symbol //= $external_content_symbol
l!l&&r!l&&!r
29700
MC/DC0%0/2
$content_symbol //= $external_content_symbol
$content_symbol $external_content_symbol
Truth table33%1/3
A //= B
A= $content_symbolB= $external_content_symbol
ABresult
1X1
011
000
255 297 my $content_entry = $symbol_table->{$content_symbol};
256 297 ▶ if ( not defined $content_entry ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $content_entry) 121 176 297
257 121 ▶ if ( not $content_symbol =~ /\A ELE_ /xms ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($content_symbol =~ /\A ELE_ /msx) 0 121 121
258 0 problem_in_rule(
259 qq{Symbol "$external_content_symbol" is undefined\n});
260 }
261 121 $content_entry = [];
262 } ## end if ( not defined $content_entry )
263 297 $closed_reason = $content_entry->[CONTEXT_CLOSED];
264 297 ▶ if ($closed_reason) {
Branch: 1 branch
BranchTrueFalseTotal
if ($closed_reason) 0 297 297
265 0 Carp::croak(
266 qq{Context of "$external_content_symbol" cannot be changed:\n},
267 qq{ Reason: $closed_reason\n},
268 qq{ Problem was in this line: },
269 $Marpa::R2::HTML::Config::Compile::LINE
270 );
271 } ## end if ($closed_reason)
272 297 push @contents, $content_symbol;
273 } ## end CONTAINED_SYMBOL: for my $external_content_symbol (@external_contents)
274  
275 187 push @{ $element_entry->[CONTENTS] }, @contents;
276  
277 187 return;
278  
279 } ## end sub do_contains
280  
281 sub do_array_assignment {
282 33 ▶ my ( $self, $external_list, undef, $external_members ) = @_;
Subroutine do_array_assignment: called CC=5 SCAR=16.1
Pod undocumented
283 33 ( my $new_list = $external_list ) =~ s/\A [@] //xms;
284 33 my $lists = $self->{lists};
285 Carp::croak(
286 "Problem in line: ", $Marpa::R2::HTML::Config::Compile::LINE,
287 "\n", 'list @' . $new_list . ' is already defined'
288 33 ▶ ) if defined $lists->{$new_list};
Branch: 1 branch
BranchTrueFalseTotal
if defined $lists->{$new_list} 0 33 33
289 33 my @members = ();
290 33 RAW_MEMBER: for my $raw_member (@{$external_members}) {
291 110 ▶ if ( $raw_member =~ / \A [@] (.*) \z/xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($raw_member =~ / \A [\@] (.*) \z/msx) 11 99 110
292 11 my $member_list = $1;
293 Carp::croak(
294 "Problem in line: ",
295 $Marpa::R2::HTML::Config::Compile::LINE,
296 "\n",
297 'member list @' . $member_list . ' is not yet defined'
298 11 ▶ ) if not defined $lists->{$member_list};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lists->{$member_list} 0 11 11
299 11 push @members, @{ $lists->{$member_list} };
300 11 next RAW_MEMBER;
301 } ## end if ( $raw_member =~ / \A [@] (.*) \z/xms )
302 99 push @members, $raw_member;
303 } ## end RAW_MEMBER: for my $raw_member (@{$external_members})
304 33 $lists->{$new_list} = \@members;
305 33 return;
306 } ## end sub do_array_assignment
307  
308 sub do_ruby_statement {
309 296 ▶ my ( $self, $external_reject_symbol, undef, $external_candidates ) = @_;
Subroutine do_ruby_statement: called CC=13 SCAR=25.8
Pod undocumented
310 296 my $lists = $self->{lists};
311 296 my @symbols = ($external_reject_symbol);
312 296 RAW_CANDIDATE: for my $raw_candidate ( @{$external_candidates} ) {
313 733 ▶ if ( $raw_candidate =~ / \A [@] (.*) \z/xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($raw_candidate =~ / \A [\@] (.*) \z/msx) 242 491 733
314 242 my $list = $1;
315 Carp::croak(
316 "Problem in line: ",
317 $Marpa::R2::HTML::Config::Compile::LINE,
318 "\n", 'candidate list @' . $list . ' is not yet defined'
319 242 ▶ ) if not defined $lists->{$list};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lists->{$list} 0 242 242
320 242 push @symbols, @{ $lists->{$list} };
321 242 next RAW_CANDIDATE;
322 } ## end if ( $raw_candidate =~ / \A [@] (.*) \z/xms )
323 491 push @symbols, $raw_candidate;
324 } ## end RAW_CANDIDATE: for my $raw_candidate ( @{$external_candidates} )
325 296 my @internal_symbols = ();
326 296 SYMBOL: for my $symbol (@symbols) {
327 1722 ▶ if ( $symbol eq 'CDATA' or $symbol eq 'PCDATA' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($symbol eq "CDATA" or $symbol eq "PCDATA") 22 1700 1722
Condition100%3/3
$symbol eq "CDATA" or $symbol eq "PCDATA"
l!l&&r!l&&!r
11111700
MC/DC100%2/2
$symbol eq "CDATA" or $symbol eq "PCDATA"
$symbol eq "CDATA" $symbol eq "PCDATA"
Truth table100%3/3
A or B
A= $symbol eq "CDATA"B= $symbol eq "PCDATA"
ABresult
1X1
011
000
328 22 push @internal_symbols, $symbol;
329 22 next SYMBOL;
330 }
331 1700 ▶ if ( $symbol =~ /\A ( [<] [%] (inline|head|block) [>] ) \z/xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($symbol =~ /\A ( [<] [%] (inline|head|block) [>] ) \z/msx) 22 1678 1700
332 22 my $special_symbol = $1;
333 22 push @internal_symbols, $special_symbol;
334 22 next SYMBOL;
335 }
336 1678 ▶ if ( $symbol =~ m{\A ( [<] [/] [%] (inline|head|block) [>] ) \z}xms )
Branch: 1 branch
BranchTrueFalseTotal
if ($symbol =~ m[\A ( [<] [/] [%] (inline|head|block) [>] ) \z]msx) 0 1678 1678
337 {
338 0 my $special_symbol = $1;
339 0 push @internal_symbols, $special_symbol;
340 0 next SYMBOL;
341 } ## end if ( $symbol =~ ...)
342 1678 ▶ if ( $symbol =~ m{\A ( [<] [*] [>] ) \z}xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($symbol =~ /\A ( [<] [*] [>] ) \z/msx) 11 1667 1678
343 11 my $special_symbol = $1;
344 11 push @internal_symbols, $special_symbol;
345 11 next SYMBOL;
346 }
347 1667 ▶ if ( $symbol =~ m{\A ( [<] [/] [*] [>] ) \z}xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($symbol =~ m[\A ( [<] [/] [*] [>] ) \z]msx) 132 1535 1667
348 132 my $special_symbol = $1;
349 132 push @internal_symbols, $special_symbol;
350 132 next SYMBOL;
351 }
352 1535 ▶ if ( $symbol =~ /\A [<] (\w+) [>] \z/xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($symbol =~ /\A [<] (\w+) [>] \z/msx) 1493 42 1535
353 1493 my $start_tag = 'S_' . $1;
354 1493 push @internal_symbols, $start_tag;
355 1493 next SYMBOL;
356 }
357 42 ▶ if ( $symbol =~ m{\A [<] [/](\w+) [>] \z}xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($symbol =~ m[\A [<] [/](\w+) [>] \z]msx) 42 0 42
358 42 my $end_tag = 'E_' . $1;
359 42 push @internal_symbols, $end_tag;
360 42 next SYMBOL;
361 }
362 Carp::croak(
363 0 "Problem in line: ",
364 $Marpa::R2::HTML::Config::Compile::LINE,
365 "\n", qq{Misformed symbol "$symbol"}
366 );
367 } ## end SYMBOL: for my $symbol (@symbols)
368 296 my $rejected_symbol = shift @internal_symbols;
369 296 $self->{ruby_config}->{$rejected_symbol} = \@internal_symbols;
370 296 return;
371 } ## end sub do_ruby_statement
372  
373 sub die_on_read_problem {
374 0 ▶ my ( $rec, $t, $token_value, $string, $position ) = @_;
Subroutine die_on_read_problem: not called CC=3 SCAR=24.8
Pod undocumented
375 0 ▶ say $rec->show_progress() or die "say failed: $ERRNO";
Branch: 1 branch
BranchTrueFalseTotal
say $rec->show_progress or die "say failed: $Marpa::R2::HTML::Config::Compile::ERRNO" 0 0 0
376 0 my $problem_position = $position - length $1;
377 0 my $before_start = $problem_position - 40;
378 0 ▶ $before_start = 0 if $before_start < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $before_start < 0 0 0 0
379 0 my $before_length = $problem_position - $before_start;
380 0 die "Problem near position $problem_position\n",
381 q{Problem is here: "},
382 ( substr $string, $before_start, $before_length + 40 ),
383 qq{"\n},
384 ( q{ } x ( $before_length + 18 ) ), qq{^\n},
385 q{Token rejected, "}, $t->[0], qq{", "$token_value"},
386 ;
387 } ## end sub die_on_read_problem
388  
389 516 ▶sub do_array { shift; return [@_]; }
Subroutine do_array: called CC=1 SCAR=0.0
Pod undocumented
390  
391 sub do_what_I_mean {
392  
393 # The first argument is the per-parse variable.
394 # At this stage, just throw it away
395 4703 ▶ shift;
Subroutine do_what_I_mean: called CC=2 SCAR=7.0
Pod undocumented
396  
397 # Throw away any undef's
398 4703 my @children = grep { defined } @_;
399  
400 # Return what's left
401 4703 ▶ return scalar @children > 1 ? \@children : shift @children;
Branch: 1 branch
BranchTrueFalseTotal
scalar @children > 1 ? : 0 4703 4703
402 }
403  
404 # Order matters !!
405 11 my @terminals = (
406 [ kw_CDATA => qr/CDATA\b/xms ],
407 [ kw_PCDATA => qr/PCDATA\b/xms ],
408 [ kw_is => qr/is\b/ixms ],
409 [ kw_a => qr/a\b/ixms ],
410 [ kw_contains => qr/contains\b/ixms ],
411 [ kw_included => qr/included\b/ixms ],
412 [ kw_in => qr/in\b/ixms ],
413 [ flow => qr/[*]\w+\b/xms ],
414 [ group => qr/[%]\w+\b/xms ],
415 [ list => qr/[@]\w+\b/xms ],
416 [ start_tag => qr/[<]\w+[>]/xms ],
417 [ end_tag => qr{[<][/]\w+[>]}xms ],
418 [ wildcard_start_tag => qr/[<][*][>]/xms ],
419 [ wildcard_end_tag => qr{[<][/][*][>]}xms ],
420 [ group_start_tag => qr/[<][%]\w+[>]/xms ],
421 [ group_end_tag => qr/[<][%]\w+[>]/xms ],
422 [ op_assign => qr/[=]/xms ],
423 [ op_ruby => qr/[-][>]/xms ],
424 [ semi_colon => qr/[;]/xms ],
425 );
426  
427 sub create_grammar {
428  
429 11 ▶my $source = <<'END_OF_GRAMMAR';
Subroutine create_grammar: called CC=1 SCAR=0.0
Pod undocumented
430 translation_unit ::= statement*
431 statement ::= is_included_statement
432 | is_a_included_statement
433 | is_statement
434 | contains_statement
435 | list_assignment
436 | ruby_statement
437 is_included_statement ::= element kw_is kw_included kw_in <group>
438 action => do_is_included_statement
439 element ::= start_tag
440 is_a_included_statement ::= element kw_is kw_a flow kw_included kw_in <group>
441 action => do_is_a_included_statement
442 is_statement ::= element kw_is flow
443 action => do_is_statement
444 contains_statement ::= element kw_contains contents
445 action => do_contains_statement
446 contents ::= content_item*
447 action => do_array
448 list_assignment ::= list op_assign list_members
449 action => do_array_assignment
450 list_members ::= list_member*
451 action => do_array
452 list_member ::= ruby_symbol
453 list_member ::= list
454 content_item ::= element | <group> | kw_PCDATA | kw_CDATA
455 ruby_statement ::= ruby_symbol op_ruby ruby_symbol_list
456 action => do_ruby_statement
457 ruby_symbol_list ::= ruby_symbol*
458 action => do_array
459 ruby_symbol ::= kw_PCDATA | kw_CDATA
460 | start_tag | group_start_tag | wildcard_start_tag
461 | end_tag | group_end_tag | wildcard_end_tag
462 | list
463 END_OF_GRAMMAR
464
465 11 my $grammar = Marpa::R2::Grammar->new(
466 { start => 'translation_unit',
467 action_object => __PACKAGE__,
468 rules =>$source,
469 default_action => 'do_what_I_mean'
470 }
471 );
472 11 $grammar->precompute();
473 11 return $grammar;
474 }
475  
476 sub source_by_location_range {
477 0 ▶ my ( $self, $start, $end ) = @_;
Subroutine source_by_location_range: not called CC=2 SCAR=17.9
Pod undocumented
478 0 my $positions = $self->{positions};
479 0 ▶ my $start_pos = $start > 0 ? $positions->[$start] : 0;
Branch: 1 branch
BranchTrueFalseTotal
$start > 0 ? : 0 0 0
480 0 my $end_pos = $positions->[$end];
481 0 return substr ${ $self->{source_ref} }, $start_pos, $end_pos - $start_pos;
482 } ## end sub source_by_location_range
483  
484 sub compile {
485 11 ▶ my ($source_ref) = @_;
Subroutine compile: called CC=64 SCAR=43.1
Pod undocumented
486  
487 # A quasi-object, not used outside this routine
488 11 my $self = bless {}, __PACKAGE__;
489  
490 11 my %species_handler = (
491 cruft => 'SPE_CRUFT',
492 comment => 'SPE_COMMENT',
493 pi => 'SPE_PI',
494 decl => 'SPE_DECL',
495 document => 'SPE_TOP',
496 whitespace => 'SPE_WHITESPACE',
497 pcdata => 'SPE_PCDATA',
498 cdata => 'SPE_CDATA',
499 prolog => 'SPE_PROLOG',
500 trailer => 'SPE_TRAILER',
501 );
502  
503 11 my @core_rules = ();
504 11 my %runtime_tag = ();
505 11 my %primary_group_by_tag = ();
506 11 $self->{primary_group_by_tag} = \%primary_group_by_tag;
507  
508 {
509 11 LINE:
510 11 for my $line ( split /\n/xms,
511 $Marpa::R2::HTML::Internal::Core::CORE_BNF )
512 {
513 726 my $definition = $line;
514 726 chomp $definition;
515 726 $definition =~ s/ [#] .* //xms; # Remove comments
516 next LINE
517 726 ▶ if not $definition =~ / \S /xms; # ignore all-whitespace line
Branch: 1 branch
BranchTrueFalseTotal
unless $definition =~ / \S /msx 286 440 726
518 440 my $sequence = ( $definition =~ s/ [*] \s* $//xms );
519 440 ▶ if ( $definition =~ s/ \s* [:][:][=] \s* / /xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($definition =~ s/ \s* [:][:][=] \s* / /msx) 440 0 440
520  
521 # Production is Ordinary BNF rule
522 440 my @symbols = ( split q{ }, $definition );
523 440 my $lhs = shift @symbols;
524 440 my %rule_descriptor = (
525 lhs => $lhs,
526 rhs => \@symbols,
527 );
528 440 ▶ if ($sequence) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sequence) 77 363 440
529 77 $rule_descriptor{min} = 0;
530 }
531 440 ▶ if ( my $handler = $species_handler{$lhs} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $handler = $species_handler{$lhs}) { } 110 330 440
elsif ($lhs =~ /^ELE_/msx) { } 11 319 330
532 110 $rule_descriptor{action} = $handler;
533 }
534 elsif ( $lhs =~ /^ELE_/xms ) {
535 11 $rule_descriptor{action} = "$lhs";
536 }
537 440 push @core_rules, \%rule_descriptor;
538 440 next LINE;
539 } ## end if ( $definition =~ s/ \s* [:][:][=] \s* / /xms )
540 0 die "Badly formed line in grammar description: $line";
541 } ## end LINE: for my $line ( split /\n/xms, ...)
542 }
543  
544 11 my @core_symbols = map { ( $_->{lhs}, @{ $_->{rhs} } ) } @core_rules;
545  
546 # Start out by closing the context and contents of everything
547 my %symbol_table = map {
548 11 $_ =>
549 [ 'Reserved by the core grammar', 'Reserved by the core grammar' ]
550 } @core_symbols;
551 11 $self->{symbol_table} = \%symbol_table;
552  
553 # A few token symbols are allowed as contents -- most non-element
554 # tokens are included via the SGML group
555 11 for my $token_symbol (qw(cdata pcdata)) {
556 22 $symbol_table{$token_symbol}->[CONTEXT_CLOSED] = 0;
557 }
558  
559 # Many groups are defined to to be used
560 11 for my $group_symbol (
561 qw( GRP_anywhere GRP_pcdata GRP_cdata GRP_mixed GRP_block GRP_head GRP_inline)
562 )
563 {
564 77 $symbol_table{$group_symbol}->[CONTEXT_CLOSED] = 0;
565 } ## end for my $group_symbol ( ...)
566  
567 # Flow symbols are almost all allowed as contents
568 FLOW_SYMBOL:
569 11 for my $flow_symbol ( grep { $_ =~ m/\A FLO_ /xms } @core_symbols ) {
570  
571 # The SGML flow is included automatically as needed
572 # and should not be explicity specified
573 143 ▶ next FLOW_SYMBOL if $flow_symbol eq 'FLO_SGML';
Branch: 1 branch
BranchTrueFalseTotal
if $flow_symbol eq "FLO_SGML" 66 77 143
574 77 $symbol_table{$flow_symbol}->[CONTEXT_CLOSED] = 0;
575 } ## end for my $flow_symbol ( grep { $_ =~ m/\A FLO_ /xms } ...)
576  
577 # A few groups are also extensible
578 11 for my $group_symbol (qw( GRP_anywhere GRP_block GRP_head GRP_inline )) {
579 44 $symbol_table{$group_symbol}->[CONTENTS_CLOSED] = 0;
580 }
581  
582 # As very special cases the contents of the <head> and <body>
583 # elements can be changed
584 11 for my $element_symbol (qw( ELE_head ELE_body )) {
585 22 $symbol_table{$element_symbol}->[CONTENTS_CLOSED] = 0;
586 }
587  
588 {
589 # Make sure everything for which we have a handler was defined in
590 # the core grammar
591 11 my @species_not_defined = grep { not defined $symbol_table{$_} }
592 keys %species_handler;
593 11 ▶ if ( scalar @species_not_defined ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @species_not_defined) 0 11 11
594 0 die
595 'Definitions for the following required text components are missing: ',
596 join q{ }, @species_not_defined;
597 }
598 }
599  
600 11 my %ruby_config = ();
601 11 my %lists = ();
602 11 $self->{ruby_config} = \%ruby_config;
603 11 $self->{lists} = \%lists;
604 11 $self->{source_ref} = $source_ref;
605 11 my @positions = (0);
606 11 $self->{positions} = \@positions;
607  
608 11 state $grammar = create_grammar();
609 11 my $recce = Marpa::R2::Recognizer->new({ grammar => $grammar});
610 11 my $string = ${$source_ref};
611 11 my $length = length $string;
612 11 pos $string = 0;
613 11 ▶ TOKEN: while ( pos $string < $length ) {
Branch: 1 branch
BranchTrueFalseTotal
if (pos $string < $length) 18348 11 18359
614  
615 # skip comment
616 18348 ▶ next TOKEN if $string =~ m/\G \s* [#] [^\n]* \n/gcxms;
Branch: 1 branch
BranchTrueFalseTotal
if $string =~ /\G \s* [#] [^\n]* \n/cgmsx 187 18161 18348
617  
618 # skip whitespace
619 18161 ▶ next TOKEN if $string =~ m/\G\s+/gcxms;
Branch: 1 branch
BranchTrueFalseTotal
if $string =~ /\G\s+/cgmsx 9072 9089 18161
620  
621 # read other tokens
622 9089 TOKEN_TYPE: for my $t (@terminals) {
623 72835 ▶ next TOKEN_TYPE if not $string =~ m/\G($t->[1])/gcxms;
Branch: 1 branch
BranchTrueFalseTotal
unless $string =~ /\G($t->[1])/cgmsx 63746 9089 72835
624 # say join " ", $t->[0], '->', $1;
625 9089 ▶ if ( not defined $recce->read( $t->[0], $1 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $recce->read($t->[0], $1)) 0 9089 9089
626 0 die_on_read_problem( $recce, $t, $1, $string, pos $string );
627 }
628 9089 my $latest_earley_set = $recce->latest_earley_set();
629 9089 $positions[$latest_earley_set] = pos $string;
630 9089 next TOKEN;
631 } ## end TOKEN_TYPE: for my $t (@terminals)
632  
633 0 die q{No token at "}, ( substr $string, pos $string, 40 ),
634 q{", position }, pos $string;
635 } ## end TOKEN: while ( pos $string < $length )
636  
637 # Value not used
638 11 my $parse_value_ref;
639 11 my $eval_ok = eval {
640  
641 # Have the new() just return the current $self
642 11 ▶ local *new = sub { return $self };
Subroutine __ANON__: called CC=1 SCAR=0.0
643 11 $parse_value_ref = $recce->value();
644 11 1;
645 };
646 11 ▶ if ( not defined $eval_ok ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $eval_ok) 0 11 11
647 0 my $eval_ref_type = ref $EVAL_ERROR;
648 0 ▶ die $EVAL_ERROR if not $eval_ref_type;
Branch: 1 branch
BranchTrueFalseTotal
unless $eval_ref_type 0 0 0
649 0 ▶ if ( $eval_ref_type eq 'ARRAY' and $EVAL_ERROR->[0] eq 'rule' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($eval_ref_type eq "ARRAY" and $Marpa::R2::HTML::Config::Compile::EVAL_ERROR->[0] eq "rule") 0 0 0
Condition0%0/3
$eval_ref_type eq "ARRAY" and $Marpa::R2::HTML::Config::Compile::EVAL_ERROR->[0] eq "rule"
!ll&&!rl&&r
000
MC/DC0%0/2
$eval_ref_type eq "ARRAY" and $Marpa::R2::HTML::Config::Compile::EVAL_ERROR->[0] eq "rule"
$eval_ref_type eq "ARRAY" $Marpa::R2::HTML::Config::Compile::EVAL_ERROR->[0] eq "rule"
Truth table0%0/3
A and B
A= $eval_ref_type eq "ARRAY"B= $Marpa::R2::HTML::Config::Compile::EVAL_ERROR->[0] eq "rule"
ABresult
0X0
100
111
650 0 my ( undef, $message, $start, $end ) = @{$EVAL_ERROR};
651 0 chomp $message;
652 0 die $message, "\n",
653 "Rule with problem was: ",
654 $self->source_by_location_range( $start, $end ), "\n";
655 } ## end if ( $eval_ref_type eq 'ARRAY' and $EVAL_ERROR->[0] ...)
656 0 die "Unknown exception: ", Data::Dumper::Dumper($EVAL_ERROR);
657 } ## end if ( not defined $eval_ok )
658 11 ▶ if ( not defined $parse_value_ref ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $parse_value_ref) 0 11 11
659 0 die "Compile of HTML configuration failed: source did not parse";
660 }
661  
662 11 my %sgml_flow_included = ();
663 11 SYMBOL: for my $element_symbol ( keys %symbol_table ) {
664 1579 ▶ next SYMBOL if not 'ELE_' eq substr $element_symbol, 0, 4;
Branch: 1 branch
BranchTrueFalseTotal
unless "ELE_" eq substr($element_symbol, 0, 4) 407 1172 1579
665 1172 my $tag = substr $element_symbol, 4;
666 1172 my $entry = $symbol_table{$element_symbol};
667 1172 my $context = $entry->[CONTEXT];
668 1172 my $contents = $entry->[CONTENTS];
669 1172 ▶ next SYMBOL if not defined $context and not defined $contents;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $context or defined $contents 11 1161 1172
Condition100%3/3
defined $context or defined $contents
l!l&&r!l&&!r
96319811
MC/DC100%2/2
defined $context or defined $contents
defined $context defined $contents
Truth table100%3/3
A or B
A= defined $contextB= defined $contents
ABresult
1X1
011
000
670 1161 ▶ if ( defined $context and not defined $contents ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $context and not defined $contents) 0 1161 1161
Condition66%2/3
defined $context and not defined $contents
!ll&&!rl&&r
1989630
MC/DC0%0/2
defined $context and not defined $contents
defined $context not defined $contents
Truth table66%2/3
A and not(B)
A= defined $contextB= not defined $contents
ABresult
0X0
100
111
671 0 Carp::croak(
672 qq{Element <$tag> was defined but was never given any contents}
673 );
674 }
675  
676 # Contents without context are OK at this point
677 # We will check later for elements defined but not used
678 1161 ▶ $context //= [];
Condition100%2/2
$context //= []
l!l
963198
MC/DC100%1/1
$context //= []
$context
Truth table100%2/2
A
A= $context
Aresult
11
00
679  
680 # The special case where both are defined and both
681 # are scalars is for elements to be created at runtime
682 1161 ▶ if ( not ref $context and not ref $contents ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $context or ref $contents) 853 308 1161
Condition66%2/3
ref $context or ref $contents
l!l&&r!l&&!r
3080853
MC/DC50%1/2
ref $context or ref $contents
ref $context ref $contents
Truth table66%2/3
A or B
A= ref $contextB= ref $contents
ABresult
1X1
011
000
683 853 $runtime_tag{$tag} = $contents;
684 853 next SYMBOL;
685 }
686  
687 308 ▶ if ( ref $contents ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $contents) { } 176 132 308
688 176 my $contents_symbol = 'Contents_ELE_' . $tag;
689 176 my $item_symbol = 'GRP_ELE_' . $tag;
690 176 push @core_rules,
691 {
692 lhs => $element_symbol,
693 rhs => [ "S_$tag", $contents_symbol, "E_$tag" ],
694 action => $element_symbol,
695 },
696 {
697 lhs => $contents_symbol,
698 rhs => [$item_symbol],
699 min => 0
700 };
701 176 for my $content_item ( @{$contents} ) {
702 297 push @core_rules,
703 {
704 lhs => $item_symbol,
705 rhs => [$content_item],
706 };
707 } ## end for my $content_item ( @{$contents} )
708 176 ▶ if ( !$sgml_flow_included{$item_symbol} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sgml_flow_included{$item_symbol}) 176 0 176
709 176 $sgml_flow_included{$item_symbol} = 1;
710 176 push @core_rules,
711 {
712 lhs => $item_symbol,
713 rhs => ['GRP_SGML'],
714 };
715 } ## end if ( !$sgml_flow_included{$item_symbol} )
716 } ## end if ( ref $contents )
717 else {
718 132 push @core_rules,
719 {
720 lhs => $element_symbol,
721 rhs => [ "S_$tag", $contents, "E_$tag" ],
722 action => $element_symbol,
723 };
724 } ## end else [ if ( ref $contents ) ]
725  
726 308 ▶ $context = [$context] if not ref $context;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $context 0 308 308
727 308 for my $context_item ( @{$context} ) {
728 110 push @core_rules,
729 {
730 lhs => $context_item,
731 rhs => [$element_symbol],
732 };
733 } ## end for my $context_item ( @{$context} )
734 } ## end SYMBOL: for my $element_symbol ( keys %symbol_table )
735  
736 # Finish out the Ruby Slippers configuration
737 # Make sure the last resort defaults are always defined
738 11 for my $required_rubies_desc (qw( <*> </*> <!element> )) {
739 33 ▶ $ruby_config{$required_rubies_desc} //= [];
Condition100%2/2
$ruby_config{$required_rubies_desc} //= []
l!l
1122
MC/DC100%1/1
$ruby_config{$required_rubies_desc} //= []
$ruby_config{$required_rubies_desc}
Truth table100%2/2
A
A= $ruby_config{$required_rubies_desc}
Aresult
11
00
740 }
741  
742 11 DESC: for my $rubies_desc ( keys %ruby_config ) {
743 318 my $candidates = $ruby_config{$rubies_desc};
744 318 ▶ next DESC if grep { '</*>' eq $_ } @{$candidates};
Branch: 1 branch
BranchTrueFalseTotal
if grep {"</*>" eq $_;} @{$candidates;} 132 186 318
745 186 $ruby_config{$rubies_desc} = [ @{$candidates}, '</*>' ];
746 }
747  
748 11 my %is_empty_element = ();
749 {
750 11 for my $tag ( keys %runtime_tag ) {
751 853 my $contents = $runtime_tag{$tag};
752 853 ▶ $is_empty_element{$tag} = 1 if $contents eq 'FLO_empty';
Branch: 1 branch
BranchTrueFalseTotal
if $contents eq "FLO_empty" 100 753 853
753 }
754 11 RULE: for my $rule (@core_rules) {
755 1507 my $lhs = $rule->{lhs};
756 1507 ▶ next RULE if not 'ELE_' eq substr $lhs, 0, 4;
Branch: 1 branch
BranchTrueFalseTotal
unless "ELE_" eq substr($lhs, 0, 4) 1188 319 1507
757 319 my $contents = $rule->{rhs}->[1];
758 319 ▶ $is_empty_element{ substr $lhs, 4 } = 1
Branch: 1 branch
BranchTrueFalseTotal
if $contents eq "FLO_empty" 34 285 319
759 if $contents eq 'FLO_empty';
760 } ## end RULE: for my $rule (@core_rules)
761 }
762  
763 {
764 # Make sure no ruby candidates or rejected symbols are
765 # end tags of empty elements
766 11 SYMBOL: for my $rejected_symbol ( keys %ruby_config ) {
767 318 ▶ next SYMBOL if 'E_' ne substr $rejected_symbol, 0, 2;
Branch: 1 branch
BranchTrueFalseTotal
if "E_" ne substr($rejected_symbol, 0, 2) 286 32 318
768 32 my $tag = substr $rejected_symbol, 2;
769 32 ▶ next SYMBOL if not $is_empty_element{$tag};
Branch: 1 branch
BranchTrueFalseTotal
unless $is_empty_element{$tag} 32 0 32
770 0 Carp::croak(
771 qq{Ruby Slippers alternatives specified for </$tag>\n},
772 qq{ "$tag" is an empty element and this is not allowed"}
773 );
774 } ## end SYMBOL: for my $rejected_symbol ( keys %ruby_config )
775 SYMBOL:
776 11 for my $candidate_symbol ( map { @{$_} } values %ruby_config ) {
777 1612 ▶ next SYMBOL if 'E_' ne substr $candidate_symbol, 0, 2;
Branch: 1 branch
BranchTrueFalseTotal
if "E_" ne substr($candidate_symbol, 0, 2) 1602 10 1612
778 10 my $tag = substr $candidate_symbol, 2;
779 10 ▶ next SYMBOL if not $is_empty_element{$tag};
Branch: 1 branch
BranchTrueFalseTotal
unless $is_empty_element{$tag} 10 0 10
780 0 Carp::croak(
781 qq{Tag </$tag> specified as a Ruby Slippers alternative\n},
782 qq{ "$tag" is an empty element and this is not allowed"}
783 );
784 } ## end for my $candidate_symbol ( map { @{$_} } values ...)
785 }
786  
787 # Special case the EOF Ruby Slippers treatment
788 {
789 11 @{ $ruby_config{EOF} } =
790 qw( S_html S_head S_body </*> E_body E_html );
791 }
792  
793 {
794 # Find the tag descriptors which refer to required
795 # elements and add them
796  
797 # Required elements are those which we may have to
798 # supply even though they are not in the physical input
799  
800 # Anything which has a start tag among the ruby candidates
801 # is required, since we may be required to create a
802 # non-physical one
803 11 my @ruby_start_tags =
804 1678 grep { ( substr $_, 0, 2 ) eq 'S_' }
805 11 map { @{$_} } values %ruby_config;
806  
807 my %defined_in_core_rules =
808 319 map { ( substr $_, 4 ) => 'core' }
809 11 grep {m/\A ELE_ /xms} map { $_->{lhs} } @core_rules;
810  
811 11 my %required_tags = map { ( substr $_, 2 ) => 1 } @ruby_start_tags;
812 11 TAG: for my $tag ( keys %required_tags ) {
813 154 ▶ next TAG if $defined_in_core_rules{$tag};
Branch: 1 branch
BranchTrueFalseTotal
if $defined_in_core_rules{$tag} 143 11 154
814 11 my $flow = $runtime_tag{$tag};
815 11 ▶ die qq{Required element "ELE_$tag" was never defined}
Branch: 1 branch
BranchTrueFalseTotal
unless defined $flow 0 11 11
816 if not defined $flow;
817 11 my $group = $primary_group_by_tag{$tag};
818 11 my $element = 'ELE_' . $tag;
819 11 push @core_rules,
820 {
821 lhs => $element,
822 rhs => [ "S_$tag", $flow, "E_$tag" ],
823 action => $element
824 },
825 {
826 lhs => $group,
827 rhs => [$element],
828 };
829 11 delete $runtime_tag{$tag};
830 } ## end TAG: for my $tag ( keys %required_tags )
831 }
832  
833 {
834 11 my @mentioned_in_core =
835 418 map { substr $_, 4 }
836 11 grep {m/\A ELE_ /xms} map { @{ $_->{rhs} } } @core_rules;
837 my %defined_in_core =
838 330 map { ( substr $_, 4 ) => 'core' }
839 11 grep {m/\A ELE_ /xms} map { $_->{lhs} } @core_rules;
840 my @symbols_with_no_ruby_status =
841 11 ▶ grep { !$defined_in_core{$_} and !$runtime_tag{$_} }
Condition33%1/3
$defined_in_core{$_} || $runtime_tag{$_}
l!l&&r!l&&!r
41800
MC/DC0%0/2
$defined_in_core{$_} || $runtime_tag{$_}
$defined_in_core{$_} $runtime_tag{$_}
Truth table33%1/3
A || B
A= $defined_in_core{$_}B= $runtime_tag{$_}
ABresult
1X1
011
000
842 @mentioned_in_core;
843 11 ▶ die 'symbols with no ruby status: ', join q{ },
Branch: 1 branch
BranchTrueFalseTotal
if scalar @symbols_with_no_ruby_status 0 11 11
844 @symbols_with_no_ruby_status
845 if scalar @symbols_with_no_ruby_status;
846 }
847  
848 # Calculate the numeric Ruby ranks
849 11 my %ruby_rank = ();
850 11 for my $rejected_symbol ( keys %ruby_config ) {
851 329 my $rank = 1;
852 329 for my $candidate ( reverse @{ $ruby_config{$rejected_symbol} } ) {
853 1678 $ruby_rank{$rejected_symbol}{$candidate} = $rank++;
854 }
855 } ## end for my $rejected_symbol ( keys %ruby_config )
856  
857 {
858 my %element_used =
859 418 map { ( $_ => 1 ) }
860 11 grep {m/\A ELE_ /xms} map { @{ $_->{rhs} } } @core_rules;
861 my @elements_defined_but_not_used =
862 330 grep { !$element_used{$_} }
863 11 grep {m/\A ELE_ /xms} map { $_->{lhs} } @core_rules;
864 11 ▶ die 'elements defined but never used: ', join q{ },
Branch: 1 branch
BranchTrueFalseTotal
if scalar @elements_defined_but_not_used 0 11 11
865 @elements_defined_but_not_used
866 if scalar @elements_defined_but_not_used;
867 }
868  
869 {
870 11 my %seen = ();
871 11 for my $rule (@core_rules) {
872 1529 my $lhs = $rule->{lhs};
873 1529 my $rhs = $rule->{rhs};
874 1529 my $desc = join q{ }, $lhs, '::=', @{$rhs};
875 1529 ▶ if ( $seen{$desc} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seen{$desc}) 0 1529 1529
876 0 Carp::croak("Duplicate rule: $desc");
877 }
878 1529 $seen{$desc}++;
879 } ## end for my $rule (@core_rules)
880 }
881  
882 return {
883 11 rules => \@core_rules,
884 runtime_tag => \%runtime_tag,
885 ruby_slippers_rank_by_name => \%ruby_rank,
886 is_empty_element => \%is_empty_element,
887 primary_group_by_tag => \%primary_group_by_tag
888 };
889  
890 } ## end sub compile
891  
892 11 1;
893  
894 # vim: expandtab shiftwidth=4:
« blib/lib/Marpa/R2/SLG.pm ↑ Summary blib/script/marpa_r2_html_fmt »