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