lib/MarpaX/G4/Parser.pm

filter: Statementstmt 58.0% 188 / 324 Branchbran 42.3% 66 / 156 Conditioncond 37.3% 28 / 75 MC/DCmcdc 14.5% 7 / 48 Subroutinesub 63.2% 31 / 49 Podpod 0.0% 0 / 4 totaltotal 48.7% 320 / 656 CC 109 SCAR 32.5
CC
109
Cov
51%
do_right_side
61.1
do_group
56.0
do_fragment
50.0
CRAP 25.7
« lib/MarpaX/G4/MarpaGen.pm ↑ Summary script/testmarpagrammar.pl »
1 # ----------------------------------------------------------------------------------------------------- #
2 # MarpaX::G4 #
3 # #
4 # a grammar for parsing antlr4 grammars and translating them to Marpa::R2 grammars. #
5 # #
6 # ----------------------------------------------------------------------------------------------------- #
7  
8 package MarpaX::G4::Parser;
9 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Marpa::R2 2.039_000;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 sub new
16 1 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
17 1 my ($class) = @_;
18  
19 1 my $self = bless {}, $class;
20  
21 1 $self->{grammarstate} = undef;
22  
23 1 $self->{grammar} = Marpa::R2::Scanless::G->new(
24 {
25 action_object => 'MarpaX::G4::Actions',
26 default_action => 'default_action',
27 source => \(<<'END_OF_SOURCE'),
28 lexeme default = latm => 1
29  
30 :start ::= g4grammar
31  
32 :discard ~ whitespace
33 whitespace ~ [\s]+
34  
35 g4grammar ::= grammarentry* action => do_grammar
36  
37 grammarentry ::= symbolrule
38 | fragmentrule
39 | grammarspec
40 | optionspec
41 | namedspec
42 | linecomment
43 | blockcomment
44  
45 symbolrule ::= name opt_return opt_comment (COLON) right_side action => do_single_rule
46  
47 right_side ::= rhs opt_hashcomment opt_comment end_rhs action => do_right_side
48 | opt_redir (SEMICOLON) action => do_empty_rule
49  
50 end_rhs ::= (BAR) right_side action => do_endrhs
51 | opt_redir (SEMICOLON) action => do_empty_rule
52  
53 rhs ::= nonterminal+ action => do_rhs
54  
55 nonterminal ::= opt_assoc rulecomponent opt_card action => do_nonterminal
56  
57 rulecomponent ::= token | group action => do_rulecomponent
58  
59 group ::= (LPAREN) opt_colon rhs grouplist opt_bar (RPAREN) action => do_group
60  
61 grouplist ::= groupelement* action => do_grouplist
62 groupelement ::= (BAR) rhs action => do_groupelement_alternative
63 | rhs action => do_groupelement_concat
64  
65 fragmentrule ::= (fragmentkeywd) opt_comment name opt_comment
66 (COLON) fragment_right_side action => do_fragment
67 fragmentkeywd ~ 'fragment'
68  
69 fragment_right_side ::= fragment_rhs opt_hashcomment opt_comment
70 fragment_end_rhs action => do_right_side
71 | (SEMICOLON)
72  
73 fragment_rhs ::= tokenlist action => do_rhs
74  
75 fragment_end_rhs ::= (BAR) fragment_right_side action => do_endrhs
76 | (SEMICOLON) action => do_empty_rule
77  
78 token ::= opt_neg literal action => do_token
79 | opt_neg tokengroup action => do_token
80 | name ALIASOP rulecomponent action => do_assignalias
81 | opt_neg name action => do_name
82 | range
83 | regex
84 | valueclause
85 | <Inline Action>
86 | linecomment
87 | blockcomment
88  
89 tokengroup ::= (LPAREN) opt_colon tokenlist (RPAREN) action => do_token_group
90 tokenlist ::= tokenelement+ action => do_token_list
91 tokenelement ::= (BAR) token opt_card action => do_tokenelement_alternative
92 | token opt_card action => do_tokenelement_concat
93  
94 range ::= literal (RANGEOP) literal action => do_range
95  
96 name ~ [a-zA-Z0-9_]+
97  
98 valueclause ::= (LANGLE) name (RANGLE) action => do_valueclause
99  
100 literal ::= lstring action => do_literal
101 | characterclass action => do_characterclass
102  
103 lstring ~ quote in_string quote
104 quote ~ [']
105 in_string ~ in_string_char*
106  
107 in_string_char ~ [^'\\]
108 | '\' [']
109 | '\' 'b'
110 | '\' 'f'
111 | '\' 'n'
112 | '\' 'r'
113 | '\' 't'
114 | '\' '/'
115 | '\' '*'
116 | '\' '#'
117 | '\\'
118 | '\' 'u' four_hex_digits
119 | '\' 'u' '{' hex_digits '}'
120 | '\' 'x' hex_digits
121  
122 # a dash ('-') character immediately following or preceding the opening/closing bracket counts as a dash not a range
123 characterclass ~ '[-' in_class ']'
124 | '[' in_class '-]'
125 | '[' in_class ']'
126 in_class ~ in_class_element+
127 in_class_element ~ in_class_char | in_class_range
128 in_class_range ~ in_class_char '-' in_class_char
129 in_class_char ~ [^-\]\\]
130 | '\' [^u]
131 | '\' 'u' four_hex_digits
132 | '\' 'u' '{' hex_digits '}'
133 | '\' 'x' hex_digits
134  
135 hex_digits ~ hex_digit+
136 four_hex_digits ~ hex_digit hex_digit hex_digit hex_digit
137 hex_digit ~ [0-9a-fA-F]
138  
139 regex ::= '.' regex_cardinality action => do_regex
140 regex_cardinality ::= cardinality*
141  
142 opt_assoc ::=
143 opt_assoc ::= assoc_clause
144 assoc_clause ~ '<assoc=' assoc_type '>'
145 assoc_type ~ 'left' | 'right' | 'group'
146  
147 opt_redir ::=
148 opt_redir ::= (redirect) redir_target redir_list action => do_redirect
149 redir_list ::= redir_suffix*
150 redir_suffix ::= COMMA redir_target
151 redir_target ::= name
152 | name (LPAREN) name (RPAREN)
153 redirect ~ '->'
154  
155 opt_bar ::=
156 opt_bar ::= BAR
157  
158 opt_colon ::=
159 opt_colon ::= COLON
160  
161 opt_neg ::=
162 opt_neg ::= negation
163 negation ~ '~'
164  
165 opt_card ::=
166 opt_card ::= cardinality
167 cardinality ~ [?*+]
168 | [*+] [?]
169  
170 grammarspec ::= opt_grammarprefix ('grammar') name (SEMICOLON) action => do_grammarspec
171 opt_grammarprefix ::=
172 opt_grammarprefix ::= 'lexer'
173 | 'parser'
174  
175 opt_return ::=
176 opt_return ::= 'returns' (LBRACKET) namelist (RBRACKET) action => do_return_clause
177 namelist ::= name+
178  
179 optionspec ::= <Options Prefix> <Inline Action> action => do_option_spec
180 <Options Prefix> ~ 'options'
181 | 'channels'
182 | 'tokens'
183 | '@' <Options Name>
184 <Options Name> ~ [a-zA-Z0-9_:]+
185  
186 namedspec ::= namedoptionkeywords name (SEMICOLON) action => do_named_spec
187 namedoptionkeywords ~ 'mode'
188 | 'import'
189  
190 <Inline Action> ::= ('{') <inline action text> ('}') action => do_inline_action
191 <inline action text> ~ [^}]*
192  
193 opt_comment ::=
194 opt_comment ::= multi_comment
195 multi_comment ::= single_comment+
196 single_comment ::= linecomment
197 | blockcomment
198  
199 opt_hashcomment ::=
200 opt_hashcomment ::= hashcomment
201 hashcomment ::= hashcommenttext
202 hashcommenttext ~ '#' linecommenttext
203  
204 linecomment ::= linecommentmatch action => do_comment
205 linecommentmatch ~ linecommentprefix linecommenttext
206 linecommentprefix ~ '//'
207 linecommenttext ~ [^\n]*
208  
209 blockcomment ::= <C style comment> action => do_comment
210 <C style comment> ~ '/*' <comment interior> '*/'
211 <comment interior> ~ <optional non stars> <optional star prefixed segments> <optional pre final stars>
212 <optional non stars> ~ [^*]*
213 <optional star prefixed segments> ~ <star prefixed segment>*
214 <star prefixed segment> ~ <stars> [^/*] <optional star free text>
215 <stars> ~ [*]+
216 <optional star free text> ~ [^*]*
217 <optional pre final stars> ~ [*]*
218  
219 LPAREN ~ '('
220 RPAREN ~ ')'
221 LBRACKET ~ '['
222 RBRACKET ~ ']'
223 LANGLE ~ '<'
224 RANGLE ~ '>'
225 COLON ~ ':'
226 SEMICOLON ~ ';'
227 COMMA ~ ','
228 RANGEOP ~ '..'
229 BAR ~ [|]
230 ALIASOP ~ '='
231 | '+='
232  
233 END_OF_SOURCE
234 }
235 );
236 1 return $self;
237 }
238  
239 0 ▶sub enabletrace { my ($self) = @_; $MarpaX::G4::Actions::trace = 1; }
Subroutine enabletrace: not called CC=1 SCAR=6.9
Pod undocumented
240 0 ▶sub ignoreredirect { my ($self) = @_; $MarpaX::G4::Actions::ignoreredirect = 1; }
Subroutine ignoreredirect: not called CC=1 SCAR=6.9
Pod undocumented
241  
242 sub parse
243 1 ▶{
Subroutine parse: called CC=1 SCAR=0.0
Pod undocumented
244 1 my ($self, $string) = @_;
245 1 my $parserinstance = Marpa::R2::Scanless::R->new({ grammar => $self->{grammar} });
246 1 $parserinstance->read(\$string);
247 1 my $value_ref = $parserinstance->value();
248 1 return ${$value_ref};
249 }
250  
251 # ----------------------------------------------------------------------------------------------------- #
252 # MarpaX::G4::Actions #
253 # #
254 # actions for processing grammar rules. #
255 # ----------------------------------------------------------------------------------------------------- #
256  
257 package MarpaX::G4::Actions;
258 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
259  
260 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
261  
262 2 my $trace = 0;
263 2 my $ignoreredirect = 0;
264  
265 sub new
266 1 ▶{
Subroutine new: called CC=1 SCAR=0.0
267 1 my ($class) = @_;
268 1 return bless {}, $class;
269 }
270  
271 sub isNotNull
272 236 ▶{
Subroutine isNotNull: called CC=6 SCAR=18.2
273 236 my ($value) = @_;
274 236 ▶ return 0 if !defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 6 230 236
275 230 ▶ return 0 if ref $value eq "ARRAY" && scalar @$value == 0;
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "ARRAY" and scalar @$value == 0 217 13 230
Condition100%3/3
ref $value eq "ARRAY" and scalar @$value == 0
!ll&&!rl&&r
121217
MC/DC100%2/2
ref $value eq "ARRAY" and scalar @$value == 0
ref $value eq "ARRAY" scalar @$value == 0
Truth table100%3/3
A and B
A= ref $value eq "ARRAY"B= scalar @$value == 0
ABresult
0X0
100
111
276 13 ▶ return 0 if ref $value eq "HASH" && scalar keys %$value == 0;
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "HASH" and scalar keys %$value == 0 0 13 13
Condition33%1/3
ref $value eq "HASH" and scalar keys %$value == 0
!ll&&!rl&&r
1300
MC/DC0%0/2
ref $value eq "HASH" and scalar keys %$value == 0
ref $value eq "HASH" scalar keys %$value == 0
Truth table33%1/3
A and B
A= ref $value eq "HASH"B= scalar keys %$value == 0
ABresult
0X0
100
111
277 13 return 1;
278 }
279  
280 sub dumpStructure
281 0 ▶{
Subroutine dumpStructure: not called CC=1 SCAR=6.9
282 0 my ( $self, $title, $structure ) = @_;
283  
284 0 printf "=== %s\n", $title;
285 0 $Data::Dumper::Indent = 1;
286 0 print Dumper($structure);
287 }
288  
289 sub abortWithError
290 0 ▶{
Subroutine abortWithError: not called CC=2 SCAR=17.9
291 0 my ( $self, $msg, $structure ) = @_;
292  
293 0 ▶ $self->dumpStructure($msg, $structure) if defined $structure;
Branch: 1 branch
BranchTrueFalseTotal
if defined $structure 0 0 0
294 0 die $msg;
295 }
296  
297 sub do_trace
298 519 ▶{
Subroutine do_trace: called CC=2 SCAR=8.1
299 519 my ($self, $subroutinename, $structure ) = @_;
300 519 ▶ return if !$MarpaX::G4::Actions::trace;
Branch: 1 branch
BranchTrueFalseTotal
unless $MarpaX::G4::Actions::trace 519 0 519
301 0 $self->dumpStructure($subroutinename,$structure);
302 }
303  
304 sub flattenArray
305 11 ▶{
Subroutine flattenArray: called CC=3 SCAR=15.0
306 11 my ($self, $value) = @_;
307 11 my $result = $value;
308 11 ▶ if (ref $value eq "ARRAY")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq "ARRAY") 0 11 11
309 {
310 0 ▶ $self->abortWithError("\$value must hold exactly 1 value", $value) if scalar @$value != 1;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$value != 1 0 0 0
311 0 $result = @{$value}[0];
312 }
313 11 return $result;
314 }
315  
316 sub default_action
317 278 ▶{
Subroutine default_action: called CC=2 SCAR=6.9
318 278 my ($self, @items ) = @_;
319 278 $self->do_trace("default_action", \@items);
320 278 my $result = \@items;
321 278 ▶ $result = $items[0] if scalar @items == 1;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @items == 1 60 218 278
322 278 return $result;
323 }
324  
325 sub do_grammar
326 1 ▶{
Subroutine do_grammar: called CC=1 SCAR=0.0
327 1 my ($self, @rules ) = @_;
328 1 return \@rules;
329 }
330  
331 sub do_option_spec
332 0 ▶{
Subroutine do_option_spec: not called CC=2 SCAR=17.9
333 0 my ($self, @items) = @_;
334 0 $self->do_trace("do_option_spec", \@items);
335 0 my $value = $items[1]->{action};
336 0 ▶ $value = join("\n", @$value) if ref($value) eq "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "ARRAY" 0 0 0
337 0 my $result = { comment => sprintf("%s : <%s>", $items[0], $value) };
338 0 return $result;
339 }
340  
341 sub do_named_spec
342 0 ▶{
Subroutine do_named_spec: not called CC=1 SCAR=6.9
343 0 my ($self, @items) = @_;
344 0 $self->do_trace("do_named_spec", \@items);
345 0 my $result = { comment => sprintf("%s : <%s>", $items[0], $items[1]) };
346 0 return $result;
347 }
348  
349 sub do_return_clause
350 0 ▶{
Subroutine do_return_clause: not called CC=1 SCAR=6.9
351 0 my ($self, @items) = @_;
352 0 $self->do_trace("do_return_clause", \@items);
353 0 my $result = { comment => sprintf("returns : [%s]", join( " ", @{$items[1]})) };
354 0 return $result;
355 }
356  
357 sub do_comment
358 0 ▶{
Subroutine do_comment: not called CC=6 SCAR=37.4
359 0 my ($self, @comment ) = @_;
360 0 $self->do_trace("do_comment", \@comment);
361 0 my $result = {};
362  
363 0 ▶ if ( ref($comment[0]) eq "HASH")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $comment[0] eq 'HASH') { } 0 0 0
364 {
365 0 my $multicomment = [];
366 0 for my $entry (@comment)
367 {
368 0 ▶ $self->abortWithError( "'comment' entry not found", $entry) if !exists $entry->{comment};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $entry->{"comment"} 0 0 0
369 0 push @$multicomment, $entry->{comment};
370 }
371 0 $result = { comment => \@$multicomment };
372 }
373 else
374 {
375 0 $result = { comment => $comment[0] };
376 0 ▶ if (scalar @comment > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @comment > 1) 0 0 0
377 {
378 0 my $multicomment = [];
379 0 for my $entry (@comment)
380 {
381 0 push @$multicomment, $entry;
382 }
383 0 $result = { comment => \@$multicomment };
384 }
385 }
386  
387 0 return $result;
388 }
389  
390 sub do_grammarspec
391 2 ▶{
Subroutine do_grammarspec: called CC=2 SCAR=6.9
392 2 my ($self, @items) = @_;
393 2 $self->do_trace("do_grammarspec", \@items);
394 2 my $result = { grammarspec => $items[1] };
395  
396 2 ▶ if (isNotNull($items[0]))
Branch: 1 branch
BranchTrueFalseTotal
if (isNotNull($items[0])) 1 1 2
397 {
398 1 $self->{grammarstate} = $items[0];
399 1 $result->{type} = $items[0];
400 }
401  
402 2 return $result;
403 }
404  
405 sub do_inline_action
406 0 ▶{
Subroutine do_inline_action: not called CC=1 SCAR=6.9
407 0 my ($self, @items) = @_;
408 0 $self->do_trace("do_inline_action", \@items);
409 0 my $result = { action => $items[0] };
410 0 return $result;
411 }
412  
413 sub do_redirect
414 1 ▶{
Subroutine do_redirect: called CC=5 SCAR=17.0
415 1 my ($self, @items ) = @_;
416 1 $self->do_trace("do_redirect", \@items);
417  
418 ##
419 # only process skip/hidden redirects when 'ignoreredirect' is active
420 ##
421 1 ▶ return {} if $MarpaX::G4::Actions::ignoreredirect && $items[0] !~ /skip|hidden/i;
Branch: 1 branch
BranchTrueFalseTotal
if $MarpaX::G4::Actions::ignoreredirect and not $items[0] =~ /skip|hidden/i 0 1 1
Condition33%1/3
$MarpaX::G4::Actions::ignoreredirect and not $items[0] =~ /skip|hidden/i
!ll&&!rl&&r
100
MC/DC0%0/2
$MarpaX::G4::Actions::ignoreredirect and not $items[0] =~ /skip|hidden/i
$MarpaX::G4::Actions::ignoreredirect not $items[0] =~ /skip|hidden/i
Truth table33%1/3
A and not(B)
A= $MarpaX::G4::Actions::ignoreredirectB= not $items[0] =~ /skip|hidden/i
ABresult
0X0
100
111
422  
423 1 my ($redir, @redirlist) = @items;
424  
425 1 my $result = $redir;
426 1 ▶ if ( scalar @redirlist > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @redirlist > 0) 1 0 1
427 {
428 1 $result = [$redir];
429 1 ▶ map { push @$result, $_ if scalar @$_ > 0; } @redirlist;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$_ > 0 0 1 1
430 }
431  
432 1 return $result;
433 }
434  
435 sub do_fragment
436 6 ▶{
Subroutine do_fragment: called CC=14 SCAR=39.1
437 6 my ($self, $comment1, $name, $comment2, $tokenlist ) = @_;
438 6 $self->do_trace("do_fragment", \[$name, $tokenlist]);
439  
440 6 ▶ $tokenlist = $tokenlist->{rightsides} if ref $tokenlist eq "HASH" && exists $tokenlist->{rightsides};
Branch: 1 branch
BranchTrueFalseTotal
if ref $tokenlist eq "HASH" and exists $tokenlist->{"rightsides"} 6 0 6
Condition33%1/3
ref $tokenlist eq "HASH" and exists $tokenlist->{"rightsides"}
!ll&&!rl&&r
006
MC/DC0%0/2
ref $tokenlist eq "HASH" and exists $tokenlist->{"rightsides"}
ref $tokenlist eq "HASH" exists $tokenlist->{"rightsides"}
Truth table33%1/3
A and B
A= ref $tokenlist eq "HASH"B= exists $tokenlist->{"rightsides"}
ABresult
0X0
100
111
441  
442 6 ▶ $self->abortWithError( "'tokenlist' must be an array in fragment $name", $tokenlist) if ref $tokenlist ne "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
if ref $tokenlist ne "ARRAY" 0 6 6
443  
444 ##
445 # save the fragment's tokenlist in the same format as a regular rule's right sides
446 ##
447 6 my $result = {};
448  
449 6 ▶ if ( scalar @$tokenlist <= 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tokenlist <= 1) { } 2 4 6
450 {
451 2 $result = {
452 type => 'fragment',
453 name => $name,
454 rightsides => [ { rhs => $tokenlist->[0] } ]
455 };
456 }
457 else
458 {
459 4 $result = {
460 type => 'fragment',
461 name => $name,
462 rightsides => [ { rhs => { type => 'tokengroup', definition => $tokenlist } } ]
463 };
464 }
465  
466 6 ▶ if (isNotNull($comment1) || isNotNull($comment2))
Branch: 1 branch
BranchTrueFalseTotal
if (isNotNull($comment1) or isNotNull($comment2)) 0 6 6
Condition33%1/3
isNotNull($comment1) or isNotNull($comment2)
l!l&&r!l&&!r
006
MC/DC0%0/2
isNotNull($comment1) or isNotNull($comment2)
isNotNull($comment1) isNotNull($comment2)
Truth table33%1/3
A or B
A= isNotNull($comment1)B= isNotNull($comment2)
ABresult
1X1
011
000
467 {
468 0 my $commentlines = [];
469 0 ▶ push @$commentlines, $comment1 if ref $comment1 eq '';
Branch: 1 branch
BranchTrueFalseTotal
if ref $comment1 eq "" 0 0 0
470 0 ▶ push @$commentlines, $comment1->{comment} if ref $comment1 eq "HASH";
Branch: 1 branch
BranchTrueFalseTotal
if ref $comment1 eq "HASH" 0 0 0
471 0 ▶ if (ref $comment2 eq "ARRAY")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $comment2 eq "ARRAY") 0 0 0
472 {
473 0 for my $cl (@$comment2)
474 {
475 0 ▶ push @$commentlines, $cl->{comment} if ref $cl eq "HASH";
Branch: 1 branch
BranchTrueFalseTotal
if ref $cl eq "HASH" 0 0 0
476 }
477 }
478 0 ▶ $result->{comment} = $commentlines if scalar @$commentlines > 0;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$commentlines > 0 0 0 0
479 }
480  
481 6 ▶ $result->{grammarstate} = $self->{grammarstate} if exists $self->{grammarstate};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"grammarstate"} 6 0 6
482  
483 6 return $result;
484 }
485  
486 sub do_single_rule
487 8 ▶{
Subroutine do_single_rule: called CC=14 SCAR=38.9
488 8 my ( $self, @items ) = @_;
489 8 $self->do_trace("do_single_rule", \@items);
490  
491 8 my ( $name, $retclause, $comment, $rightsides ) = @items;
492  
493 8 my $result = { name => $name };
494  
495 8 ▶ $result->{redirect} = $rightsides->{redirect} if ref $rightsides eq "HASH" && exists $rightsides->{redirect};
Branch: 1 branch
BranchTrueFalseTotal
if ref $rightsides eq "HASH" and exists $rightsides->{"redirect"} 1 7 8
Condition66%2/3
ref $rightsides eq "HASH" and exists $rightsides->{"redirect"}
!ll&&!rl&&r
071
MC/DC50%1/2
ref $rightsides eq "HASH" and exists $rightsides->{"redirect"}
ref $rightsides eq "HASH" exists $rightsides->{"redirect"}
Truth table66%2/3
A and B
A= ref $rightsides eq "HASH"B= exists $rightsides->{"redirect"}
ABresult
0X0
100
111
496  
497 # CAVEAT: extract 'redirect' before reassigning '$rightsides' !
498 8 ▶ $rightsides = $rightsides->{rightsides} if ref $rightsides eq "HASH" && exists $rightsides->{rightsides};
Branch: 1 branch
BranchTrueFalseTotal
if ref $rightsides eq "HASH" and exists $rightsides->{"rightsides"} 8 0 8
Condition33%1/3
ref $rightsides eq "HASH" and exists $rightsides->{"rightsides"}
!ll&&!rl&&r
008
MC/DC0%0/2
ref $rightsides eq "HASH" and exists $rightsides->{"rightsides"}
ref $rightsides eq "HASH" exists $rightsides->{"rightsides"}
Truth table33%1/3
A and B
A= ref $rightsides eq "HASH"B= exists $rightsides->{"rightsides"}
ABresult
0X0
100
111
499  
500 8 $result->{rightsides} = $rightsides;
501  
502 8 ▶ if (isNotNull($comment))
Branch: 1 branch
BranchTrueFalseTotal
if (isNotNull($comment)) 0 8 8
503 {
504 0 ▶ if (ref $comment eq "HASH" && exists $comment->{comment})
Branch: 2 branches
BranchTrueFalseTotal
if (ref $comment eq 'HASH' and exists $comment->{'comment'}) { } 0 0 0
elsif (ref $comment eq 'ARRAY') { } 0 0 0
Condition0%0/3
ref $comment eq "HASH" and exists $comment->{"comment"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $comment eq "HASH" and exists $comment->{"comment"}
ref $comment eq "HASH" exists $comment->{"comment"}
Truth table0%0/3
A and B
A= ref $comment eq "HASH"B= exists $comment->{"comment"}
ABresult
0X0
100
111
505 {
506 0 $result->{comment} = $comment->{comment};
507 }
508 elsif (ref $comment eq "ARRAY")
509 {
510 0 my $commentlines = [];
511 0 for my $cl (@$comment)
512 {
513 0 ▶ if (ref $cl eq "HASH" && exists $cl->{comment})
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cl eq 'HASH' and exists $cl->{'comment'}) { } 0 0 0
Condition0%0/3
ref $cl eq "HASH" and exists $cl->{"comment"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $cl eq "HASH" and exists $cl->{"comment"}
ref $cl eq "HASH" exists $cl->{"comment"}
Truth table0%0/3
A and B
A= ref $cl eq "HASH"B= exists $cl->{"comment"}
ABresult
0X0
100
111
514 {
515 0 push @$commentlines, $cl->{comment};
516 }
517 else
518 {
519 0 push @$commentlines, $cl;
520 }
521 }
522 0 $result->{comment} = $commentlines;
523 }
524 else
525 {
526 0 $result->{comment} = $comment;
527 }
528 }
529  
530 8 ▶ $result->{returns} = $retclause if isNotNull($retclause);
Branch: 1 branch
BranchTrueFalseTotal
if isNotNull($retclause) 0 8 8
531 8 ▶ $result->{grammarstate} = $self->{grammarstate} if exists $self->{grammarstate};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"grammarstate"} 3 5 8
532  
533 8 return $result;
534 }
535  
536 sub do_right_side
537 22 ▶{
Subroutine do_right_side: called CC=22 SCAR=41.1
538 22 my ($self, @items ) = @_;
539 22 $self->do_trace("do_right_side", \@items);
540 22 my ( $rhs, $comment1, $comment2, $endrhs ) = @items;
541  
542 22 my $result = {};
543  
544 ##
545 # create 'rightsides' from rhs
546 ##
547 22 ▶ if (ref $rhs eq "ARRAY" && scalar @$rhs > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $rhs eq 'ARRAY' and scalar @$rhs > 0) { } 13 9 22
Condition66%2/3
ref $rhs eq "ARRAY" and scalar @$rhs > 0
!ll&&!rl&&r
9013
MC/DC50%1/2
ref $rhs eq "ARRAY" and scalar @$rhs > 0
ref $rhs eq "ARRAY" scalar @$rhs > 0
Truth table66%2/3
A and B
A= ref $rhs eq "ARRAY"B= scalar @$rhs > 0
ABresult
0X0
100
111
548 {
549 13 $rhs = { rightsides => $rhs };
550 }
551 else
552 {
553 9 $rhs = { rightsides => [$rhs] };
554 }
555  
556 22 $result = $rhs;
557  
558 22 ▶ if (isNotNull($comment1) || isNotNull($comment2))
Branch: 1 branch
BranchTrueFalseTotal
if (isNotNull($comment1) or isNotNull($comment2)) 0 22 22
Condition33%1/3
isNotNull($comment1) or isNotNull($comment2)
l!l&&r!l&&!r
0022
MC/DC0%0/2
isNotNull($comment1) or isNotNull($comment2)
isNotNull($comment1) isNotNull($comment2)
Truth table33%1/3
A or B
A= isNotNull($comment1)B= isNotNull($comment2)
ABresult
1X1
011
000
559 {
560 0 my $commentlines = [];
561 0 ▶ push @$commentlines, $comment1 if ref $comment1 eq '';
Branch: 1 branch
BranchTrueFalseTotal
if ref $comment1 eq "" 0 0 0
562 0 ▶ push @$commentlines, $comment1->{comment} if ref $comment1 eq "HASH";
Branch: 1 branch
BranchTrueFalseTotal
if ref $comment1 eq "HASH" 0 0 0
563 0 ▶ if (ref $comment2 eq "ARRAY")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $comment2 eq "ARRAY") 0 0 0
564 {
565 0 for my $cl (@$comment2)
566 {
567 0 ▶ push @$commentlines, $cl->{comment} if ref $cl eq "HASH";
Branch: 1 branch
BranchTrueFalseTotal
if ref $cl eq "HASH" 0 0 0
568 }
569 }
570 0 ▶ $result->{comment} = $commentlines if scalar @$commentlines > 0;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$commentlines > 0 0 0 0
571 }
572  
573 22 ▶ my $redirect = $endrhs->{redirect} if ref $endrhs eq "HASH" && exists $endrhs->{redirect};
Branch: 1 branch
BranchTrueFalseTotal
if ref $endrhs eq "HASH" and exists $endrhs->{"redirect"} 1 21 22
Condition66%2/3
ref $endrhs eq "HASH" and exists $endrhs->{"redirect"}
!ll&&!rl&&r
0211
MC/DC50%1/2
ref $endrhs eq "HASH" and exists $endrhs->{"redirect"}
ref $endrhs eq "HASH" exists $endrhs->{"redirect"}
Truth table66%2/3
A and B
A= ref $endrhs eq "HASH"B= exists $endrhs->{"redirect"}
ABresult
0X0
100
111
574  
575 22 ▶ if (ref $endrhs eq "ARRAY" && isNotNull($endrhs))
Branch: 1 branch
BranchTrueFalseTotal
if (ref $endrhs eq "ARRAY" and isNotNull($endrhs)) 0 22 22
Condition33%1/3
ref $endrhs eq "ARRAY" and isNotNull($endrhs)
!ll&&!rl&&r
2200
MC/DC0%0/2
ref $endrhs eq "ARRAY" and isNotNull($endrhs)
ref $endrhs eq "ARRAY" isNotNull($endrhs)
Truth table33%1/3
A and B
A= ref $endrhs eq "ARRAY"B= isNotNull($endrhs)
ABresult
0X0
100
111
576 {
577 0 $self->abortWithError("unexpected : endrhs is an ARRAY\n");
578 }
579  
580 ##
581 # merge the rightsides of endrhs to those of rhs
582 ##
583 22 ▶ if (ref $endrhs eq "HASH" && exists $endrhs->{rightsides})
Branch: 1 branch
BranchTrueFalseTotal
if (ref $endrhs eq "HASH" and exists $endrhs->{"rightsides"}) 8 14 22
Condition66%2/3
ref $endrhs eq "HASH" and exists $endrhs->{"rightsides"}
!ll&&!rl&&r
0148
MC/DC50%1/2
ref $endrhs eq "HASH" and exists $endrhs->{"rightsides"}
ref $endrhs eq "HASH" exists $endrhs->{"rightsides"}
Truth table66%2/3
A and B
A= ref $endrhs eq "HASH"B= exists $endrhs->{"rightsides"}
ABresult
0X0
100
111
584 {
585 8 my $rightsides = $endrhs->{rightsides};
586  
587 8 ▶ $self->abortWithError("INTERNAL: endrhs rightsides must be an array", $rightsides ) if ref $rightsides ne "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
if ref $rightsides ne "ARRAY" 0 8 8
588 8 ▶ $self->abortWithError("INTERNAL: rhs in do_endrhs must be a hash and contain 'rightsides'", $rhs ) if ref $rhs ne "HASH" || !exists $rhs->{rightsides};
Branch: 1 branch
BranchTrueFalseTotal
if ref $rhs ne "HASH" or not exists $rhs->{"rightsides"} 0 8 8
Condition33%1/3
ref $rhs ne "HASH" or not exists $rhs->{"rightsides"}
l!l&&r!l&&!r
008
MC/DC0%0/2
ref $rhs ne "HASH" or not exists $rhs->{"rightsides"}
ref $rhs ne "HASH" not exists $rhs->{"rightsides"}
Truth table33%1/3
A or not(B)
A= ref $rhs ne "HASH"B= not exists $rhs->{"rightsides"}
ABresult
1X1
011
000
589 8 ▶ $self->abortWithError("INTERNAL: rhs/rightsides in do_endrhs must be a an array" , $rhs ) if ref $rhs->{rightsides} ne "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
if ref $rhs->{"rightsides"} ne "ARRAY" 0 8 8
590  
591 # merge the rightsides of rhs and endrhs
592 8 push (@{$result->{rightsides}}, @$rightsides);
593 }
594  
595 22 ▶ $result->{redirect} = $redirect if defined $redirect;
Branch: 1 branch
BranchTrueFalseTotal
if defined $redirect 1 21 22
596  
597 22 return $result;
598 }
599  
600 sub do_empty_rule
601 14 ▶{
Subroutine do_empty_rule: called CC=2 SCAR=6.9
602 14 my ($self, $opt_redir ) = @_;
603 14 $self->do_trace("do_empty_rule", \$opt_redir);
604 14 my $result = {};
605 14 ▶ $result->{redirect} = $opt_redir if isNotNull($opt_redir);
Branch: 1 branch
BranchTrueFalseTotal
if isNotNull($opt_redir) 1 13 14
606 14 return $result;
607 }
608  
609 sub do_endrhs
610 8 ▶{
Subroutine do_endrhs: called CC=10 SCAR=27.8
611 8 my ($self, @items ) = @_;
612 8 $self->do_trace("do_endrhs", \@items);
613 8 my $rhs = $items[0];
614  
615 ##
616 # return an empty array if we run into an empty rule/alternative.
617 ##
618 8 ▶ if (ref $rhs eq "ARRAY" && scalar @$rhs == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $rhs eq "ARRAY" and scalar @$rhs == 0) 0 8 8
Condition33%1/3
ref $rhs eq "ARRAY" and scalar @$rhs == 0
!ll&&!rl&&r
800
MC/DC0%0/2
ref $rhs eq "ARRAY" and scalar @$rhs == 0
ref $rhs eq "ARRAY" scalar @$rhs == 0
Truth table33%1/3
A and B
A= ref $rhs eq "ARRAY"B= scalar @$rhs == 0
ABresult
0X0
100
111
619 {
620 0 printf "WARNING: encountered empty right side of rule in 'endrhs'\n";
621 0 return [];
622 }
623  
624 8 ▶ $self->abortWithError("INTERNAL: 'rhs' must be a hash", $rhs) if ref $rhs ne "HASH";
Branch: 1 branch
BranchTrueFalseTotal
if ref $rhs ne "HASH" 0 8 8
625  
626 8 ▶ return { redirect => $rhs->{redirect} } if exists $rhs->{redirect} && !exists $rhs->{rightsides};
Branch: 1 branch
BranchTrueFalseTotal
if exists $rhs->{"redirect"} and not exists $rhs->{"rightsides"} 0 8 8
Condition33%1/3
exists $rhs->{"redirect"} and not exists $rhs->{"rightsides"}
!ll&&!rl&&r
800
MC/DC0%0/2
exists $rhs->{"redirect"} and not exists $rhs->{"rightsides"}
exists $rhs->{"redirect"} not exists $rhs->{"rightsides"}
Truth table33%1/3
A and not(B)
A= exists $rhs->{"redirect"}B= not exists $rhs->{"rightsides"}
ABresult
0X0
100
111
627  
628 8 ▶ if (!exists $rhs->{rightsides})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $rhs->{"rightsides"}) 0 8 8
629 {
630 0 printf "WARNING: 'rhs' does not contain 'rightsides' in 'endrhs'";
631 0 return {};
632 }
633  
634 8 my $rightsides = $rhs->{rightsides};
635 8 ▶ $self->abortWithError( "INTERNAL: rightsides must be an array", $rightsides) if ref $rightsides ne "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
if ref $rightsides ne "ARRAY" 0 8 8
636  
637 8 my $firstrhs = $rightsides->[0];
638 8 ▶ $self->abortWithError( "INTERNAL: firstrhs must be a hash", $firstrhs) if ref $firstrhs ne "HASH";
Branch: 1 branch
BranchTrueFalseTotal
if ref $firstrhs ne "HASH" 0 8 8
639 8 ▶ $self->abortWithError( "INTERNAL: firstrhs must contain 'rhs'", $firstrhs) if !exists $firstrhs->{rhs};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $firstrhs->{"rhs"} 0 8 8
640  
641 8 $firstrhs->{rhs}{alternative} = 'true';
642  
643 8 return $rhs;
644 }
645  
646 sub do_rhs
647 22 ▶{
Subroutine do_rhs: called CC=2 SCAR=6.9
648 22 my ($self, @items) = @_;
649 22 $self->do_trace("do_rhs", \@items);
650 22 my $result = $items[0];
651 22 ▶ $result = \@items if scalar @items > 1;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @items > 1 7 15 22
652 22 return $result;
653 }
654  
655 sub do_nonterminal
656 31 ▶{
Subroutine do_nonterminal: called CC=9 SCAR=30.9
657 31 my ( $self, @items ) = @_;
658 31 $self->do_trace("do_nonterminal", \@items);
659 31 my ($opt_assoc, $rulecomponent, $opt_card) = @items;
660  
661 31 ▶ $rulecomponent = $rulecomponent->[0] if ref $rulecomponent eq "ARRAY" && scalar @$rulecomponent == 1;
Branch: 1 branch
BranchTrueFalseTotal
if ref $rulecomponent eq "ARRAY" and scalar @$rulecomponent == 1 0 31 31
Condition33%1/3
ref $rulecomponent eq "ARRAY" and scalar @$rulecomponent == 1
!ll&&!rl&&r
3100
MC/DC0%0/2
ref $rulecomponent eq "ARRAY" and scalar @$rulecomponent == 1
ref $rulecomponent eq "ARRAY" scalar @$rulecomponent == 1
Truth table33%1/3
A and B
A= ref $rulecomponent eq "ARRAY"B= scalar @$rulecomponent == 1
ABresult
0X0
100
111
662  
663 31 ▶ if (isNotNull($opt_card))
Branch: 1 branch
BranchTrueFalseTotal
if (isNotNull($opt_card)) 7 24 31
664 {
665 7 ▶ if (ref $rulecomponent ne "HASH")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $rulecomponent ne "HASH") 0 7 7
666 {
667 0 ▶ if (ref $rulecomponent eq "")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $rulecomponent eq '') { } 0 0 0
668 {
669 0 $rulecomponent = { token => $rulecomponent };
670 }
671 else
672 {
673 0 $self->abortWithError( "'rulecomponent' must be a scalar or a hash", $rulecomponent );
674 }
675 }
676 7 $rulecomponent->{cardinality} = $self->flattenArray($opt_card);
677 }
678  
679 31 ▶ if (isNotNull($opt_assoc))
Branch: 1 branch
BranchTrueFalseTotal
if (isNotNull($opt_assoc)) 0 31 31
680 {
681 0 ▶ if (ref $rulecomponent ne "HASH")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $rulecomponent ne "HASH") 0 0 0
682 {
683 0 ▶ if (ref $rulecomponent eq "")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $rulecomponent eq '') { } 0 0 0
684 {
685 0 $rulecomponent = { token => $rulecomponent };
686 }
687 else
688 {
689 0 $self->abortWithError( "'rulecomponent' must be a scalar or a hash", $rulecomponent );
690 }
691 }
692 0 $rulecomponent->{associativity} = $self->flattenArray($opt_assoc);
693 }
694  
695 31 my $result = { rhs => $rulecomponent };
696  
697 31 return $result;
698 }
699  
700 sub do_rulecomponent
701 0 ▶{
Subroutine do_rulecomponent: not called CC=1 SCAR=6.9
702 0 my ($self, @items ) = @_;
703 0 $self->do_trace("do_rulecomponent", \@items);
704 0 return \@items;
705 }
706  
707 sub do_group
708 0 ▶{
Subroutine do_group: not called CC=7 SCAR=40.3
709 0 my ($self, @items ) = @_;
710 0 $self->do_trace("do_group", \@items);
711 0 my ( $opt_colon, $rhs, $grouplist, $opt_bar ) = @items;
712  
713 0 my $resultlist = [];
714  
715 0 ▶ $rhs = $rhs->[1] if ref $rhs eq "ARRAY" && scalar @$rhs == 1;
Branch: 1 branch
BranchTrueFalseTotal
if ref $rhs eq "ARRAY" and scalar @$rhs == 1 0 0 0
Condition0%0/3
ref $rhs eq "ARRAY" and scalar @$rhs == 1
!ll&&!rl&&r
000
MC/DC0%0/2
ref $rhs eq "ARRAY" and scalar @$rhs == 1
ref $rhs eq "ARRAY" scalar @$rhs == 1
Truth table0%0/3
A and B
A= ref $rhs eq "ARRAY"B= scalar @$rhs == 1
ABresult
0X0
100
111
716 0 push @$resultlist, $rhs;
717  
718 0 ▶ push @$resultlist, $grouplist if ref $grouplist eq "HASH";
Branch: 1 branch
BranchTrueFalseTotal
if ref $grouplist eq "HASH" 0 0 0
719 0 ▶ map { push @$resultlist, $_ } @$grouplist if ref $grouplist eq "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
if ref $grouplist eq "ARRAY" 0 0 0
720  
721 0 my $result = { type => 'rulegroup', definition => $resultlist };
722 0 ▶ $result->{option} = '(:' if isNotNull($opt_colon);
Branch: 1 branch
BranchTrueFalseTotal
if isNotNull($opt_colon) 0 0 0
723 0 ▶ $result->{option} = '|)' if isNotNull($opt_bar);
Branch: 1 branch
BranchTrueFalseTotal
if isNotNull($opt_bar) 0 0 0
724  
725 0 return $result;
726 }
727  
728 sub do_grouplist
729 0 ▶{
Subroutine do_grouplist: not called CC=1 SCAR=6.9
730 0 my ($self, @items ) = @_;
731 0 $self->do_trace("do_grouplist", \@items);
732 0 my $result = $items[0];
733 0 return $result;
734 }
735  
736 sub do_groupelement_concat
737 0 ▶{
Subroutine do_groupelement_concat: not called CC=3 SCAR=24.8
738 0 my ($self, @items ) = @_;
739 0 $self->do_trace("do_groupelement_concat", \@items);
740 0 my $element = $items[0];
741 0 my $result = { groupelement => $element };
742 0 ▶ $result = $element if ref $element eq "HASH" && scalar keys %$element == 1;
Branch: 1 branch
BranchTrueFalseTotal
if ref $element eq "HASH" and scalar keys %$element == 1 0 0 0
Condition0%0/3
ref $element eq "HASH" and scalar keys %$element == 1
!ll&&!rl&&r
000
MC/DC0%0/2
ref $element eq "HASH" and scalar keys %$element == 1
ref $element eq "HASH" scalar keys %$element == 1
Truth table0%0/3
A and B
A= ref $element eq "HASH"B= scalar keys %$element == 1
ABresult
0X0
100
111
743 0 return $result;
744 }
745  
746 sub do_groupelement_alternative
747 0 ▶{
Subroutine do_groupelement_alternative: not called CC=3 SCAR=24.8
748 0 my ($self, @items ) = @_;
749 0 $self->do_trace("do_groupelement_alternative", \@items);
750 0 my $element = $items[0];
751  
752 0 my $result = { alternative => 'true', groupelement => $element };
753  
754 0 ▶ if ( ref $element eq "HASH" && scalar keys %$element == 1)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $element eq "HASH" and scalar keys %$element == 1) 0 0 0
Condition0%0/3
ref $element eq "HASH" and scalar keys %$element == 1
!ll&&!rl&&r
000
MC/DC0%0/2
ref $element eq "HASH" and scalar keys %$element == 1
ref $element eq "HASH" scalar keys %$element == 1
Truth table0%0/3
A and B
A= ref $element eq "HASH"B= scalar keys %$element == 1
ABresult
0X0
100
111
755 {
756 0 $result = $element;
757 0 $result->{alternative} = 'true';
758 }
759  
760 0 return $result;
761 }
762  
763 sub do_token_group
764 5 ▶{
Subroutine do_token_group: called CC=2 SCAR=7.0
765 5 my ($self, @items ) = @_;
766 5 $self->do_trace("do_token_group", \@items);
767 5 my $result = { type => 'tokengroup', definition => $items[1] };
768 5 ▶ $result->{option} = '(:' if isNotNull($items[0]);
Branch: 1 branch
BranchTrueFalseTotal
if isNotNull($items[0]) 0 5 5
769 5 return $result;
770 }
771  
772 sub do_token_list
773 11 ▶{
Subroutine do_token_list: called CC=1 SCAR=0.0
774 11 my ($self, @items ) = @_;
775 11 $self->do_trace("do_token_list", \@items);
776 11 return \@items;
777 }
778  
779 sub do_tokenelement_concat
780 22 ▶{
Subroutine do_tokenelement_concat: called CC=5 SCAR=16.2
781 22 my ($self, $token, $opt_card ) = @_;
782 22 $self->do_trace("do_tokenelement_concat", \[$token, $opt_card]);
783 22 ▶ $token = $token->{token} if ref $token eq "HASH" && scalar keys %$token == 1 && exists $token->{token};
Branch: 1 branch
BranchTrueFalseTotal
if ref $token eq "HASH" and scalar keys %$token == 1 and exists $token->{"token"} 21 1 22
Condition66%4/6
ref $token eq "HASH" and scalar keys %$token == 1 and exists $token->{"token"}
!ll&&!rl&&r
1021
ref $token eq "HASH" and scalar keys %$token == 1
!ll&&!rl&&r
0121
MC/DC33%1/3
ref $token eq "HASH" and scalar keys %$token == 1 and exists $token->{"token"}
ref $token eq "HASH" scalar keys %$token == 1 exists $token->{"token"}
Truth table50%2/4
A and B and C
A= ref $token eq "HASH"B= scalar keys %$token == 1C= exists $token->{"token"}
ABCresult
0XX0
10X0
1100
1111
784 22 my $result = { token => $token };
785 22 ▶ $result->{cardinality} = $self->flattenArray($opt_card) if isNotNull($opt_card);
Branch: 1 branch
BranchTrueFalseTotal
if isNotNull($opt_card) 3 19 22
786 22 return $result;
787 }
788  
789 sub do_tokenelement_alternative
790 3 ▶{
Subroutine do_tokenelement_alternative: called CC=5 SCAR=18.4
791 3 my ( $self, $token, $opt_card ) = @_;
792 3 $self->do_trace("do_tokenelement_alternative", \[$token, $opt_card]);
793 3 ▶ $token = $token->{token} if ref $token eq "HASH" && scalar keys %$token == 1 && exists $token->{token};
Branch: 1 branch
BranchTrueFalseTotal
if ref $token eq "HASH" and scalar keys %$token == 1 and exists $token->{"token"} 3 0 3
Condition33%2/6
ref $token eq "HASH" and scalar keys %$token == 1 and exists $token->{"token"}
!ll&&!rl&&r
003
ref $token eq "HASH" and scalar keys %$token == 1
!ll&&!rl&&r
003
MC/DC0%0/3
ref $token eq "HASH" and scalar keys %$token == 1 and exists $token->{"token"}
ref $token eq "HASH" scalar keys %$token == 1 exists $token->{"token"}
Truth table25%1/4
A and B and C
A= ref $token eq "HASH"B= scalar keys %$token == 1C= exists $token->{"token"}
ABCresult
0XX0
10X0
1100
1111
794 3 my $result = { alternative => 'true', token => $token };
795 3 ▶ $result->{cardinality} = $self->flattenArray($opt_card) if isNotNull($opt_card);
Branch: 1 branch
BranchTrueFalseTotal
if isNotNull($opt_card) 0 3 3
796 3 return $result;
797 }
798  
799 sub do_token
800 35 ▶{
Subroutine do_token: called CC=2 SCAR=6.9
801 35 my ($self, $opt_neg, $token ) = @_;
802 35 $self->do_trace("do_token", \[$opt_neg, $token]);
803 35 my $result = { token => $token };
804 35 ▶ $result->{negation} = $self->flattenArray($opt_neg) if isNotNull($opt_neg);
Branch: 1 branch
BranchTrueFalseTotal
if isNotNull($opt_neg) 1 34 35
805 35 return $result;
806 }
807  
808 sub do_assignalias
809 0 ▶{
Subroutine do_assignalias: not called CC=1 SCAR=6.9
810 0 my ($self, @items ) = @_;
811 0 $self->do_trace("do_assignalias", \@items);
812 # alias op can be '=' or '+='
813 0 my $result = { token => $items[2], alias => { name => $items[0], op => $items[1] } };
814 0 return $result;
815 }
816  
817 sub do_name
818 21 ▶{
Subroutine do_name: called CC=2 SCAR=7.0
819 21 my ($self, @items ) = @_;
820 21 $self->do_trace("do_name", \@items);
821 21 my $result = { token => $items[1] };
822 21 ▶ $result->{negation} = $items[0] if isNotNull($items[0]);
Branch: 1 branch
BranchTrueFalseTotal
if isNotNull($items[0]) 0 21 21
823 21 return $result;
824 }
825  
826 sub do_range
827 0 ▶{
Subroutine do_range: not called CC=1 SCAR=6.9
828 0 my ($self, @items ) = @_;
829 0 $self->do_trace("do_range", \@items);
830 0 my $result = { type => 'range', begr => $items[0], endr => $items[1] };
831 0 return $result;
832 }
833  
834 sub do_regex
835 0 ▶{
Subroutine do_regex: not called CC=1 SCAR=6.9
836 0 my ($self, @items ) = @_;
837 0 $self->do_trace("do_regex", \@items);
838 0 my $result = { type => 'regex', anchor => $items[0], cardinality => $items[1] };
839 0 return $result;
840 }
841  
842 sub do_valueclause
843 0 ▶{
Subroutine do_valueclause: not called CC=1 SCAR=6.9
844 0 my ($self, @items ) = @_;
845 0 $self->do_trace("do_valueclause", \@items);
846 0 my $result = { type => 'value', name => $items[0] };
847 0 return $result;
848 }
849  
850 sub do_literal
851 21 ▶{
Subroutine do_literal: called CC=1 SCAR=0.0
852 21 my ($self, @items ) = @_;
853 21 $self->do_trace("do_literal", \@items);
854 21 my $value = $items[0];
855 21 my $delimiter = substr($value, 0, 1);
856 21 $value =~ s/^${delimiter}(.*)${delimiter}$/$1/;
857 21 my $result = { type => 'literal', value => $value };
858 21 return $result;
859 }
860  
861 sub do_characterclass
862 9 ▶{
Subroutine do_characterclass: called CC=1 SCAR=0.0
863 9 my ($self, @items ) = @_;
864 9 $self->do_trace("do_characterclass", \@items);
865 9 my $classtext = $items[0];
866 9 $classtext =~ s/\[(.*)\]/$1/;
867 9 my $result = { type => 'class', value => $classtext };
868 9 return $result;
869 }
870  
871 2 1;
872  
873 # ABSTRACT: G4 parser using Marpa
874  
875 =head1 SYNOPSIS
876 =for MarpaX::G4
877 name: Landing page synopsis
878 normalize-whitespace: 1
879 use MarpaX::G4;
880 my $infile = shift @ARGV;
881 my $grammartext = readFile($infile);
882 my $data = MarpaX::G4::parse_rules($grammartext);
883 =head1 DESCRIPTION
884 Parse an antlr4 grammar from the grammar text and return a parse tree.
885 =cut
« lib/MarpaX/G4/MarpaGen.pm ↑ Summary script/testmarpagrammar.pl »