lib/MarpaX/G4/MarpaGen.pm

filter: Statementstmt 69.5% 681 / 979 Branchbran 57.9% 314 / 542 Conditioncond 51.1% 155 / 303 MC/DCmcdc 25.0% 45 / 180 Subroutinesub 77.9% 60 / 77 Podpod 0.0% 0 / 71 totaltotal 58.3% 1255 / 2152 CC 396 SCAR 44.5
CC
396
Cov
63%
retagSimpleRule
315.7
processRightSides
218.2
walktoken
202.3
CRAP 85.3
« lib/MarpaX/G4/Symboltable.pm ↑ Summary lib/MarpaX/G4/Parser.pm »
1 # ----------------------------------------------------------------------------------------------------- #
2 # MarpaX::MarpaGen #
3 # #
4 # translate the parsed antlr4 rules to Marpa::R2 syntax. #
5 # #
6 # ----------------------------------------------------------------------------------------------------- #
7  
8 package MarpaX::G4::MarpaGen;
9  
10 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶no warnings 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 ▶use MarpaX::G4::Parser;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use MarpaX::G4::Symboltable;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 # --------------------------------------------------- #
20 # exposed class methods #
21 # --------------------------------------------------- #
22  
23 sub new
24 1 ▶{
Subroutine new: called CC=2 SCAR=7.0
Pod undocumented
25 1 my $invocant = shift;
26 1 ▶ my $class = ref($invocant) || $invocant; # Object or class name
Condition33%1/3
ref $invocant || $invocant
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $invocant || $invocant
ref $invocant $invocant
Truth table33%1/3
A || B
A= ref $invocantB= $invocant
ABresult
1X1
011
000
27 1 my $self = {}; # initiate our handy hashref
28 1 bless($self,$class); # make it usable
29  
30 1 $self->{symboltable} = undef;
31 1 $self->{verbosity} = 0;
32 1 $self->{level} = -1;
33 1 $self->{outputfilename} = '-';
34 1 $self->{outf} = undef;
35 1 $self->{rules} = {};
36 1 $self->{subrules} = {};
37 1 $self->{generationoptions} = {};
38  
39 1 return $self;
40 }
41  
42 0 ▶sub setVerbosity { my ($self, $verbosity) = @_; $self->{verbosity} = defined($verbosity) ? $verbosity : 0; }
Subroutine setVerbosity: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
defined $verbosity ? : 0 0 0
43 48 ▶sub symboltable { my ($self) = @_; return $self->{symboltable}; }
Subroutine symboltable: called CC=1 SCAR=0.0
Pod undocumented
44 1 ▶sub setoutputfile { my ($self, $outputfilename) = @_; $self->{outputfilename} = $outputfilename; }
Subroutine setoutputfile: called CC=1 SCAR=0.0
Pod undocumented
45  
46 1 ▶sub fragment2class { my ($self) = @_; $self->{generationoptions}{fragment2class} = 'true'; }
Subroutine fragment2class: called CC=1 SCAR=0.0
Pod undocumented
47 0 ▶sub embedactions { my ($self) = @_; $self->{generationoptions}{embedactions} = 'true'; }
Subroutine embedactions: not called CC=1 SCAR=6.9
Pod undocumented
48 0 ▶sub stripactions { my ($self) = @_; $self->{generationoptions}{stripactions} = 'true'; }
Subroutine stripactions: not called CC=1 SCAR=6.9
Pod undocumented
49 0 ▶sub stripallcomments { my ($self) = @_; $self->{generationoptions}{stripallcomments} = 'true'; }
Subroutine stripallcomments: not called CC=1 SCAR=6.9
Pod undocumented
50 1 ▶sub matchcaseinsensitive { my ($self) = @_; $self->{generationoptions}{matchcaseinsensitive} = 'true'; }
Subroutine matchcaseinsensitive: called CC=1 SCAR=0.0
Pod undocumented
51 0 ▶sub shiftlazytogreedy { my ($self) = @_; $self->{generationoptions}{shiftlazytogreedy} = 'true'; }
Subroutine shiftlazytogreedy: not called CC=1 SCAR=6.9
Pod undocumented
52 1 ▶sub buildkeywords { my ($self) = @_; $self->{generationoptions}{buildkeywords} = 'true'; }
Subroutine buildkeywords: called CC=1 SCAR=0.0
Pod undocumented
53  
54 sub testoption
55 189 ▶{
Subroutine testoption: called CC=3 SCAR=11.3
Pod undocumented
56 189 my ( $self, $option ) = @_;
57  
58 189 ▶ return undef if !defined $option;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $option 0 189 189
59 189 $option = lc $option;
60 189 ▶ return undef if !exists $self->{generationoptions}{$option};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"generationoptions"}{$option} 0 189 189
61  
62 189 return $self->{generationoptions}{$option};
63 }
64  
65 sub dumpStructure
66 0 ▶{
Subroutine dumpStructure: not called CC=1 SCAR=6.9
Pod undocumented
67 0 my ( $self, $title, $structure ) = @_;
68  
69 0 printf "=== %s\n", $title;
70 0 $Data::Dumper::Indent = 1;
71 0 print Dumper($structure);
72 }
73  
74 sub abortWithError
75 0 ▶{
Subroutine abortWithError: not called CC=1 SCAR=6.9
Pod undocumented
76 0 my ( $self, $msg, $structure ) = @_;
77  
78 0 $self->dumpStructure($msg, $structure);
79 0 die "aborting on unrecoverable error";
80 }
81  
82 sub mydie
83 0 ▶{
Subroutine mydie: not called CC=1 SCAR=6.9
Pod undocumented
84 0 my ( $msg ) = @_;
85 0 die "${msg}";
86 }
87  
88 sub addMarpaRule
89 32 ▶{
Subroutine addMarpaRule: called CC=2 SCAR=7.0
Pod undocumented
90 32 my ( $self, $rulename, $marparule ) = @_;
91  
92 32 my $rules = $self->{rules};
93 32 ▶ mydie "INTERNAL: rule $rulename defined more than once" if exists $rules->{$rulename};
Branch: 1 branch
BranchTrueFalseTotal
if exists $rules->{$rulename} 0 32 32
94 32 $rules->{$rulename} = $marparule;
95 }
96  
97 ##
98 # deleteMarpaRule : delete '$rulename'
99 ##
100 sub deleteMarpaRule
101 0 ▶{
Subroutine deleteMarpaRule: not called CC=2 SCAR=17.9
Pod undocumented
102 0 my ( $self, $rulename ) = @_;
103  
104 0 my $rules = $self->{rules};
105  
106 0 ▶ mydie "INTERNAL: can't delete undefined rule $rulename" if !exists $rules->{$rulename};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $rules->{$rulename} 0 0 0
107  
108 0 $self->deleteAllSubrules($rulename);
109 0 $rules->{$rulename} = { deletedafterconversiontoclass => 'true' };
110 }
111  
112 ##
113 # deleteAllSubrules : delete all subrules of '$rulename'
114 ##
115 sub deleteAllSubrules
116 1 ▶{
Subroutine deleteAllSubrules: called CC=3 SCAR=13.3
Pod undocumented
117 1 my ($self, $rulename ) = @_;
118  
119 1 my $subrules = $self->{subrules};
120 1 my $rules = $self->{rules};
121  
122 1 ▶ return if !exists $subrules->{$rulename};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $subrules->{$rulename} 1 0 1
123  
124 0 for my $subrulename (@{$subrules->{$rulename}})
125 {
126 0 $rules->{$subrulename} = { deletedafterconversiontoclass => 'true' };
127 }
128 }
129  
130 ##
131 # deleteSingleSubrule : delete 'subrulename' if it is a subrule of 'rulename'
132 ##
133 sub deleteSingleSubrule
134 0 ▶{
Subroutine deleteSingleSubrule: not called CC=5 SCAR=34.0
Pod undocumented
135 0 my ( $self, $rulename, $subrulename ) = @_;
136  
137 0 ▶ return if !exists $self->{subrules}{$rulename};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"subrules"}{$rulename} 0 0 0
138  
139 0 my $subrules = $self->{subrules}{$rulename};
140  
141 ##
142 # remove the subrule by creating a new list of subrules
143 ##
144 0 my $status = 0;
145 0 my @newrules;
146  
147 map {
148 0 ▶ if ( $_ eq $subrulename )
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq $subrulename) { } 0 0 0
149 {
150 0 $status = 1;
151 }
152 else
153 {
154 0 push @newrules, $_;
155 }
156 } @$subrules;
157  
158 0 $self->{subrules}{$rulename} = \@newrules;
159 0 ▶ if ($status)
Branch: 1 branch
BranchTrueFalseTotal
if ($status) 0 0 0
160 {
161 0 my $rules = $self->{rules};
162 0 ▶ mydie "INTERNAL: can't delete undefined rule $subrulename" if !exists $rules->{$subrulename};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $rules->{$subrulename} 0 0 0
163 0 $rules->{$subrulename} = { deletedafterconversiontoclass => 'true' }
164 }
165 }
166  
167 sub checkMarpaRuleExists
168 5 ▶{
Subroutine checkMarpaRuleExists: called CC=2 SCAR=7.0
Pod undocumented
169 5 my ( $self, $rulename ) = @_;
170  
171 5 my $rules = $self->{rules};
172  
173 5 ▶ return undef if !exists $rules->{$rulename};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $rules->{$rulename} 0 5 5
174  
175 5 return $rules->{$rulename};
176 }
177  
178 sub getMarpaRule
179 96 ▶{
Subroutine getMarpaRule: called CC=3 SCAR=14.2
Pod undocumented
180 96 my ( $self, $parent, $rulename ) = @_;
181  
182 96 my $rules = $self->{rules};
183  
184 96 ▶ if (!exists $rules->{$rulename})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $rules->{$rulename}) 0 96 96
185 {
186 0 ▶ $parent = "<ROOT>" if !defined $parent;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parent 0 0 0
187 0 mydie "INTERNAL: rule $rulename is undefined under parent $parent";
188 }
189  
190 96 return $rules->{$rulename};
191 }
192  
193 sub tagMarpaRule
194 32 ▶{
Subroutine tagMarpaRule: called CC=2 SCAR=7.0
Pod undocumented
195 32 my ( $self, $rulename ) = @_;
196  
197 32 my $rules = $self->{rules};
198 32 ▶ mydie "INTERNAL: rule $rulename is undefined" if !exists $rules->{$rulename};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $rules->{$rulename} 0 32 32
199 32 $rules->{$rulename}{status} = 'done';
200 }
201  
202 sub isSubrule
203 5 ▶{
Subroutine isSubrule: called CC=4 SCAR=14.1
Pod undocumented
204 5 my ( $self, $rulename, $subrulename ) = @_;
205  
206 5 my $subrules = $self->{subrules};
207  
208 5 ▶ return 0 if !exists $subrules->{$rulename};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $subrules->{$rulename} 0 5 5
209  
210 5 for my $sr (@{$subrules->{$rulename}})
211 {
212 9 ▶ return 1 if $sr eq $subrulename;
Branch: 1 branch
BranchTrueFalseTotal
if $sr eq $subrulename 5 4 9
213 }
214  
215 0 return 0;
216 }
217  
218 # --------------------------------------------------- #
219 # grammar generator #
220 # --------------------------------------------------- #
221  
222 sub enterLevel
223 14 ▶{
Subroutine enterLevel: called CC=3 SCAR=11.3
Pod undocumented
224 14 my ($self, $rulename, $context) = @_;
225  
226 14 ▶ my $level = $context->{level} if exists $context->{level};
Branch: 1 branch
BranchTrueFalseTotal
if exists $context->{"level"} 14 0 14
227 14 ▶ $level = -1 if !defined $level;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $level 0 14 14
228 14 ++$level;
229 14 $context->{level} = $level;
230 }
231  
232 sub exitLevel
233 14 ▶{
Subroutine exitLevel: called CC=1 SCAR=0.0
Pod undocumented
234 14 my ($self, $rulename, $context) = @_;
235  
236 14 my $level = $context->{level};
237 14 --$level;
238 14 $context->{level} = $level;
239 }
240  
241 sub retrieveModifier
242 360 ▶{
Subroutine retrieveModifier: called CC=3 SCAR=11.0
Pod undocumented
243 360 my ($token, $tag) = @_;
244  
245 360 ▶ return undef if ref $token ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $token ne "HASH" 0 360 360
246  
247 360 my $modifier = undef;
248 360 ▶ $modifier = $token->{$tag} if exists $token->{$tag};
Branch: 1 branch
BranchTrueFalseTotal
if exists $token->{$tag} 51 309 360
249  
250 360 return $modifier;
251 }
252  
253 sub negateElement
254 1 ▶{
Subroutine negateElement: called CC=8 SCAR=26.7
Pod undocumented
255 1 my ($self, $rulename, $mxtoken, $context) = @_;
256  
257 # if ($rulename =~ /NATIONAL_CHAR_STRING_LIT/)
258 # {
259 # printf "found!\n";
260 # }
261  
262 1 ▶ mydie "INTERNAL: negated element is not a hash in rule $rulename" if ref $mxtoken ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $mxtoken ne "HASH" 0 1 1
263  
264 1 my $mxelement;
265  
266 1 ▶ if (! exists $mxtoken->{class4list} )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $mxtoken->{"class4list"}) 0 1 1
267 {
268 0 mydie "INTERNAL: can't negate missing class4list in rule $rulename";
269 ##
270 # TODO: verify if we could continue by mapping this error to 'unsupported'
271 # so that we could process the complete input
272 ##
273 0 $mxelement = { type => 'unsupported', msg => "can't negate non-class token in $rulename" };
274 }
275  
276 1 my $class4list = $mxtoken->{class4list};
277 1 $mxelement = { type => 'negatedclass', value => "^${class4list}" };
278  
279 1 ▶ $mxelement->{grammarstate} = $mxtoken->{grammarstate} if exists $mxtoken->{grammarstate};
Branch: 1 branch
BranchTrueFalseTotal
if exists $mxtoken->{"grammarstate"} 0 1 1
280 1 ▶ $mxelement->{isFragmentOrChild} = $mxtoken->{isFragmentOrChild} if exists $mxtoken->{isFragmentOrChild};
Branch: 1 branch
BranchTrueFalseTotal
if exists $mxtoken->{"isFragmentOrChild"} 0 1 1
281  
282 ##
283 # delete the negated subrule since it will be replaced with a new subrule.
284 ##
285 1 ▶ if (exists $mxtoken->{rhs} && exists $mxtoken->{rhs}{token})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $mxtoken->{"rhs"} and exists $mxtoken->{"rhs"}{"token"}) 0 1 1
Condition33%1/3
exists $mxtoken->{"rhs"} and exists $mxtoken->{"rhs"}{"token"}
!ll&&!rl&&r
100
MC/DC0%0/2
exists $mxtoken->{"rhs"} and exists $mxtoken->{"rhs"}{"token"}
exists $mxtoken->{"rhs"} exists $mxtoken->{"rhs"}{"token"}
Truth table33%1/3
A and B
A= exists $mxtoken->{"rhs"}B= exists $mxtoken->{"rhs"}{"token"}
ABresult
0X0
100
111
286 {
287 0 my $token = $mxtoken->{rhs}{token};
288 0 ▶ if (ref $token eq "")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $token eq "") 0 0 0
289 {
290 0 $self->deleteSingleSubrule($rulename, $token);
291 }
292 }
293  
294 1 return $mxelement;
295 }
296  
297 sub translateLiteralCase
298 0 ▶{
Subroutine translateLiteralCase: not called CC=2 SCAR=17.9
Pod undocumented
299 0 my ($string, $case) = @_;
300  
301 0 ▶ return $case =~ /^U/i ? uc $string : lc $string;
Branch: 1 branch
BranchTrueFalseTotal
$case =~ /^U/i ? : 0 0 0
302 }
303  
304 ##
305 # generatematchcaseinsensitive : make a literal (somewhat) case-insensitive by creating a subrule with 2 match alternatives :
306 #
307 # - all uppercase
308 # - characterclass with the 1st character in upper/lower case, the rest all lowercase
309 #
310 # if the literal is only a single letter, we only retain the characterclass
311 # if the first character is not a letter, we don't generate a class.
312 #
313 ## --------------------------------------------------------------------------------------------------------- ##
314 ## CAVEAT : introduction of the ':i' and ':ic' literal and class modifiers has made this function obsolete. ##
315 ## we retain it as a demo of generated subrules. ##
316 ## --------------------------------------------------------------------------------------------------------- ##
317 sub generateMatchCaseInsensitive
318 0 ▶{
Subroutine generateMatchCaseInsensitive: not called CC=5 SCAR=34.0
Pod undocumented
319 0 my ($tokenvalue) = @_;
320  
321 0 my $lctoken = translateLiteralCase($tokenvalue, 'L');
322 0 my $uctoken = translateLiteralCase($tokenvalue, 'U');
323 0 my $prefix = substr($lctoken, 0, 1);
324 0 my $rest = substr($lctoken, 1);
325 0 my $lcp = lc $prefix;
326 0 my $ucp = uc $prefix;
327 0 my $mixedcase = "${lcp}${ucp}";
328  
329 0 my $literaltoken;
330  
331 0 ▶ if ($lcp =~ /[A-Z]/i)
Branch: 1 branch
BranchTrueFalseTotal
if ($lcp =~ /[A-Z]/i) { } 0 0 0
332 {
333 0 $literaltoken = { type => 'tokengroup',
334 definition => [{token => {type => 'class', value => $mixedcase}}]
335 };
336 0 ▶ push @{$literaltoken->{definition}}, {token => {type => 'literal', value => $rest }} if length($rest) > 0;
Branch: 1 branch
BranchTrueFalseTotal
if length $rest > 0 0 0 0
337 0 ▶ push @{$literaltoken->{definition}}, {token => {type => 'literal', value => $uctoken}, alternative=> 'true'} if length($uctoken) > 1;
Branch: 1 branch
BranchTrueFalseTotal
if length $uctoken > 1 0 0 0
338 }
339 else
340 {
341 0 $literaltoken = { type => 'tokengroup',
342 definition => [{token => {type => 'literal', value => $lctoken}}]
343 };
344 0 ▶ push @{$literaltoken->{definition}}, {token => {type => 'literal', value => $uctoken}, alternative=> 'true'} if length($uctoken) > 1;
Branch: 1 branch
BranchTrueFalseTotal
if length $uctoken > 1 0 0 0
345 }
346  
347 0 return $literaltoken;
348 }
349  
350 sub isSingleChar
351 21 ▶{
Subroutine isSingleChar: called CC=5 SCAR=16.2
Pod undocumented
352 21 my ($string) = @_;
353  
354 21 ▶ return 1 if $string =~ /^.$/;
Branch: 1 branch
BranchTrueFalseTotal
if $string =~ /^.$/ 17 4 21
355 4 ▶ return 1 if $string =~ /^\\[^u]$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $string =~ /^\\[^u]$/i 1 3 4
356 3 ▶ return 1 if $string =~ /^\\u[0-9A-F]{4,4}$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $string =~ /^\\u[0-9A-F]{4,4}$/i 0 3 3
357 3 ▶ return 1 if $string =~ /^\\u\{[0-9A-F]{5,5}\}$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $string =~ /^\\u\{[0-9A-F]{5,5}\}$/i 0 3 3
358 3 return 0;
359 }
360  
361 sub isKeywordLetter
362 71 ▶{
Subroutine isKeywordLetter: called CC=6 SCAR=22.1
Pod undocumented
363 71 my ($self, $rulename, $rule ) = @_;
364  
365 71 ▶ return 0 if !exists $rule->{class4list};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $rule->{"class4list"} 62 9 71
366 9 my $s = $rule->{class4list};
367 9 ▶ return 1 if $rulename =~ /^[a-z]$/i && $s =~ /([a-z])([a-z])/i && ( uc "$1" eq "$2" || lc "$1" eq "$2");
Branch: 1 branch
BranchTrueFalseTotal
if $rulename =~ /^[a-z]$/i and $s =~ /([a-z])([a-z])/i and uc "$1" eq "$2" || lc "$1" eq "$2" 0 9 9
Condition22%2/9
$rulename =~ /^[a-z]$/i and $s =~ /([a-z])([a-z])/i and uc "$1" eq "$2" || lc "$1" eq "$2"
!ll&&!rl&&r
900
$rulename =~ /^[a-z]$/i and $s =~ /([a-z])([a-z])/i
!ll&&!rl&&r
900
uc "$1" eq "$2" or lc "$1" eq "$2"
l!l&&r!l&&!r
000
MC/DC0%0/4
$rulename =~ /^[a-z]$/i and $s =~ /([a-z])([a-z])/i and uc "$1" eq "$2" || lc "$1" eq "$2"
$rulename =~ /^[a-z]$/i $s =~ /([a-z])([a-z])/i uc "$1" eq "$2" lc "$1" eq "$2"
Truth table20%1/5
A and B and C or D
A= $rulename =~ /^[a-z]$/iB= $s =~ /([a-z])([a-z])/iC= uc "$1" eq "$2"D= lc "$1" eq "$2"
ABCDresult
0XXX0
10XX0
11000
111X1
11011
368 9 return 0;
369 }
370  
371 ##
372 # isKeywordFragment : return 1 if '$string' is a characterclass with a pair of lower/upper case letters
373 ##
374 sub isKeywordFragment
375 60 ▶{
Subroutine isKeywordFragment: called CC=7 SCAR=19.5
Pod undocumented
376 60 my ($self, $rulename, $rule ) = @_;
377  
378 60 ▶ return undef if !exists $rule->{class4list};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $rule->{"class4list"} 30 30 60
379 30 my $string = $rule->{class4list};
380  
381 30 ▶ return lc substr($string, 0, 1) if $string =~ /([a-z])([a-z])/i && ( uc "$1" eq "$2" || lc "$1" eq "$2");
Branch: 1 branch
BranchTrueFalseTotal
if $string =~ /([a-z])([a-z])/i and uc "$1" eq "$2" || lc "$1" eq "$2" 1 29 30
Condition83%5/6
$string =~ /([a-z])([a-z])/i and uc "$1" eq "$2" || lc "$1" eq "$2"
!ll&&!rl&&r
2361
uc "$1" eq "$2" or lc "$1" eq "$2"
l!l&&r!l&&!r
016
MC/DC66%2/3
$string =~ /([a-z])([a-z])/i and uc "$1" eq "$2" || lc "$1" eq "$2"
$string =~ /([a-z])([a-z])/i uc "$1" eq "$2" lc "$1" eq "$2"
Truth table75%3/4
A and B or C
A= $string =~ /([a-z])([a-z])/iB= uc "$1" eq "$2"C= lc "$1" eq "$2"
ABCresult
0XX0
1000
11X1
1011
382 29 ▶ return substr($string, 0, 1) if $string !~ /[a-z]/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $string =~ /[a-z]/i 21 8 29
383 8 ▶ return substr($string, 0, 1) if $string =~ /[0-9]/i;
Branch: 1 branch
BranchTrueFalseTotal
if $string =~ /[0-9]/i 5 3 8
384  
385 3 return undef;
386 }
387  
388 sub convertLiteralToClass
389 21 ▶{
Subroutine convertLiteralToClass: called CC=2 SCAR=6.9
Pod undocumented
390 21 my ($literal) = @_;
391  
392 21 ▶ return undef if !isSingleChar($literal);
Branch: 1 branch
BranchTrueFalseTotal
unless isSingleChar($literal) 3 18 21
393  
394 18 return "${literal}";
395 }
396  
397 sub convertRangeToClass
398 0 ▶{
Subroutine convertRangeToClass: not called CC=5 SCAR=34.0
Pod undocumented
399 0 my ($token) = @_;
400  
401 0 my $begr = $token->{begr};
402 0 my $endr = $token->{endr};
403  
404 0 ▶ return { type => 'unsupported', msg => "can't convert non-literal beg/end range to class" } if $begr->{type} ne 'literal' || $endr->{type} ne 'literal';
Branch: 1 branch
BranchTrueFalseTotal
if $begr->{"type"} ne "literal" or $endr->{"type"} ne "literal" 0 0 0
Condition0%0/3
$begr->{"type"} ne "literal" or $endr->{"type"} ne "literal"
l!l&&r!l&&!r
000
MC/DC0%0/2
$begr->{"type"} ne "literal" or $endr->{"type"} ne "literal"
$begr->{"type"} ne "literal" $endr->{"type"} ne "literal"
Truth table0%0/3
A or B
A= $begr->{"type"} ne "literal"B= $endr->{"type"} ne "literal"
ABresult
1X1
011
000
405  
406 0 $begr = $begr->{value};
407 0 $endr = $endr->{value};
408  
409 0 ▶ return { type => 'unsupported', msg => "can't convert range (${begr} .. ${endr}) to class" } if !isSingleChar($begr) || !isSingleChar($endr);
Branch: 1 branch
BranchTrueFalseTotal
unless isSingleChar($begr) and isSingleChar($endr) 0 0 0
Condition0%0/3
isSingleChar($begr) and isSingleChar($endr)
!ll&&!rl&&r
000
MC/DC0%0/2
isSingleChar($begr) and isSingleChar($endr)
isSingleChar($begr) isSingleChar($endr)
Truth table0%0/3
A and B
A= isSingleChar($begr)B= isSingleChar($endr)
ABresult
0X0
100
111
410  
411 0 my $classtext = "${begr}-${endr}";
412  
413 0 return { type => 'class', value => $classtext, isLexeme => 1, class4list => $classtext };
414 }
415  
416 sub mergeClass4List
417 120 ▶{
Subroutine mergeClass4List: called CC=4 SCAR=13.9
Pod undocumented
418 120 my ($tracker, $mxelement) = @_;
419  
420 120 ▶ mydie "tracker has no 'status'" if !exists $tracker->{status};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $tracker->{"status"} 0 120 120
421  
422 120 ▶ if ( !exists $mxelement->{class4list} || $tracker->{status} == -1 )
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $mxelement->{'class4list'} or $tracker->{'status'} == -1) { } 90 30 120
Condition100%3/3
not exists $mxelement->{"class4list"} or $tracker->{"status"} == -1
l!l&&r!l&&!r
781230
MC/DC100%2/2
not exists $mxelement->{"class4list"} or $tracker->{"status"} == -1
not exists $mxelement->{"class4list"} $tracker->{"status"} == -1
Truth table100%3/3
not(A) or B
A= not exists $mxelement->{"class4list"}B= $tracker->{"status"} == -1
ABresult
1X1
011
000
423 {
424 90 $tracker->{status} = -1;
425 }
426 else
427 {
428 30 $tracker->{value} .= $mxelement->{class4list};
429 }
430 }
431  
432 sub mergeKeywordFragment
433 60 ▶{
Subroutine mergeKeywordFragment: called CC=4 SCAR=13.9
Pod undocumented
434 60 my ($tracker, $mxelement) = @_;
435  
436 60 ▶ mydie "tracker has no 'status'" if !exists $tracker->{status};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $tracker->{"status"} 0 60 60
437  
438 60 ▶ if ( !exists $mxelement->{keywordfragment} || $tracker->{status} == -1 )
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $mxelement->{'keywordfragment'} or $tracker->{'status'} == -1) { } 45 15 60
Condition100%3/3
not exists $mxelement->{"keywordfragment"} or $tracker->{"status"} == -1
l!l&&r!l&&!r
37815
MC/DC100%2/2
not exists $mxelement->{"keywordfragment"} or $tracker->{"status"} == -1
not exists $mxelement->{"keywordfragment"} $tracker->{"status"} == -1
Truth table100%3/3
not(A) or B
A= not exists $mxelement->{"keywordfragment"}B= $tracker->{"status"} == -1
ABresult
1X1
011
000
439 {
440 45 $tracker->{status} = -1;
441 }
442 else
443 {
444 15 $tracker->{value} .= $mxelement->{keywordfragment};
445 }
446 }
447  
448 sub generateSubruleName
449 18 ▶{
Subroutine generateSubruleName: called CC=4 SCAR=13.9
Pod undocumented
450 18 my ($self, $rulename, $cardinality, $context) = @_;
451  
452 18 ▶ $context->{subruleindex}{$rulename}{index} = 0 if !exists $context->{subruleindex}{$rulename}{index};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $context->{"subruleindex"}{$rulename}{"index"} 8 10 18
453  
454 18 my $subruleindex = ++$context->{subruleindex}{$rulename}{index};
455 18 my $subrulename = sprintf "%s_%03d", $rulename, $subruleindex;
456  
457 18 ▶ if ( defined $cardinality && $cardinality eq "?" )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cardinality and $cardinality eq "?") 4 14 18
Condition100%3/3
defined $cardinality and $cardinality eq "?"
!ll&&!rl&&r
954
MC/DC100%2/2
defined $cardinality and $cardinality eq "?"
defined $cardinality $cardinality eq "?"
Truth table100%3/3
A and B
A= defined $cardinalityB= $cardinality eq "?"
ABresult
0X0
100
111
458 {
459 4 $subrulename = "opt_" . $subrulename;
460 }
461  
462 18 push @{$self->{subrules}{$rulename}}, $subrulename;
463  
464 18 return $subrulename;
465 }
466  
467 ##
468 # createSubRule : create a (non-)anonymous subrule to 'rulename'.
469 # create a negated class if the class or token group was negated.
470 #
471 # CAVEAT: remember to reset the 'negation' flag in the caller
472 # to avoid negating twice.
473 ##
474 sub createSubRule
475 18 ▶{
Subroutine createSubRule: called CC=10 SCAR=23.2
Pod undocumented
476 18 my ($self, $rulename, $mxelement, $negation, $cardinality, $context ) = @_;
477  
478 18 ▶ if ( defined $negation )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $negation) 0 18 18
479 {
480 0 $mxelement = $self->negateElement($rulename, $mxelement, $context);
481 }
482  
483 18 my $subrulename = $self->generateSubruleName($rulename, $cardinality, $context);
484  
485 ##
486 # propagate grammar fragment states to subrules (i.e. children)
487 ##
488 18 ▶ $mxelement->{grammarstate} = $context->{subruleindex}{$rulename}{grammarstate} if exists $context->{subruleindex}{$rulename}{grammarstate};
Branch: 1 branch
BranchTrueFalseTotal
if exists $context->{"subruleindex"}{$rulename}{"grammarstate"} 14 4 18
489 18 ▶ $mxelement->{isFragmentOrChild} = $context->{subruleindex}{$rulename}{isFragmentOrChild} if exists $context->{subruleindex}{$rulename}{isFragmentOrChild};
Branch: 1 branch
BranchTrueFalseTotal
if exists $context->{"subruleindex"}{$rulename}{"isFragmentOrChild"} 7 11 18
490  
491 ##
492 # wrap cardinality "?" into an 'opt_' rule
493 ##
494 18 ▶ $mxelement->{cardinality} = $cardinality if defined $cardinality && $cardinality eq "?";
Branch: 1 branch
BranchTrueFalseTotal
if defined $cardinality and $cardinality eq "?" 4 14 18
Condition100%3/3
defined $cardinality and $cardinality eq "?"
!ll&&!rl&&r
954
MC/DC100%2/2
defined $cardinality and $cardinality eq "?"
defined $cardinality $cardinality eq "?"
Truth table100%3/3
A and B
A= defined $cardinalityB= $cardinality eq "?"
ABresult
0X0
100
111
495  
496 18 $self->addMarpaRule($subrulename, $mxelement);
497  
498 18 my $mxalias = { rule => $subrulename, rhs => { token => $subrulename } };
499  
500 ##
501 # CAVEAT: don't propagate the lexeme tag upwards.
502 # this avoids confusion in G1 rules.
503 ##
504 18 ▶ $mxalias->{class4list} = $mxelement->{class4list} if exists $mxelement->{class4list} && !defined $cardinality;
Branch: 1 branch
BranchTrueFalseTotal
if exists $mxelement->{"class4list"} and not defined $cardinality 0 18 18
Condition66%2/3
exists $mxelement->{"class4list"} and not defined $cardinality
!ll&&!rl&&r
1440
MC/DC0%0/2
exists $mxelement->{"class4list"} and not defined $cardinality
exists $mxelement->{"class4list"} not defined $cardinality
Truth table66%2/3
A and not(B)
A= exists $mxelement->{"class4list"}B= not defined $cardinality
ABresult
0X0
100
111
505 18 ▶ $mxalias->{grammarstate} = $context->{subruleindex}{$rulename}{grammarstate} if exists $context->{subruleindex}{$rulename}{grammarstate};
Branch: 1 branch
BranchTrueFalseTotal
if exists $context->{"subruleindex"}{$rulename}{"grammarstate"} 14 4 18
506 18 ▶ $mxalias->{isFragmentOrChild} = $context->{subruleindex}{$rulename}{isFragmentOrChild} if exists $context->{subruleindex}{$rulename}{isFragmentOrChild};
Branch: 1 branch
BranchTrueFalseTotal
if exists $context->{"subruleindex"}{$rulename}{"isFragmentOrChild"} 7 11 18
507  
508 18 return $mxalias;
509 }
510  
511 ## ------------------------------------------------------
512 # 'walktoken' : process all token flavours
513 ## ------------------------------------------------------
514 sub walktoken
515 40 ▶{
Subroutine walktoken: called CC=39 SCAR=53.1
Pod undocumented
516 40 my ($self, $rulename, $token, $context) = @_;
517  
518 # if ( $rulename eq "EOF")
519 # {
520 # printf "found!\n";
521 # }
522  
523 40 my $alternative = retrieveModifier( $token, 'alternative' );
524 40 my $cardinality = retrieveModifier( $token, 'cardinality' );
525  
526 40 my $mxToken = {};
527 40 my $comments = [];
528  
529 40 ▶ if (ref $token eq 'HASH' && exists $token->{comment} && !$self->testoption('stripallcomments'))
Branch: 1 branch
BranchTrueFalseTotal
if (ref $token eq "HASH" and exists $token->{"comment"} and not $self->testoption("stripallcomments")) 0 40 40
Condition33%2/6
ref $token eq "HASH" and exists $token->{"comment"} and not $self->testoption("stripallcomments")
!ll&&!rl&&r
4000
ref $token eq "HASH" and exists $token->{"comment"}
!ll&&!rl&&r
0400
MC/DC0%0/3
ref $token eq "HASH" and exists $token->{"comment"} and not $self->testoption("stripallcomments")
ref $token eq "HASH" exists $token->{"comment"} not $self->testoption("stripallcomments")
Truth table25%1/4
A and B and not(C)
A= ref $token eq "HASH"B= exists $token->{"comment"}C= not $self->testoption("stripallcomments")
ABCresult
0XX0
10X0
1100
1111
530 {
531 0 ▶ mydie "comment not a plain string in rule $rulename" if ref $token->{comment} ne "";
Branch: 1 branch
BranchTrueFalseTotal
if ref $token->{"comment"} ne "" 0 0 0
532 0 my $cl = $self->renderComment($rulename, [$token->{comment}]);
533 0 push (@$comments, @$cl);
534 }
535  
536 40 my $negation = retrieveModifier($token, 'negation');
537  
538 SWITCH:
539 {
540 40 ▶ (ref $token eq "") && do {
Branch: 1 branch
BranchTrueFalseTotal
ref $token eq "" and do { $mxToken = $self->processSubRule($token, $context); $mxToken = $self->createSubRule($rulename, $mxToken, $negation, $cardinality, $context); $negation = undef; last SWITCH } 0 40 40
541 0 $mxToken = $self->processSubRule($token, $context);
542 0 $mxToken = $self->createSubRule( $rulename, $mxToken, $negation, $cardinality, $context );
543 # reset 'negation' since it was processed by 'createSubRule'
544 0 $negation = undef;
545 0 last SWITCH;
546 };
547 40 ▶ (ref $token eq 'HASH' && exists $token->{type} && $token->{type} eq 'tokengroup') && do {
Branch: 1 branch
BranchTrueFalseTotal
ref $token eq "HASH" and exists $token->{"type"} and $token->{"type"} eq "tokengroup" and do { $mxToken = $self->walkgroup($rulename, $token, $context); $mxToken = $self->createSubRule($rulename, $mxToken, $negation, $cardinality, $context); $negation = undef; last SWITCH } 9 31 40
Condition83%5/6
ref $token eq "HASH" and exists $token->{"type"} and $token->{"type"} eq "tokengroup"
!ll&&!rl&&r
1309
ref $token eq "HASH" and exists $token->{"type"}
!ll&&!rl&&r
0139
MC/DC66%2/3
ref $token eq "HASH" and exists $token->{"type"} and $token->{"type"} eq "tokengroup"
ref $token eq "HASH" exists $token->{"type"} $token->{"type"} eq "tokengroup"
Truth table75%3/4
A and B and C
A= ref $token eq "HASH"B= exists $token->{"type"}C= $token->{"type"} eq "tokengroup"
ABCresult
0XX0
10X0
1100
1111
548 9 $mxToken = $self->walkgroup($rulename, $token, $context);
549 9 $mxToken = $self->createSubRule( $rulename, $mxToken, $negation, $cardinality, $context );
550 # reset 'negation' since it was processed by 'createSubRule'
551 9 $negation = undef;
552 9 last SWITCH;
553 };
554 31 ▶ (ref $token eq 'HASH' && exists $token->{type} && $token->{type} eq 'rulegroup') && do {
Branch: 1 branch
BranchTrueFalseTotal
ref $token eq "HASH" and exists $token->{"type"} and $token->{"type"} eq "rulegroup" and do { $mxToken = $self->walkgroup($rulename, $token, $context); delete $mxToken->{"isLexeme"}; $mxToken = $self->createSubRule($rulename, $mxToken, $negation, $cardinality, $context); $negation = undef; last SWITCH } 0 31 31
Condition66%4/6
ref $token eq "HASH" and exists $token->{"type"} and $token->{"type"} eq "rulegroup"
!ll&&!rl&&r
1300
ref $token eq "HASH" and exists $token->{"type"}
!ll&&!rl&&r
0130
MC/DC0%0/3
ref $token eq "HASH" and exists $token->{"type"} and $token->{"type"} eq "rulegroup"
ref $token eq "HASH" exists $token->{"type"} $token->{"type"} eq "rulegroup"
Truth table50%2/4
A and B and C
A= ref $token eq "HASH"B= exists $token->{"type"}C= $token->{"type"} eq "rulegroup"
ABCresult
0XX0
10X0
1100
1111
555 0 $mxToken = $self->walkgroup($rulename, $token, $context);
556 # strip lexeme status off rule groups
557 0 delete $mxToken->{isLexeme};
558 0 $mxToken = $self->createSubRule( $rulename, $mxToken, $negation, $cardinality, $context );
559 # reset 'negation' since it was processed by 'createSubRule'
560 0 $negation = undef;
561 0 last SWITCH;
562 };
563 31 ▶ (ref $token eq 'HASH' && exists $token->{type} && $token->{type} eq 'literal') && do {
Branch: 1 branch
BranchTrueFalseTotal
ref $token eq "HASH" and exists $token->{"type"} and $token->{"type"} eq "literal" and do { my $tokenvalue = $token->{"value"}; $mxToken = {"type", "literal", "value", $tokenvalue, "isLexeme", 1}; my $class4list = convertLiteralToClass($tokenvalue); $mxToken->{"class4list"} = $class4list if defined $class4list; last SWITCH } 21 10 31
Condition83%5/6
ref $token eq "HASH" and exists $token->{"type"} and $token->{"type"} eq "literal"
!ll&&!rl&&r
1921
ref $token eq "HASH" and exists $token->{"type"}
!ll&&!rl&&r
0130
MC/DC66%2/3
ref $token eq "HASH" and exists $token->{"type"} and $token->{"type"} eq "literal"
ref $token eq "HASH" exists $token->{"type"} $token->{"type"} eq "literal"
Truth table75%3/4
A and B and C
A= ref $token eq "HASH"B= exists $token->{"type"}C= $token->{"type"} eq "literal"
ABCresult
0XX0
10X0
1100
1111
564 21 my $tokenvalue = $token->{value};
565 21 $mxToken = { type => 'literal', value => $tokenvalue, isLexeme => 1 };
566 21 my $class4list = convertLiteralToClass($tokenvalue);
567 21 ▶ $mxToken->{class4list} = $class4list if defined $class4list;
Branch: 1 branch
BranchTrueFalseTotal
if defined $class4list 18 3 21
568 21 last SWITCH;
569 };
570 10 ▶ (ref $token eq 'HASH' && exists $token->{type} && $token->{type} eq 'class') && do {
Branch: 1 branch
BranchTrueFalseTotal
ref $token eq "HASH" and exists $token->{"type"} and $token->{"type"} eq "class" and do { $mxToken = {"type", "class", "value", $token->{"value"}, "isLexeme", 1, "class4list", $token->{"value"}}; last SWITCH } 9 1 10
Condition66%4/6
ref $token eq "HASH" and exists $token->{"type"} and $token->{"type"} eq "class"
!ll&&!rl&&r
109
ref $token eq "HASH" and exists $token->{"type"}
!ll&&!rl&&r
019
MC/DC33%1/3
ref $token eq "HASH" and exists $token->{"type"} and $token->{"type"} eq "class"
ref $token eq "HASH" exists $token->{"type"} $token->{"type"} eq "class"
Truth table50%2/4
A and B and C
A= ref $token eq "HASH"B= exists $token->{"type"}C= $token->{"type"} eq "class"
ABCresult
0XX0
10X0
1100
1111
571 9 $mxToken = { type => 'class', value => $token->{value}, isLexeme => 1, class4list => $token->{value} };
572 9 last SWITCH;
573 };
574 1 ▶ (ref $token eq 'HASH' && exists $token->{type} && $token->{type} eq 'regex') && do {
Branch: 1 branch
BranchTrueFalseTotal
ref $token eq "HASH" and exists $token->{"type"} and $token->{"type"} eq "regex" and do { $mxToken = {"type", "unsupported", "msg", "can't convert arbitrary regex to Marpa in $rulename"}; last SWITCH } 0 1 1
Condition33%2/6
ref $token eq "HASH" and exists $token->{"type"} and $token->{"type"} eq "regex"
!ll&&!rl&&r
100
ref $token eq "HASH" and exists $token->{"type"}
!ll&&!rl&&r
010
MC/DC0%0/3
ref $token eq "HASH" and exists $token->{"type"} and $token->{"type"} eq "regex"
ref $token eq "HASH" exists $token->{"type"} $token->{"type"} eq "regex"
Truth table25%1/4
A and B and C
A= ref $token eq "HASH"B= exists $token->{"type"}C= $token->{"type"} eq "regex"
ABCresult
0XX0
10X0
1100
1111
575 0 $mxToken = { type => 'unsupported', msg => "can't convert arbitrary regex to Marpa in $rulename" };
576 0 last SWITCH;
577 };
578 1 ▶ (ref $token eq 'HASH' && exists $token->{type} && $token->{type} eq 'range') && do {
Branch: 1 branch
BranchTrueFalseTotal
ref $token eq "HASH" and exists $token->{"type"} and $token->{"type"} eq "range" and do { $mxToken = convertRangeToClass($token); last SWITCH } 0 1 1
Condition33%2/6
ref $token eq "HASH" and exists $token->{"type"} and $token->{"type"} eq "range"
!ll&&!rl&&r
100
ref $token eq "HASH" and exists $token->{"type"}
!ll&&!rl&&r
010
MC/DC0%0/3
ref $token eq "HASH" and exists $token->{"type"} and $token->{"type"} eq "range"
ref $token eq "HASH" exists $token->{"type"} $token->{"type"} eq "range"
Truth table25%1/4
A and B and C
A= ref $token eq "HASH"B= exists $token->{"type"}C= $token->{"type"} eq "range"
ABCresult
0XX0
10X0
1100
1111
579 0 $mxToken = convertRangeToClass($token);
580 0 last SWITCH;
581 };
582 1 ▶ (ref $token eq 'HASH' && exists $token->{type} && $token->{type} eq 'value') && do {
Branch: 1 branch
BranchTrueFalseTotal
ref $token eq "HASH" and exists $token->{"type"} and $token->{"type"} eq "value" and do { $mxToken = {"type", "unsupported", "msg", "can't convert 'value' to Marpa in $rulename"}; last SWITCH } 0 1 1
Condition33%2/6
ref $token eq "HASH" and exists $token->{"type"} and $token->{"type"} eq "value"
!ll&&!rl&&r
100
ref $token eq "HASH" and exists $token->{"type"}
!ll&&!rl&&r
010
MC/DC0%0/3
ref $token eq "HASH" and exists $token->{"type"} and $token->{"type"} eq "value"
ref $token eq "HASH" exists $token->{"type"} $token->{"type"} eq "value"
Truth table25%1/4
A and B and C
A= ref $token eq "HASH"B= exists $token->{"type"}C= $token->{"type"} eq "value"
ABCresult
0XX0
10X0
1100
1111
583 0 $mxToken = { type => 'unsupported', msg => "can't convert 'value' to Marpa in $rulename" };
584 0 last SWITCH;
585 };
586 1 ▶ (ref $token eq 'HASH' && exists $token->{token}) && do {
Branch: 1 branch
BranchTrueFalseTotal
ref $token eq "HASH" and exists $token->{"token"} and do { $mxToken = $self->walktoken($rulename, $token->{"token"}, $context); last SWITCH } 1 0 1
Condition33%1/3
ref $token eq "HASH" and exists $token->{"token"}
!ll&&!rl&&r
001
MC/DC0%0/2
ref $token eq "HASH" and exists $token->{"token"}
ref $token eq "HASH" exists $token->{"token"}
Truth table33%1/3
A and B
A= ref $token eq "HASH"B= exists $token->{"token"}
ABresult
0X0
100
111
587 1 $mxToken = $self->walktoken($rulename, $token->{token}, $context);
588 1 last SWITCH;
589 };
590 0 ▶ (ref $token eq 'HASH' && exists $token->{action}) && do {
Branch: 1 branch
BranchTrueFalseTotal
ref $token eq "HASH" and exists $token->{"action"} and do { $mxToken = {"type", "ignore", "msg", "embedded action in $rulename"}; last SWITCH } 0 0 0
Condition0%0/3
ref $token eq "HASH" and exists $token->{"action"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $token eq "HASH" and exists $token->{"action"}
ref $token eq "HASH" exists $token->{"action"}
Truth table0%0/3
A and B
A= ref $token eq "HASH"B= exists $token->{"action"}
ABresult
0X0
100
111
591 0 $mxToken = { type => 'ignore', msg => "embedded action in $rulename" };
592 0 last SWITCH;
593 };
594 0 ▶ (ref $token eq 'HASH' && exists $token->{comment}) && do {
Branch: 1 branch
BranchTrueFalseTotal
ref $token eq "HASH" and exists $token->{"comment"} and do { $mxToken = {"type", "ignore", "msg", "comment in $rulename"}; last SWITCH } 0 0 0
Condition0%0/3
ref $token eq "HASH" and exists $token->{"comment"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $token eq "HASH" and exists $token->{"comment"}
ref $token eq "HASH" exists $token->{"comment"}
Truth table0%0/3
A and B
A= ref $token eq "HASH"B= exists $token->{"comment"}
ABresult
0X0
100
111
595 0 $mxToken = { type => 'ignore', msg => "comment in $rulename" };
596 0 last SWITCH;
597 };
598 0 do {
599 0 $self->abortWithError( "can't process token for rule $rulename", $token );
600 0 last SWITCH;
601 };
602 }
603  
604 ##
605 # apply 'negation' to every token type but groups and subrules
606 ##
607 40 ▶ if ( defined $negation )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $negation) 1 39 40
608 {
609 1 $mxToken = $self->negateElement($rulename, $mxToken, $context);
610 1 $negation = undef;
611 }
612  
613 ###
614 # create explicit subrule for
615 # - nonterminals
616 # - subgroups
617 # annotated for cardinality
618 ##
619 40 ▶ if ( defined $cardinality )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cardinality) 0 40 40
620 {
621 0 $mxToken = $self->createSubRule( $rulename, $mxToken, undef, $cardinality, $context );
622  
623 # strip lexeme status off annotated subrules
624 0 delete $mxToken->{isLexeme};
625 }
626  
627 40 ▶ $mxToken->{alternative} = 'A' if defined $alternative;
Branch: 1 branch
BranchTrueFalseTotal
if defined $alternative 0 40 40
628 40 ▶ $mxToken->{comments} = $comments if scalar @$comments > 0 && !$self->testoption('stripallcomments');
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$comments > 0 and not $self->testoption("stripallcomments") 0 40 40
Condition33%1/3
scalar @$comments > 0 and not $self->testoption("stripallcomments")
!ll&&!rl&&r
4000
MC/DC0%0/2
scalar @$comments > 0 and not $self->testoption("stripallcomments")
scalar @$comments > 0 not $self->testoption("stripallcomments")
Truth table33%1/3
A and not(B)
A= scalar @$comments > 0B= not $self->testoption("stripallcomments")
ABresult
0X0
100
111
629  
630 40 return $mxToken;
631 }
632  
633 sub walknonterminal
634 0 ▶{
Subroutine walknonterminal: not called CC=3 SCAR=24.8
Pod undocumented
635 0 my ( $self, $rulename, $nonterminal, $context ) = @_;
636  
637 0 ▶ mydie "nonterminal is not a hash for rule $rulename" if ref $nonterminal ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $nonterminal ne "HASH" 0 0 0
638  
639 0 my $mxToken = {};
640  
641 SWITCH:
642 {
643 0 ▶ (exists $nonterminal->{rhs}) && do {
Branch: 1 branch
BranchTrueFalseTotal
exists $nonterminal->{"rhs"} and do { my $rhs = $nonterminal->{"rhs"}; $mxToken = $self->walktoken($rulename, $rhs, $context); last SWITCH } 0 0 0
644 0 my $rhs = $nonterminal->{rhs};
645 0 $mxToken = $self->walktoken($rulename, $rhs, $context);
646 0 last SWITCH;
647 };
648 0 do {
649 0 $self->abortWithError( "can't process nonterminal for rule $rulename", $nonterminal );
650 0 last SWITCH;
651 };
652 }
653  
654 0 return $mxToken;
655 }
656  
657 ## -------------------------------------------------------------------------------
658 # 'retagSimpleRule' : check if the cardinality can be added to 'mxtoken'.
659 # Conditions :
660 # - '?' is consumed by 'opt_' subrules, so we have to reject it here
661 # - 'mxtoken' must be a subrule of 'rule'
662 # - the parent rule must consist of a single element
663 # (responsibility of the caller to verify)
664 ## -------------------------------------------------------------------------------
665 sub retagSimpleRule
666 6 ▶{
Subroutine retagSimpleRule: called CC=35 SCAR=57.5
Pod undocumented
667 6 my ( $self, $rulename, $mxtoken, $cardinality, $context, $options ) = @_;
668  
669 6 ▶ mydie "retagSimpleRule : token must be a hash in $rulename" if ref $mxtoken ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $mxtoken ne "HASH" 0 6 6
670 6 ▶ return 0 if $cardinality eq "?";
Branch: 1 branch
BranchTrueFalseTotal
if $cardinality eq "?" 0 6 6
671  
672 6 ▶ $cardinality =~ s/([+*])\?/$1/ if $cardinality =~ /[+*]\?/ && $self->testoption('shiftlazytogreedy');
Branch: 1 branch
BranchTrueFalseTotal
if $cardinality =~ /[+*]\?/ and $self->testoption("shiftlazytogreedy") 0 6 6
Condition33%1/3
$cardinality =~ /[+*]\?/ and $self->testoption("shiftlazytogreedy")
!ll&&!rl&&r
600
MC/DC0%0/2
$cardinality =~ /[+*]\?/ and $self->testoption("shiftlazytogreedy")
$cardinality =~ /[+*]\?/ $self->testoption("shiftlazytogreedy")
Truth table33%1/3
A and B
A= $cardinality =~ /[+*]\?/B= $self->testoption("shiftlazytogreedy")
ABresult
0X0
100
111
673 6 ▶ mydie sprintf "lazy quantifier %s in rule %s not supported by Marpa. use option -g to map to greedy.", $cardinality, $rulename if $cardinality =~ /[+*]\?/;
Branch: 1 branch
BranchTrueFalseTotal
if $cardinality =~ /[+*]\?/ 0 6 6
674  
675 6 ▶ $options = {} if !defined $options;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $options 1 5 6
676  
677 6 my $abortatfirstlevel = exists $options->{abortatfirstlevel};
678  
679 SWITCH: {
680 6 ▶ (exists $mxtoken->{rhs}) && do {
Branch: 1 branch
BranchTrueFalseTotal
exists $mxtoken->{"rhs"} and do { my $rhs = $mxtoken->{"rhs"}; mydie("'rhs' must be a hash in $rulename") if ref $rhs ne "HASH"; mydie("'token' must be a scalar in 'rhs' in rule $rulename") if not exists $rhs->{"token"} or ref $rhs->{"token"} ne ""; return 0 unless defined $self->checkMarpaRuleExists($rhs->{"token"}); my $rc = 0; if ($abortatfirstlevel) { my $subrulename = $rhs->{"token"}; return 0 unless $self->isSubrule($rulename, $subrulename); my $rule = $self->getMarpaRule($rulename, $subrulename); if ($cardinality ne "?") { $rule->{"cardinality"} = $cardinality; delete $rule->{"class4list"}; $rc = 1; } ; } else { my $subrulename = $rhs->{"token"}; return 0 unless $self->isSubrule($rulename, $subrulename); my $rule = $self->getMarpaRule($rulename, $subrulename); $rc = $self->retagSimpleRule($rulename, $rule, $cardinality, $context, $options); if ($rc) { mydie("can't retag subrule $subrulename twice in rule $rulename") if exists $rule->{"cardinality"}; $rule->{"cardinality"} = $cardinality; delete $rule->{"class4list"}; } ; } ; return $rc; last SWITCH } 5 1 6
681 5 my $rhs = $mxtoken->{rhs};
682  
683 5 ▶ mydie "'rhs' must be a hash in $rulename" if ref $rhs ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $rhs ne "HASH" 0 5 5
684 5 ▶ mydie "'token' must be a scalar in 'rhs' in rule $rulename" if !exists $rhs->{token} || ref $rhs->{token} ne "";
Branch: 1 branch
BranchTrueFalseTotal
if not exists $rhs->{"token"} or ref $rhs->{"token"} ne "" 0 5 5
Condition33%1/3
not exists $rhs->{"token"} or ref $rhs->{"token"} ne ""
l!l&&r!l&&!r
005
MC/DC0%0/2
not exists $rhs->{"token"} or ref $rhs->{"token"} ne ""
not exists $rhs->{"token"} ref $rhs->{"token"} ne ""
Truth table33%1/3
not(A) or B
A= not exists $rhs->{"token"}B= ref $rhs->{"token"} ne ""
ABresult
1X1
011
000
685  
686 5 ▶ return 0 if !defined $self->checkMarpaRuleExists($rhs->{token});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->checkMarpaRuleExists($rhs->{"token"}) 0 5 5
687  
688 5 my $rc = 0;
689  
690 5 ▶ if ($abortatfirstlevel)
Branch: 1 branch
BranchTrueFalseTotal
if ($abortatfirstlevel) { } 5 0 5
691 {
692 5 my $subrulename = $rhs->{token};
693  
694 # don't push cardinality to a rule unless it is a subrule of the parent
695 5 ▶ return 0 if !$self->isSubrule($rulename, $subrulename);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->isSubrule($rulename, $subrulename) 0 5 5
696  
697 5 my $rule = $self->getMarpaRule($rulename, $subrulename);
698 5 ▶ if ($cardinality ne "?")
Branch: 1 branch
BranchTrueFalseTotal
if ($cardinality ne "?") 5 0 5
699 {
700 5 $rule->{cardinality} = $cardinality;
701 # cardinality-tagged tokens loose 'class4list' status
702 5 delete $rule->{class4list};
703 5 $rc = 1;
704 }
705 }
706 else
707 {
708 0 my $subrulename = $rhs->{token};
709  
710 # don't push cardinality to a rule unless it is a subrule of the parent
711 0 ▶ return 0 if !$self->isSubrule($rulename, $subrulename);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->isSubrule($rulename, $subrulename) 0 0 0
712  
713 0 my $rule = $self->getMarpaRule($rulename, $subrulename);
714 0 $rc = $self->retagSimpleRule($rulename, $rule, $cardinality, $context, $options);
715 0 ▶ if ($rc)
Branch: 1 branch
BranchTrueFalseTotal
if ($rc) 0 0 0
716 {
717 0 ▶ mydie "can't retag subrule $subrulename twice in rule $rulename" if exists $rule->{cardinality};
Branch: 1 branch
BranchTrueFalseTotal
if exists $rule->{"cardinality"} 0 0 0
718 0 $rule->{cardinality} = $cardinality;
719 # cardinality-tagged tokens loose 'class4list' status
720 0 delete $rule->{class4list};
721 }
722 }
723 5 return $rc;
724 0 last SWITCH;
725 };
726 1 ▶ (exists $mxtoken->{type} && $mxtoken->{type} eq "group") && do {
Branch: 1 branch
BranchTrueFalseTotal
exists $mxtoken->{"type"} and $mxtoken->{"type"} eq "group" and do { mydie("group rhs must contain 'list' in $rulename") unless exists $mxtoken->{"list"}; my $ec = 0; foreach my $al (@{$$mxtoken{"list"};}) { mydie("alternative list is not an array in rule $rulename") if ref $al ne "HASH" or not exists $al->{"list"}; foreach my $le (@{$$al{"list"};}) { mydie("alternative element is not simple in rule $rulename") if exists $le->{"type"} and not $le->{"type"} =~ /literal|class/; $ec += 1; } ; } ; return $ec <= 1; last SWITCH } 0 1 1
Condition33%1/3
exists $mxtoken->{"type"} and $mxtoken->{"type"} eq "group"
!ll&&!rl&&r
010
MC/DC0%0/2
exists $mxtoken->{"type"} and $mxtoken->{"type"} eq "group"
exists $mxtoken->{"type"} $mxtoken->{"type"} eq "group"
Truth table33%1/3
A and B
A= exists $mxtoken->{"type"}B= $mxtoken->{"type"} eq "group"
ABresult
0X0
100
111
727 0 ▶ mydie "group rhs must contain 'list' in $rulename" if !exists $mxtoken->{list};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $mxtoken->{"list"} 0 0 0
728 0 my $ec = 0;
729 0 for my $al (@{$mxtoken->{list}})
730 {
731 0 ▶ mydie "alternative list is not an array in rule $rulename" if ref $al ne 'HASH' || !exists $al->{list};
Branch: 1 branch
BranchTrueFalseTotal
if ref $al ne "HASH" or not exists $al->{"list"} 0 0 0
Condition0%0/3
ref $al ne "HASH" or not exists $al->{"list"}
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $al ne "HASH" or not exists $al->{"list"}
ref $al ne "HASH" not exists $al->{"list"}
Truth table0%0/3
A or not(B)
A= ref $al ne "HASH"B= not exists $al->{"list"}
ABresult
1X1
011
000
732 0 for my $le (@{$al->{list}})
733 {
734 0 ▶ mydie "alternative element is not simple in rule $rulename" if exists $le->{type} && $le->{type} !~ /literal|class/;
Branch: 1 branch
BranchTrueFalseTotal
if exists $le->{"type"} and not $le->{"type"} =~ /literal|class/ 0 0 0
Condition0%0/3
exists $le->{"type"} and not $le->{"type"} =~ /literal|class/
!ll&&!rl&&r
000
MC/DC0%0/2
exists $le->{"type"} and not $le->{"type"} =~ /literal|class/
exists $le->{"type"} not $le->{"type"} =~ /literal|class/
Truth table0%0/3
A and not(B)
A= exists $le->{"type"}B= not $le->{"type"} =~ /literal|class/
ABresult
0X0
100
111
735 0 $ec += 1;
736 }
737 }
738 0 return $ec <= 1;
739 0 last SWITCH;
740 };
741 1 ▶ (exists $mxtoken->{type} && $mxtoken->{type} eq 'literal') && do {
Branch: 1 branch
BranchTrueFalseTotal
exists $mxtoken->{"type"} and $mxtoken->{"type"} eq "literal" and do { $mxtoken->{"cardinality"} = $cardinality; return 1; last SWITCH } 0 1 1
Condition33%1/3
exists $mxtoken->{"type"} and $mxtoken->{"type"} eq "literal"
!ll&&!rl&&r
010
MC/DC0%0/2
exists $mxtoken->{"type"} and $mxtoken->{"type"} eq "literal"
exists $mxtoken->{"type"} $mxtoken->{"type"} eq "literal"
Truth table33%1/3
A and B
A= exists $mxtoken->{"type"}B= $mxtoken->{"type"} eq "literal"
ABresult
0X0
100
111
742 0 $mxtoken->{cardinality} = $cardinality;
743 0 return 1;
744 0 last SWITCH;
745 };
746 1 ▶ (exists $mxtoken->{type} && $mxtoken->{type} eq "class") && do {
Branch: 1 branch
BranchTrueFalseTotal
exists $mxtoken->{"type"} and $mxtoken->{"type"} eq "class" and do { mydie("'class' can't be multiplied twice in $rulename") if exists $mxtoken->{"cardinality"}; $mxtoken->{"cardinality"} = $cardinality; return 1; last SWITCH } 1 0 1
Condition33%1/3
exists $mxtoken->{"type"} and $mxtoken->{"type"} eq "class"
!ll&&!rl&&r
001
MC/DC0%0/2
exists $mxtoken->{"type"} and $mxtoken->{"type"} eq "class"
exists $mxtoken->{"type"} $mxtoken->{"type"} eq "class"
Truth table33%1/3
A and B
A= exists $mxtoken->{"type"}B= $mxtoken->{"type"} eq "class"
ABresult
0X0
100
111
747 1 ▶ mydie "'class' can't be multiplied twice in $rulename" if exists $mxtoken->{cardinality};
Branch: 1 branch
BranchTrueFalseTotal
if exists $mxtoken->{"cardinality"} 0 1 1
748 1 $mxtoken->{cardinality} = $cardinality;
749 1 return 1;
750 0 last SWITCH;
751 };
752 0 ▶ (exists $mxtoken->{type} && $mxtoken->{type} eq "negatedclass") && do {
Branch: 1 branch
BranchTrueFalseTotal
exists $mxtoken->{"type"} and $mxtoken->{"type"} eq "negatedclass" and do { mydie("'negatedclass' can't be multiplied twice in $rulename") if exists $mxtoken->{"cardinality"}; $mxtoken->{"cardinality"} = $cardinality; return 1; last SWITCH } 0 0 0
Condition0%0/3
exists $mxtoken->{"type"} and $mxtoken->{"type"} eq "negatedclass"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $mxtoken->{"type"} and $mxtoken->{"type"} eq "negatedclass"
exists $mxtoken->{"type"} $mxtoken->{"type"} eq "negatedclass"
Truth table0%0/3
A and B
A= exists $mxtoken->{"type"}B= $mxtoken->{"type"} eq "negatedclass"
ABresult
0X0
100
111
753 0 ▶ mydie "'negatedclass' can't be multiplied twice in $rulename" if exists $mxtoken->{cardinality};
Branch: 1 branch
BranchTrueFalseTotal
if exists $mxtoken->{"cardinality"} 0 0 0
754 0 $mxtoken->{cardinality} = $cardinality;
755 0 return 1;
756 0 last SWITCH;
757 };
758 0 do {
759 0 $self->abortWithError( "don't know how to analyze element in $rulename", $mxtoken );
760 0 last SWITCH;
761 };
762 }
763  
764 0 return 0;
765 }
766  
767 ## ------------------------------------------------------
768 # removeCaseEquivalentBranches :
769 # go over the branches from the alternative lists.
770 # if 2 branches
771 # - consist of exactly 1 symbol
772 # - are case-equivalent
773 # then remove one of them.
774 ## ------------------------------------------------------
775 sub removeCaseEquivalentBranches
776 23 ▶{
Subroutine removeCaseEquivalentBranches: called CC=12 SCAR=25.5
Pod undocumented
777 23 my ($self, $alternativelists) = @_;
778  
779 23 ▶ return $alternativelists if scalar @$alternativelists < 2;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$alternativelists < 2 17 6 23
780  
781 6 my $filteredlist = [];
782 6 my $filtered = 0;
783 6 my $literal;
784  
785 6 for my $branch (@$alternativelists)
786 {
787 17 ▶ if ( !exists $branch->{list})
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $branch->{'list'}) { } 0 17 17
788 {
789 0 push @$filteredlist, $branch;
790 }
791 else
792 {
793 17 my $branchlist = $branch->{list};
794 17 ▶ if (scalar @$branchlist > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$branchlist > 1) { } 5 12 17
795 {
796 5 push @$filteredlist, $branch;
797 }
798 else
799 {
800 12 my $rhs = $branchlist->[0];
801 12 my $matchfound = 0;
802  
803 12 ▶ if ( exists $rhs->{type} && $rhs->{type} eq 'literal' )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $rhs->{"type"} and $rhs->{"type"} eq "literal") 4 8 12
Condition100%3/3
exists $rhs->{"type"} and $rhs->{"type"} eq "literal"
!ll&&!rl&&r
714
MC/DC100%2/2
exists $rhs->{"type"} and $rhs->{"type"} eq "literal"
exists $rhs->{"type"} $rhs->{"type"} eq "literal"
Truth table100%3/3
A and B
A= exists $rhs->{"type"}B= $rhs->{"type"} eq "literal"
ABresult
0X0
100
111
804 {
805 4 my $newliteral = $rhs->{value};
806  
807 4 ▶ if (defined $literal)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $literal) { } 2 2 4
808 {
809 2 my $tmp1 = uc $literal;
810 2 my $tmp2 = uc $newliteral;
811 2 ▶ $matchfound = $tmp1 ne "" && $tmp1 eq $tmp2;
Condition33%1/3
$tmp1 ne '' && $tmp1 eq $tmp2
!ll&&!rl&&r
020
MC/DC0%0/2
$tmp1 ne '' && $tmp1 eq $tmp2
$tmp1 ne '' $tmp1 eq $tmp2
Truth table33%1/3
A && B
A= $tmp1 ne ''B= $tmp1 eq $tmp2
ABresult
0X0
100
111
812 2 ▶ $filtered = 1 if $matchfound;
Branch: 1 branch
BranchTrueFalseTotal
if $matchfound 0 2 2
813 }
814 else
815 {
816 2 $literal = $newliteral;
817 }
818 }
819  
820 12 ▶ push @$filteredlist, $branch if !$matchfound;
Branch: 1 branch
BranchTrueFalseTotal
unless $matchfound 12 0 12
821 }
822 }
823 }
824  
825 6 ▶ return $alternativelists if !$filtered;
Branch: 1 branch
BranchTrueFalseTotal
unless $filtered 6 0 6
826  
827 0 return $filteredlist;
828 }
829  
830 ## ------------------------------------------------------
831 # 'processRightSides' converts a single list of tokens some of which
832 # are tagged as 'alternative' into (possibly) multiple lists
833 # each of which is an alternative for a group or rule
834 ## ------------------------------------------------------
835 sub processRightSides
836 23 ▶{
Subroutine processRightSides: called CC=58 SCAR=53.9
Pod undocumented
837 23 my ( $self, $rulename, $rhslist, $context ) = @_;
838  
839 # symbol lists of alternative branches
840 23 my $alternativelists = [];
841 # current alternative branch
842 23 my $currentlist = [];
843 # number of symbols in current alternative branch
844 23 my $alternativelength = 0;
845  
846 23 my $metalist = { comments => [], actions => [] };
847  
848 # status tracking for conversion to keyword, lexeme or class
849 23 my $class4list = { status => 0, value => "" };
850 23 my $class4group = { status => 0, value => "" };
851 23 my $groupisLexeme = { status => 0 };
852 23 my $keywordfragment = { status => 0 };
853  
854 # if ( $rulename eq "outer_join_sign")
855 # {
856 # printf "found!\n";
857 # }
858  
859 23 for my $e (@$rhslist)
860 {
861 60 ▶ $e = $e->{rhs} if ref $e eq 'HASH' && exists $e->{rhs} && !exists $e->{token};
Branch: 1 branch
BranchTrueFalseTotal
if ref $e eq "HASH" and exists $e->{"rhs"} and not exists $e->{"token"} 37 23 60
Condition66%4/6
ref $e eq "HASH" and exists $e->{"rhs"} and not exists $e->{"token"}
!ll&&!rl&&r
23037
ref $e eq "HASH" and exists $e->{"rhs"}
!ll&&!rl&&r
02337
MC/DC33%1/3
ref $e eq "HASH" and exists $e->{"rhs"} and not exists $e->{"token"}
ref $e eq "HASH" exists $e->{"rhs"} not exists $e->{"token"}
Truth table50%2/4
A and B and not(C)
A= ref $e eq "HASH"B= exists $e->{"rhs"}C= not exists $e->{"token"}
ABCresult
0XX0
10X0
1100
1111
862 60 ▶ $e = { token => $e } if ref $e eq 'HASH' && exists $e->{type} && exists $e->{definition};
Branch: 1 branch
BranchTrueFalseTotal
if ref $e eq "HASH" and exists $e->{"type"} and exists $e->{"definition"} 4 56 60
Condition66%4/6
ref $e eq "HASH" and exists $e->{"type"} and exists $e->{"definition"}
!ll&&!rl&&r
5604
ref $e eq "HASH" and exists $e->{"type"}
!ll&&!rl&&r
0564
MC/DC33%1/3
ref $e eq "HASH" and exists $e->{"type"} and exists $e->{"definition"}
ref $e eq "HASH" exists $e->{"type"} exists $e->{"definition"}
Truth table50%2/4
A and B and C
A= ref $e eq "HASH"B= exists $e->{"type"}C= exists $e->{"definition"}
ABCresult
0XX0
10X0
1100
1111
863  
864 60 my $negation = retrieveModifier($e, 'negation');
865 60 my $cardinality = retrieveModifier($e, 'cardinality');
866  
867 60 ▶ if (exists $e->{comment} || exists $e->{action})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $e->{"comment"} or exists $e->{"action"}) 0 60 60
Condition33%1/3
exists $e->{"comment"} or exists $e->{"action"}
l!l&&r!l&&!r
0060
MC/DC0%0/2
exists $e->{"comment"} or exists $e->{"action"}
exists $e->{"comment"} exists $e->{"action"}
Truth table33%1/3
A or B
A= exists $e->{"comment"}B= exists $e->{"action"}
ABresult
1X1
011
000
868 {
869 0 ▶ if (exists $e->{comment} && !$self->testoption('stripallcomments'))
Branch: 1 branch
BranchTrueFalseTotal
if (exists $e->{"comment"} and not $self->testoption("stripallcomments")) 0 0 0
Condition0%0/3
exists $e->{"comment"} and not $self->testoption("stripallcomments")
!ll&&!rl&&r
000
MC/DC0%0/2
exists $e->{"comment"} and not $self->testoption("stripallcomments")
exists $e->{"comment"} not $self->testoption("stripallcomments")
Truth table0%0/3
A and not(B)
A= exists $e->{"comment"}B= not $self->testoption("stripallcomments")
ABresult
0X0
100
111
870 {
871 0 push @{$metalist->{comments}}, $self->renderComment($rulename, [$e->{comment}]);
872 0 $metalist->{state} = 1;
873 }
874  
875 0 ▶ if (exists $e->{action} && !$self->testoption('stripactions'))
Branch: 1 branch
BranchTrueFalseTotal
if (exists $e->{"action"} and not $self->testoption("stripactions")) 0 0 0
Condition0%0/3
exists $e->{"action"} and not $self->testoption("stripactions")
!ll&&!rl&&r
000
MC/DC0%0/2
exists $e->{"action"} and not $self->testoption("stripactions")
exists $e->{"action"} not $self->testoption("stripactions")
Truth table0%0/3
A and not(B)
A= exists $e->{"action"}B= not $self->testoption("stripactions")
ABresult
0X0
100
111
876 {
877 0 ▶ push @{$metalist->{actions}}, $self->testoption('embedactions') ? $e->{action} : $self->renderComment($rulename, [$e->{action}]);
Branch: 1 branch
BranchTrueFalseTotal
$self->testoption('embedactions') ? : 0 0 0
878 0 $metalist->{state} = 1;
879 }
880  
881 ##
882 # skip the rest of processing for comment/action tokens
883 ##
884 0 next;
885 }
886  
887 60 ▶ if (ref $e eq 'HASH' && !exists $e->{token})
Branch: 1 branch
BranchTrueFalseTotal
if (ref $e eq "HASH" and not exists $e->{"token"}) 0 60 60
Condition33%1/3
ref $e eq "HASH" and not exists $e->{"token"}
!ll&&!rl&&r
0600
MC/DC0%0/2
ref $e eq "HASH" and not exists $e->{"token"}
ref $e eq "HASH" not exists $e->{"token"}
Truth table33%1/3
A and not(B)
A= ref $e eq "HASH"B= not exists $e->{"token"}
ABresult
0X0
100
111
888 {
889 0 ▶ $self->abortWithError( "generic regex rules not supported in rule $rulename", $e ) if exists $e->{type} && $e->{type} eq "regex";
Branch: 1 branch
BranchTrueFalseTotal
if exists $e->{"type"} and $e->{"type"} eq "regex" 0 0 0
Condition0%0/3
exists $e->{"type"} and $e->{"type"} eq "regex"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $e->{"type"} and $e->{"type"} eq "regex"
exists $e->{"type"} $e->{"type"} eq "regex"
Truth table0%0/3
A and B
A= exists $e->{"type"}B= $e->{"type"} eq "regex"
ABresult
0X0
100
111
890 0 $self->abortWithError( "INTERNAL: 'e' must be a hash and contain 'token' in rule $rulename", $e );
891 }
892  
893 60 my $alternative = retrieveModifier($e, 'alternative');
894  
895 60 ▶ if (defined $alternative)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $alternative) { } 11 49 60
896 {
897 11 ▶ if (scalar @$currentlist > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$currentlist > 0) 11 0 11
898 {
899 ##
900 # close the current alternative list
901 ##
902 11 my $newlist;
903  
904 ##
905 # replace a keyword built from lower/upper case character classes by a literal
906 ##
907 11 my $keyword = $keywordfragment->{value};
908 11 ▶ if ($self->testoption("buildkeywords") && $keywordfragment->{status} == 0 && $keyword =~ /^[a-z]/i)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->testoption('buildkeywords') and $keywordfragment->{'status'} == 0 and $keyword =~ /^[a-z]/i) { } 0 11 11
Condition66%4/6
$self->testoption("buildkeywords") and $keywordfragment->{"status"} == 0 and $keyword =~ /^[a-z]/i
!ll&&!rl&&r
1010
$self->testoption("buildkeywords") and $keywordfragment->{"status"} == 0
!ll&&!rl&&r
0101
MC/DC0%0/3
$self->testoption("buildkeywords") and $keywordfragment->{"status"} == 0 and $keyword =~ /^[a-z]/i
$self->testoption("buildkeywords") $keywordfragment->{"status"} == 0 $keyword =~ /^[a-z]/i
Truth table50%2/4
A and B and C
A= $self->testoption("buildkeywords")B= $keywordfragment->{"status"} == 0C= $keyword =~ /^[a-z]/i
ABCresult
0XX0
10X0
1100
1111
909 {
910 0 $currentlist = [
911 { type => 'literal', value => $keyword, isLexeme => 1 }
912 ];
913 0 $newlist = { list => $currentlist, isLexeme => 1 };
914 }
915 else
916 {
917 11 $newlist = { list => $currentlist };
918 11 ▶ $newlist->{class4list} = $class4list->{value} if $class4list->{status} != -1;
Branch: 1 branch
BranchTrueFalseTotal
if $class4list->{"status"} != -1 2 9 11
919 11 ▶ $newlist->{metalist} = $metalist if exists $metalist->{state};
Branch: 1 branch
BranchTrueFalseTotal
if exists $metalist->{"state"} 0 11 11
920 }
921  
922 11 push @$alternativelists, $newlist;
923 ##
924 # re-initialize the list state
925 ##
926 11 $currentlist = [];
927 11 $class4list = { status => 0, value => "" };
928 11 $metalist = { comments => [], actions => [] };
929 11 $keywordfragment = { status => 0 };
930 11 $alternativelength = 0;
931 }
932 }
933 else
934 {
935 ##
936 # a sequence of literals can't be mapped to a class, so we reset class4list
937 ##
938 49 ▶ if ($alternativelength > 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($alternativelength > 1) 12 37 49
939 {
940 12 $class4group->{status} = -1;
941 12 delete $class4group->{value};
942 }
943 }
944  
945 60 my $mxelement;
946  
947 60 ▶ if (ref $e->{token} eq "")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $e->{'token'} eq '') { } 21 39 60
948 {
949 ##
950 # translate a G4 subrule into a Marpa subrule
951 ##
952 21 my $symbol = $e->{token};
953 21 $mxelement = $self->processSubRule($symbol, $context);
954 }
955 else
956 {
957 39 ▶ $self->abortWithError( "can't process group for rule $rulename", $rhslist ) if ref $e ne 'HASH' || !exists $e->{token};
Branch: 1 branch
BranchTrueFalseTotal
if ref $e ne "HASH" or not exists $e->{"token"} 0 39 39
Condition33%1/3
ref $e ne "HASH" or not exists $e->{"token"}
l!l&&r!l&&!r
0039
MC/DC0%0/2
ref $e ne "HASH" or not exists $e->{"token"}
ref $e ne "HASH" not exists $e->{"token"}
Truth table33%1/3
A or not(B)
A= ref $e ne "HASH"B= not exists $e->{"token"}
ABresult
1X1
011
000
958 39 $mxelement = $self->walktoken($rulename, $e->{token}, $context);
959 # ignore embedded comments/actions
960 39 ▶ next if exists $mxelement->{type} && $mxelement->{type} eq "ignore";
Branch: 1 branch
BranchTrueFalseTotal
if exists $mxelement->{"type"} and $mxelement->{"type"} eq "ignore" 0 39 39
Condition66%2/3
exists $mxelement->{"type"} and $mxelement->{"type"} eq "ignore"
!ll&&!rl&&r
9300
MC/DC0%0/2
exists $mxelement->{"type"} and $mxelement->{"type"} eq "ignore"
exists $mxelement->{"type"} $mxelement->{"type"} eq "ignore"
Truth table66%2/3
A and B
A= exists $mxelement->{"type"}B= $mxelement->{"type"} eq "ignore"
ABresult
0X0
100
111
961  
962 39 my $keywordfragment = $self->isKeywordFragment($rulename, $mxelement);
963 39 ▶ $mxelement->{keywordfragment} = $keywordfragment if defined $keywordfragment;
Branch: 1 branch
BranchTrueFalseTotal
if defined $keywordfragment 23 16 39
964 }
965  
966 ##
967 # collect embedded comments in the alternative branch state
968 ##
969 60 ▶ if (exists $mxelement->{comments})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $mxelement->{"comments"}) 0 60 60
970 {
971 0 push (@{$metalist->{comments}}, @{$mxelement->{comments}});
972 0 $metalist->{state} = 1;
973 0 delete $mxelement->{comments};
974 0 ▶ next if scalar keys %$mxelement == 0;
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %$mxelement == 0 0 0 0
975 }
976  
977 ##
978 # CAVEAT: retrieve 'isLexeme' from $mxelement
979 ##
980 60 my $il = retrieveModifier($mxelement, 'isLexeme');
981 60 ▶ $groupisLexeme->{status} = -1 if !defined $il;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $il 31 29 60
982  
983 ##
984 # negation should not come from the token
985 ##
986 60 ▶ mydie "processRightsides : unexpected negation in 'mxelement'" if exists $mxelement->{negation};
Branch: 1 branch
BranchTrueFalseTotal
if exists $mxelement->{"negation"} 0 60 60
987  
988 60 ▶ if ( defined $negation )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $negation) 0 60 60
989 {
990 0 $mxelement = $self->negateElement($rulename, $mxelement, $context);
991 }
992  
993 ##
994 # CAVEAT: use 'cardinality' from $e since $mxtoken
995 # was computed without metainformation.
996 ##
997 60 ▶ if (defined $cardinality)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cardinality) 10 50 60
998 {
999 ##
1000 # if both the parent and the sub rules are simple, we can propagate the cardinality
1001 # to the subrule.
1002 # in all other cases we create a new subrule.
1003 ##
1004 10 ▶ if ( scalar @$rhslist <= 1 && $self->retagSimpleRule($rulename, $mxelement, $cardinality, $context) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$rhslist <= 1 and $self->retagSimpleRule($rulename, $mxelement, $cardinality, $context)) { } 1 9 10
Condition66%2/3
scalar @$rhslist <= 1 and $self->retagSimpleRule($rulename, $mxelement, $cardinality, $context)
!ll&&!rl&&r
901
MC/DC50%1/2
scalar @$rhslist <= 1 and $self->retagSimpleRule($rulename, $mxelement, $cardinality, $context)
scalar @$rhslist <= 1 $self->retagSimpleRule($rulename, $mxelement, $cardinality, $context)
Truth table66%2/3
A and B
A= scalar @$rhslist <= 1B= $self->retagSimpleRule($rulename, $mxelement, $cardinality, $context)
ABresult
0X0
100
111
1005 {
1006 ##
1007 # if the tagged element is part of an alternative branch (i.e. a branch that has more than one element),
1008 # we have to make it into a subrule
1009 ##
1010 1 ▶ if (defined $alternative && scalar @$rhslist > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $alternative and scalar @$rhslist > 1) 0 1 1
Condition33%1/3
defined $alternative and scalar @$rhslist > 1
!ll&&!rl&&r
100
MC/DC0%0/2
defined $alternative and scalar @$rhslist > 1
defined $alternative scalar @$rhslist > 1
Truth table33%1/3
A and B
A= defined $alternativeB= scalar @$rhslist > 1
ABresult
0X0
100
111
1011 {
1012 0 $mxelement = $self->createSubRule( $rulename, $mxelement, undef, undef, $context );
1013 }
1014 }
1015 else
1016 {
1017 ##
1018 # create a subrule for cardinality-tagged element lists
1019 ##
1020 9 $mxelement = $self->createSubRule( $rulename, $mxelement, undef, $cardinality, $context );
1021  
1022 ##
1023 # propagate the cardinality to the new subrule
1024 # ("?" is wrapped into an 'opt_' rule in 'createSubRule', so it was already consumed).
1025 #
1026 # TODO : check if the '!defined $alternative' clause below should be reinstated
1027 ##
1028 # if ( !defined $alternative && $cardinality ne "?" && !$self->retagSimpleRule($rulename, $mxelement, $cardinality, $context, {abortatfirstlevel => 'true'}) )
1029 9 ▶ if ( $cardinality ne "?" && !$self->retagSimpleRule($rulename, $mxelement, $cardinality, $context, {abortatfirstlevel => 'true'}) )
Branch: 1 branch
BranchTrueFalseTotal
if ($cardinality ne "?" and not $self->retagSimpleRule($rulename, $mxelement, $cardinality, $context, {"abortatfirstlevel", "true"})) 0 9 9
Condition66%2/3
$cardinality ne "?" and not $self->retagSimpleRule($rulename, $mxelement, $cardinality, $context, {"abortatfirstlevel", "true"})
!ll&&!rl&&r
450
MC/DC0%0/2
$cardinality ne "?" and not $self->retagSimpleRule($rulename, $mxelement, $cardinality, $context, {"abortatfirstlevel", "true"})
$cardinality ne "?" not $self->retagSimpleRule($rulename, $mxelement, $cardinality, $context, {"abortatfirstlevel", "true"})
Truth table66%2/3
A and not(B)
A= $cardinality ne "?"B= not $self->retagSimpleRule($rulename, $mxelement, $cardinality, $context, {"abortatfirstlevel", "true"})
ABresult
0X0
100
111
1030 {
1031 0 ▶ mydie "INTERNAL: no destination for cardinality found in rule '$rulename'" if scalar @$rhslist > 1;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$rhslist > 1 0 0 0
1032 0 ▶ $mxelement->{cardinality} = $cardinality if $cardinality ne "?";
Branch: 1 branch
BranchTrueFalseTotal
if $cardinality ne "?" 0 0 0
1033 }
1034 }
1035  
1036 # cardinality-annotated subrules loose lexeme status
1037 10 delete $mxelement->{class4list};
1038 10 delete $mxelement->{isLexeme};
1039 10 $groupisLexeme->{status} = -1;
1040 }
1041  
1042 60 mergeClass4List( \%$class4list, $mxelement );
1043 60 mergeClass4List( \%$class4group, $mxelement );
1044 60 mergeKeywordFragment( \%$keywordfragment, $mxelement );
1045  
1046 60 push @$currentlist, $mxelement;
1047 60 ++$alternativelength;
1048  
1049 ##
1050 # a list of lexemes is not itself a lexeme (unless declared in the 'lexer' grammar).
1051 ##
1052 60 ▶ $groupisLexeme->{status} = -1 if $alternativelength > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $alternativelength > 1 26 34 60
1053 }
1054  
1055 ##
1056 # replace a keyword built from lower/upper case character classes by a literal.
1057 # keyword literals must start with a letter.
1058 ##
1059 23 ▶ if ($self->testoption("buildkeywords") && $keywordfragment->{status} == 0 && $keywordfragment->{value} =~ /^[a-z]/i)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->testoption("buildkeywords") and $keywordfragment->{"status"} == 0 and $keywordfragment->{"value"} =~ /^[a-z]/i) 0 23 23
Condition66%4/6
$self->testoption("buildkeywords") and $keywordfragment->{"status"} == 0 and $keywordfragment->{"value"} =~ /^[a-z]/i
!ll&&!rl&&r
2030
$self->testoption("buildkeywords") and $keywordfragment->{"status"} == 0
!ll&&!rl&&r
0203
MC/DC0%0/3
$self->testoption("buildkeywords") and $keywordfragment->{"status"} == 0 and $keywordfragment->{"value"} =~ /^[a-z]/i
$self->testoption("buildkeywords") $keywordfragment->{"status"} == 0 $keywordfragment->{"value"} =~ /^[a-z]/i
Truth table50%2/4
A and B and C
A= $self->testoption("buildkeywords")B= $keywordfragment->{"status"} == 0C= $keywordfragment->{"value"} =~ /^[a-z]/i
ABCresult
0XX0
10X0
1100
1111
1060 {
1061 $currentlist = [
1062 0 { type => 'literal', value => $keywordfragment->{value}, isLexeme => 1 }
1063 ];
1064 0 $groupisLexeme->{status} = 0;
1065 }
1066  
1067 ##
1068 # append the current list to the alternative list if it has entries.
1069 ##
1070 23 ▶ if ( scalar @$currentlist > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$currentlist > 0) 23 0 23
1071 {
1072 23 my $newlist = { list => $currentlist };
1073 23 ▶ $newlist->{class4list} = $class4list->{value} if $class4list->{status} != -1;
Branch: 1 branch
BranchTrueFalseTotal
if $class4list->{"status"} != -1 3 20 23
1074 23 ▶ $newlist->{isLexeme} = 1 if $groupisLexeme->{status} == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $groupisLexeme->{"status"} == 0 1 22 23
1075 23 ▶ $newlist->{metalist} = $metalist if exists $metalist->{state};
Branch: 1 branch
BranchTrueFalseTotal
if exists $metalist->{"state"} 0 23 23
1076 23 push @$alternativelists, $newlist;
1077 }
1078  
1079 ##
1080 # remove branches that are case-equivalent
1081 ##
1082 23 ▶ $alternativelists = $self->removeCaseEquivalentBranches($alternativelists) if $self->testoption('matchcaseinsensitive');
Branch: 1 branch
BranchTrueFalseTotal
if $self->testoption("matchcaseinsensitive") 23 0 23
1083  
1084 23 my $grouplist = { type => 'group', list => $alternativelists };
1085 # single lists of literals can be tagged as lexemes
1086 # regular rules with alternative right sides will be tagged as G1
1087 23 ▶ $grouplist->{class4list} = $class4group->{value} if $class4group->{status} != -1;
Branch: 1 branch
BranchTrueFalseTotal
if $class4group->{"status"} != -1 1 22 23
1088 23 ▶ $grouplist->{isLexeme} = 1 if $groupisLexeme->{status} == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $groupisLexeme->{"status"} == 0 1 22 23
1089  
1090 23 return $grouplist;
1091 }
1092  
1093 ## ------------------------------------------------------
1094 # 'walkgroup' processes the tokens from a parenthesized group
1095 # or from a complete rule
1096 ## ------------------------------------------------------
1097 sub walkgroup
1098 9 ▶{
Subroutine walkgroup: called CC=3 SCAR=11.8
Pod undocumented
1099 9 my ($self, $rulename, $tokengroup, $context) = @_;
1100  
1101 9 ▶ $self->abortWithError( "INTERNAL: group is missing 'definition' in rule $rulename", $tokengroup ) if ref $tokengroup ne 'HASH' || !exists $tokengroup->{definition};
Branch: 1 branch
BranchTrueFalseTotal
if ref $tokengroup ne "HASH" or not exists $tokengroup->{"definition"} 0 9 9
Condition33%1/3
ref $tokengroup ne "HASH" or not exists $tokengroup->{"definition"}
l!l&&r!l&&!r
009
MC/DC0%0/2
ref $tokengroup ne "HASH" or not exists $tokengroup->{"definition"}
ref $tokengroup ne "HASH" not exists $tokengroup->{"definition"}
Truth table33%1/3
A or not(B)
A= ref $tokengroup ne "HASH"B= not exists $tokengroup->{"definition"}
ABresult
1X1
011
000
1102 9 my $definition = $tokengroup->{definition};
1103 9 my $grouplist = $self->processRightSides( $rulename, $definition, $context );
1104  
1105 9 return $grouplist;
1106 }
1107  
1108 ## ------------------------------------------------------
1109 # 'walkrule' processes the 'rightsides' list of a parsed rule
1110 ## ------------------------------------------------------
1111 sub walkrule
1112 23 ▶{
Subroutine walkrule: called CC=18 SCAR=31.5
Pod undocumented
1113 23 my ($self, $rulename, $rule, $context) = @_;
1114  
1115 # if ( $rulename eq "outer_join_sign")
1116 # {
1117 # printf "found!\n";
1118 # }
1119  
1120 23 my $symboltable = $self->symboltable;
1121 23 my $rulestatus = $symboltable->rulestatus($rulename);
1122  
1123 # test if we traversed this node already
1124 23 ▶ if ( defined $rulestatus )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rulestatus) 9 14 23
1125 {
1126 9 my $mxrule;
1127  
1128 SWITCH: {
1129 9 ▶ ($rulestatus eq "inprogress") && do {$mxrule = $symboltable->rule( $rulename ); last SWITCH; };
Branch: 1 branch
BranchTrueFalseTotal
$rulestatus eq "inprogress" and do { $mxrule = $symboltable->rule($rulename); last SWITCH } 3 6 9
1130 6 ▶ ($rulestatus eq "done") && do {$mxrule = $self->getMarpaRule( undef, $rulename ); last SWITCH; };
Branch: 1 branch
BranchTrueFalseTotal
$rulestatus eq "done" and do { $mxrule = $self->getMarpaRule(undef, $rulename); last SWITCH } 6 0 6
1131 ($rulestatus eq "synthetic" && !$self->checkMarpaRuleExists($rulename)) && do
1132 0 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
$rulestatus eq "synthetic" and not $self->checkMarpaRuleExists($rulename) and do { my $mxrightside = $self->processRightSides($rulename, $rule->{"rightsides"}, $context); $self->addMarpaRule($rulename, $mxrightside); $symboltable->tagrule($rulename, "done"); $rulestatus = $symboltable->rulestatus($rulename); $mxrule = {}; last SWITCH } 0 0 0
Condition0%0/3
$rulestatus eq "synthetic" and not $self->checkMarpaRuleExists($rulename)
!ll&&!rl&&r
000
MC/DC0%0/2
$rulestatus eq "synthetic" and not $self->checkMarpaRuleExists($rulename)
$rulestatus eq "synthetic" not $self->checkMarpaRuleExists($rulename)
Truth table0%0/3
A and not(B)
A= $rulestatus eq "synthetic"B= not $self->checkMarpaRuleExists($rulename)
ABresult
0X0
100
111
1133 0 my $mxrightside = $self->processRightSides( $rulename, $rule->{rightsides}, $context );
1134 0 $self->addMarpaRule($rulename, $mxrightside);
1135 0 $symboltable->tagrule($rulename, 'done');
1136 0 $rulestatus = $symboltable->rulestatus($rulename);
1137 0 $mxrule = {};
1138 0 last SWITCH;
1139 };
1140 0 do { mydie "unexpected rule status $rulestatus in rule $rulename" };
1141 }
1142  
1143 9 my $result = { mxrule => $rulename, rhs => { token => $rulename } };
1144 9 ▶ $result->{class4list} = $mxrule->{class4list} if exists $mxrule->{class4list};
Branch: 1 branch
BranchTrueFalseTotal
if exists $mxrule->{"class4list"} 3 6 9
1145  
1146 9 return $result;
1147 }
1148  
1149 14 $self->enterLevel($rulename, $context);
1150  
1151 14 my $mxrightside = {};
1152 14 my $rightside = $rule->{rightsides};
1153 14 ▶ if (defined $rightside)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rightside) 14 0 14
1154 {
1155 14 ▶ $self->abortWithError( "rhs is not an array ref in $rulename", $rightside ) if ref $rightside ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $rightside ne "ARRAY" 0 14 14
1156  
1157 14 ▶ $context->{subruleindex}{$rulename}{grammarstate} = $rule->{grammarstate} if exists $rule->{grammarstate} && $rule->{grammarstate} eq "lexer";
Branch: 1 branch
BranchTrueFalseTotal
if exists $rule->{"grammarstate"} and $rule->{"grammarstate"} eq "lexer" 9 5 14
Condition66%2/3
exists $rule->{"grammarstate"} and $rule->{"grammarstate"} eq "lexer"
!ll&&!rl&&r
509
MC/DC50%1/2
exists $rule->{"grammarstate"} and $rule->{"grammarstate"} eq "lexer"
exists $rule->{"grammarstate"} $rule->{"grammarstate"} eq "lexer"
Truth table66%2/3
A and B
A= exists $rule->{"grammarstate"}B= $rule->{"grammarstate"} eq "lexer"
ABresult
0X0
100
111
1158 14 ▶ $context->{subruleindex}{$rulename}{isFragmentOrChild} = 'true' if exists $rule->{type} && $rule->{type} eq "fragment";
Branch: 1 branch
BranchTrueFalseTotal
if exists $rule->{"type"} and $rule->{"type"} eq "fragment" 6 8 14
Condition66%2/3
exists $rule->{"type"} and $rule->{"type"} eq "fragment"
!ll&&!rl&&r
806
MC/DC50%1/2
exists $rule->{"type"} and $rule->{"type"} eq "fragment"
exists $rule->{"type"} $rule->{"type"} eq "fragment"
Truth table66%2/3
A and B
A= exists $rule->{"type"}B= $rule->{"type"} eq "fragment"
ABresult
0X0
100
111
1159  
1160 ##
1161 # prevent infinite recursion by tagging any symbol
1162 # before processing begins with 'inprogress'.
1163 # the 'defined($rulestatus)' clause at the top ensures
1164 # that we don't pick up a symbol that is already
1165 # being processed.
1166 ##
1167 14 $symboltable->tagrule($rulename, 'inprogress');
1168 14 $mxrightside = $self->processRightSides( $rulename, $rightside, $context );
1169 14 $symboltable->tagrule($rulename, 'done');
1170 }
1171  
1172 14 ▶ $mxrightside->{grammarstate} = $rule->{grammarstate} if exists $rule->{grammarstate} && $rule->{grammarstate} eq "lexer";
Branch: 1 branch
BranchTrueFalseTotal
if exists $rule->{"grammarstate"} and $rule->{"grammarstate"} eq "lexer" 9 5 14
Condition66%2/3
exists $rule->{"grammarstate"} and $rule->{"grammarstate"} eq "lexer"
!ll&&!rl&&r
509
MC/DC50%1/2
exists $rule->{"grammarstate"} and $rule->{"grammarstate"} eq "lexer"
exists $rule->{"grammarstate"} $rule->{"grammarstate"} eq "lexer"
Truth table66%2/3
A and B
A= exists $rule->{"grammarstate"}B= $rule->{"grammarstate"} eq "lexer"
ABresult
0X0
100
111
1173 14 ▶ $mxrightside->{isFragmentOrChild} = 'true' if exists $rule->{type} && $rule->{type} eq "fragment";
Branch: 1 branch
BranchTrueFalseTotal
if exists $rule->{"type"} and $rule->{"type"} eq "fragment" 6 8 14
Condition66%2/3
exists $rule->{"type"} and $rule->{"type"} eq "fragment"
!ll&&!rl&&r
806
MC/DC50%1/2
exists $rule->{"type"} and $rule->{"type"} eq "fragment"
exists $rule->{"type"} $rule->{"type"} eq "fragment"
Truth table66%2/3
A and B
A= exists $rule->{"type"}B= $rule->{"type"} eq "fragment"
ABresult
0X0
100
111
1174 14 ▶ if (exists $rule->{redirect})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $rule->{"redirect"}) 1 13 14
1175 {
1176 1 $mxrightside->{redirected} = 'true';
1177 1 push @{$self->{discarded}}, $rulename;
1178 }
1179  
1180 14 $self->addMarpaRule($rulename, $mxrightside);
1181  
1182 14 $self->exitLevel($rulename, $context);
1183  
1184 14 return $mxrightside;
1185 }
1186  
1187 ## ------------------------------------------------------
1188 # 'processSub' processes a reference to a G4 subrule
1189 ## ------------------------------------------------------
1190 sub processSubRule
1191 21 ▶{
Subroutine processSubRule: called CC=2 SCAR=6.9
Pod undocumented
1192 21 my ($self, $rulename, $context) = @_;
1193  
1194 21 my $symboltable = $self->symboltable;
1195 21 my $rule = $symboltable->rule($rulename);
1196  
1197 21 my $mxrule = $self->walkrule( $rulename, $rule, $context );
1198  
1199 21 my $result = { rule => $rulename, rhs => { token => $rulename } };
1200  
1201 21 my $keywordfragment = $self->isKeywordFragment($rulename, $mxrule);
1202 21 ▶ $result->{keywordfragment} = $keywordfragment if defined $keywordfragment;
Branch: 1 branch
BranchTrueFalseTotal
if defined $keywordfragment 4 17 21
1203  
1204 21 return $result;
1205 }
1206  
1207 ## ------------------------------------------------------
1208 # 'reportUnusedRules' report all symbol table entries
1209 # that are not referred to by
1210 # parent rules.
1211 ## ------------------------------------------------------
1212 sub printHeaderUnusedRulesReport
1213 0 ▶{
Subroutine printHeaderUnusedRulesReport: not called CC=1 SCAR=6.9
Pod undocumented
1214 0 printf "\n";
1215 0 printf "WARNING: the rules listed below are orphaned. They can't be reached from the start rule:\n";
1216 0 printf "=======:\n\n";
1217 0 printf <<'END_OF_SOURCE';
1218 +----------------------------- rule name
1219 +--!----------------------------- Lexical (L) or parser rule
1220 +--!--!----------------------------- Fragment (F) or regular rule
1221 ! ! !
1222 V V V
1223 END_OF_SOURCE
1224 }
1225  
1226 sub reportUnusedRules
1227 1 ▶{
Subroutine reportUnusedRules: called CC=8 SCAR=30.8
Pod undocumented
1228 1 my ($self) = @_;
1229  
1230 1 my $symboltable = $self->symboltable;
1231  
1232 1 my $status = 0;
1233 1 my @symbols = $symboltable->symbols;
1234  
1235 1 for my $rulename (sort @symbols)
1236 {
1237 14 my $rule = $symboltable->rule($rulename);
1238 14 ▶ if (!exists $rule->{generationstatus})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $rule->{"generationstatus"}) 0 14 14
1239 {
1240 0 ▶ if (!$status)
Branch: 1 branch
BranchTrueFalseTotal
unless ($status) 0 0 0
1241 {
1242 0 printHeaderUnusedRulesReport();
1243 0 $status = 1;
1244 }
1245  
1246 printf "[%1s][%1s] %s\n",
1247 (exists $rule->{grammarstate} && $rule->{grammarstate} =~ /lexer/i) ? "L" : "",
1248 0 ▶ (exists $rule->{isFragmentOrChild}) ? "F" : "",
Branch: 2 branches
BranchTrueFalseTotal
exists $rule->{'grammarstate'} && $rule->{'grammarstate'} =~ /lexer/i ? : 0 0 0
exists $rule->{'isFragmentOrChild'} ? : 0 0 0
Condition0%0/3
exists $rule->{"grammarstate"} and $rule->{"grammarstate"} =~ /lexer/i
!ll&&!rl&&r
000
MC/DC0%0/2
exists $rule->{"grammarstate"} and $rule->{"grammarstate"} =~ /lexer/i
exists $rule->{"grammarstate"} $rule->{"grammarstate"} =~ /lexer/i
Truth table0%0/3
A and B
A= exists $rule->{"grammarstate"}B= $rule->{"grammarstate"} =~ /lexer/i
ABresult
0X0
100
111
1249 $rulename;
1250 }
1251 }
1252  
1253 1 ▶ printf "\n\n" if $status;
Branch: 1 branch
BranchTrueFalseTotal
if $status 0 1 1
1254 }
1255  
1256 ## ------------------------------------------------------
1257 # 'processRedirectRules' define Marpa rules for all
1258 # G4 rules that are tagged 'redirect'
1259 # and are not referred in parent rules
1260 ## ------------------------------------------------------
1261 sub processRedirectRules
1262 1 ▶{
Subroutine processRedirectRules: called CC=4 SCAR=13.9
Pod undocumented
1263 1 my ($self) = @_;
1264  
1265 1 my $symboltable = $self->symboltable;
1266  
1267 1 my @symbols = $symboltable->symbols;
1268  
1269 1 for my $rulename (sort @symbols)
1270 {
1271 14 my $rule = $symboltable->rule($rulename);
1272 14 ▶ if (!exists $rule->{generationstatus} && exists $rule->{redirect})
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $rule->{"generationstatus"} and exists $rule->{"redirect"}) 1 13 14
Condition66%2/3
not exists $rule->{"generationstatus"} and exists $rule->{"redirect"}
!ll&&!rl&&r
1301
MC/DC50%1/2
not exists $rule->{"generationstatus"} and exists $rule->{"redirect"}
not exists $rule->{"generationstatus"} exists $rule->{"redirect"}
Truth table66%2/3
not(A) and B
A= not exists $rule->{"generationstatus"}B= exists $rule->{"redirect"}
ABresult
0X0
100
111
1273 {
1274 1 $self->walkrule( $rulename, $rule, {level => 0} );
1275 }
1276 }
1277 }
1278  
1279 ## -------------------------------------------------------------------------------------
1280 # 'translateG4Grammar' create nested Marpa rules for the G4 rules from the symbol table
1281 # by doing a depth-first traversal starting with the grammar's
1282 # start symbol.
1283 # this creates the convex hull of the start symbol collecting all
1284 # symbols that can be reached from the start symbol.
1285 # 'reportUnusedRules' creates a report of all symbols from the
1286 # parse tree that are not part of the convex hull.
1287 ## -------------------------------------------------------------------------------------
1288 sub translateG4Grammar
1289 1 ▶{
Subroutine translateG4Grammar: called CC=2 SCAR=6.9
Pod undocumented
1290 1 my ($self) = @_;
1291  
1292 1 my $symboltable = $self->symboltable;
1293  
1294 1 my $startrule = $symboltable->startrule;
1295 1 my $startrulename = $startrule->{name};
1296 1 $startrule = $symboltable->rule($startrulename);
1297  
1298 1 ▶ mydie "INTERNAL: start rule $startrulename is missing 'rightsides'" if !exists $startrule->{rightsides};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $startrule->{"rightsides"} 0 1 1
1299  
1300 1 $self->walkrule( $startrulename, $startrule, {level => 0} );
1301  
1302 1 $self->processRedirectRules;
1303 1 $self->reportUnusedRules;
1304 }
1305  
1306 ## ================================================== #
1307 # write the generated Marpa rules to the output file #
1308 ## ================================================== #
1309  
1310 sub openOutputFile
1311 1 ▶{
Subroutine openOutputFile: called CC=3 SCAR=11.8
Pod undocumented
1312 1 my ($self) = @_;
1313  
1314 1 my $outputfile = $self->{outputfilename};
1315  
1316 1 ▶ if ( $outputfile ne "-" )
Branch: 1 branch
BranchTrueFalseTotal
if ($outputfile ne '-') { } 1 0 1
1317 {
1318 1 my $outf;
1319 1 ▶ mydie("cannot open output file $outputfile") unless open( $outf, ">$outputfile" );
Branch: 1 branch
BranchTrueFalseTotal
unless open $outf, ">$outputfile" 0 1 1
1320 1 $self->{outf} = $outf;
1321 1 $self->{is_stdout} = 0;
1322 }
1323 else
1324 {
1325 0 $self->{outf} = *STDOUT;
1326 0 $self->{is_stdout} = 1;
1327 }
1328 }
1329  
1330 sub closeOutputFile
1331 1 ▶{
Subroutine closeOutputFile: called CC=2 SCAR=7.2
Pod undocumented
1332 1 my ($self) = @_;
1333 1 ▶ close($self->{outf}) if $self->{is_stdout};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"is_stdout"} 0 1 1
1334 }
1335  
1336 sub pad
1337 50 ▶{
Subroutine pad: called CC=3 SCAR=11.0
Pod undocumented
1338 50 my ($self, $s ) = @_;
1339  
1340 50 ▶ return undef if !defined $s;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 0 50 50
1341  
1342 50 my $len = length($s);
1343 50 my $pad = $self->{indent} - $len;
1344  
1345 50 ▶ return $s if $pad < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $pad < 0 1 49 50
1346  
1347 49 return $s . (" " x $pad);
1348 }
1349  
1350 sub renderComment
1351 0 ▶{
Subroutine renderComment: not called CC=4 SCAR=30.0
Pod undocumented
1352 0 my ($self, $rulename, $comments) = @_;
1353  
1354 0 ▶ mydie "INTERNAL : 'comments' is not an array in rule $rulename" if ref $comments ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $comments ne "ARRAY" 0 0 0
1355  
1356 0 my $result = [];
1357 0 for my $comment (@$comments)
1358 {
1359 0 $comment =~ s/\/\*(.*)\*\//$1/;
1360 0 my @commentlist = split '\n', $comment;
1361  
1362 0 for my $cl (@commentlist)
1363 {
1364 0 $cl =~ s/^\/\/\s*//;
1365 0 $cl =~ s/^#\s*//;
1366 0 push @$result, "# ${cl}";
1367 }
1368 }
1369  
1370 0 return $result;
1371 }
1372  
1373 sub processRedirected
1374 39 ▶{
Subroutine processRedirected: called CC=5 SCAR=19.7
Pod undocumented
1375 39 my ($self, $token) = @_;
1376  
1377 39 ▶ mydie "processRedirected : 'token' must be a scalar" if ref $token ne "";
Branch: 1 branch
BranchTrueFalseTotal
if ref $token ne "" 0 39 39
1378  
1379 39 my $rule = $self->getMarpaRule(undef, $token);
1380  
1381 39 ▶ if ($self->testoption('matchcaseinsensitive') && $self->isKeywordLetter($token, $rule))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->testoption("matchcaseinsensitive") and $self->isKeywordLetter($token, $rule)) 0 39 39
Condition33%1/3
$self->testoption("matchcaseinsensitive") and $self->isKeywordLetter($token, $rule)
!ll&&!rl&&r
0390
MC/DC0%0/2
$self->testoption("matchcaseinsensitive") and $self->isKeywordLetter($token, $rule)
$self->testoption("matchcaseinsensitive") $self->isKeywordLetter($token, $rule)
Truth table33%1/3
A and B
A= $self->testoption("matchcaseinsensitive")B= $self->isKeywordLetter($token, $rule)
ABresult
0X0
100
111
1382 {
1383 0 my $value = $rule->{class4list};
1384 0 $value = substr($value, 0, 1);
1385 0 return { value => "'${value}':i" };
1386 }
1387  
1388 39 ▶ return { discard => 'true' } if exists $rule->{redirected};
Branch: 1 branch
BranchTrueFalseTotal
if exists $rule->{"redirected"} 0 39 39
1389  
1390 39 return { value => $token };
1391 }
1392  
1393 sub fragmentEligible2Convert
1394 28 ▶{
Subroutine fragmentEligible2Convert: called CC=2 SCAR=6.9
Pod undocumented
1395 28 my ($rule) = @_;
1396  
1397 28 ▶ return 0 if !exists $rule->{class4list};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $rule->{"class4list"} 27 1 28
1398 1 my $class4list = $rule->{class4list};
1399  
1400 # replace escaped characters and unicode codepoints with a single character
1401 1 $class4list =~ s/\\([^u])/$1/g;
1402 1 $class4list =~ s/\\u([0-9a-f]{4,4})/u/ig;
1403  
1404 1 return length($class4list) > 1;
1405 }
1406  
1407 sub writeFragmentAsClass
1408 1 ▶{
Subroutine writeFragmentAsClass: called CC=1 SCAR=0.0
Pod undocumented
1409 1 my ($self, $rulename, $rule, $options ) = @_;
1410  
1411 1 my $synthclass = { type => "class", value => $rule->{class4list} };
1412 1 my $outputline = $self->printRhs( $rulename, $synthclass, {status => 0, delimiter => '|', assignop => '~'} );
1413 1 $self->deleteAllSubrules($rulename);
1414  
1415 1 my $outf = $self->{outf};
1416 1 printf $outf "%s\n", $outputline;
1417 }
1418  
1419 #
1420 # translateunicode : translate unicodes embedded in literals or classes.
1421 # die if we are in codepages beyond 00
1422 ##
1423 sub translateunicode
1424 30 ▶{
Subroutine translateunicode: called CC=6 SCAR=23.1
Pod undocumented
1425 30 my ($self, $rulename, $string ) = @_;
1426  
1427 30 ▶ while ( $string =~ /(\\u([0-9A-F]{4,4}))|(\\u\{([0-9A-F]+)\})/i )
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /(\\u([0-9A-F]{4,4}))|(\\u\{([0-9A-F]+)\})/i) 2 30 32
1428 {
1429 2 my $fourmatch = $2;
1430 2 my $bracedmatch = $4;
1431  
1432 SWITCH: {
1433 2 ▶ (defined $fourmatch) && do {
Branch: 1 branch
BranchTrueFalseTotal
defined $fourmatch and do { mydie("translateunicode : class string $string not in codepage 00 in $rulename") unless $fourmatch =~ /00([0-9A-Z][0-9A-Z])/i; my $translatedcode = $1; $string =~ s/\\u$fourmatch/\\x$translatedcode/i; last SWITCH } 2 0 2
1434 2 ▶ mydie "translateunicode : class string $string not in codepage 00 in $rulename" if $fourmatch !~ /00([0-9A-Z][0-9A-Z])/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $fourmatch =~ /00([0-9A-Z][0-9A-Z])/i 0 2 2
1435 2 my $translatedcode = $1;
1436 2 $string =~ s/\\u${fourmatch}/\\x${translatedcode}/i;
1437 2 last SWITCH;
1438 };
1439 0 ▶ (defined $bracedmatch) && do {
Branch: 1 branch
BranchTrueFalseTotal
defined $bracedmatch and do { mydie("translateunicode : class string $string not in codepage 00 in $rulename") unless $bracedmatch =~ /0*([0-9A-Z]{2,2})/i; my $translatedcode = $1; $string =~ s/\\u\{$bracedmatch\}/\\x$translatedcode/i; last SWITCH } 0 0 0
1440 0 ▶ mydie "translateunicode : class string $string not in codepage 00 in $rulename" if $bracedmatch !~ /0*([0-9A-Z]{2,2})/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $bracedmatch =~ /0*([0-9A-Z]{2,2})/i 0 0 0
1441 0 my $translatedcode = $1;
1442 0 $string =~ s/\\u\{${bracedmatch}\}/\\x${translatedcode}/i;
1443 0 last SWITCH;
1444 };
1445 0 do {
1446 0 mydie "translateunicode : unexpected match";
1447 0 last SWITCH;
1448 };
1449 }
1450 }
1451  
1452 30 return $string;
1453 }
1454  
1455 #
1456 # normalizeClassString : remove class elements that are redundant when the class is made case-insensitive
1457 # return the modified class text as well as an indicator if the class contains letters
1458 ##
1459 sub normalizeClassString
1460 3 ▶{
Subroutine normalizeClassString: called CC=15 SCAR=28.4
Pod undocumented
1461 3 my ($self, $classstring ) = @_;
1462  
1463 3 my $classhash = {};
1464 3 my $characterhash = {};
1465  
1466 # strip [/] from classtring
1467 3 $classstring =~ s/^\[([^\]]*)\]$/$1/;
1468  
1469 3 my $result = "";
1470 3 my $isalphaclass = 0;
1471 3 ▶ while ( $classstring ne "" )
Branch: 1 branch
BranchTrueFalseTotal
if ($classstring ne "") 12 3 15
1472 {
1473 SWITCH: {
1474 12 ▶ ($classstring =~ /(\\[ux][0-9a-f]+)-(\\[ux][0-9a-f]+)(.*)$/i) && do {
Branch: 1 branch
BranchTrueFalseTotal
$classstring =~ /(\\[ux][0-9a-f]+)-(\\[ux][0-9a-f]+)(.*)$/i and do { my $beg = $1; my $end = $2; $result .= "$1-$2"; $classstring = $3; last SWITCH } 0 12 12
1475 0 my $beg = $1;
1476 0 my $end = $2;
1477 0 $result .= "${1}-${2}";
1478 0 $classstring = $3;
1479 0 last SWITCH;
1480 };
1481 12 ▶ ($classstring =~ /(\\[ux][0-9a-f]{2,4})(.*)$/i) && do {
Branch: 1 branch
BranchTrueFalseTotal
$classstring =~ /(\\[ux][0-9a-f]{2,4})(.*)$/i and do { my $c = $1; $result .= $c; $classstring = $2; last SWITCH } 0 12 12
1482 0 my $c = $1;
1483 0 $result .= $c;
1484 0 $classstring = $2;
1485 0 last SWITCH;
1486 };
1487 12 ▶ ($classstring =~ /([^-])-([^-])(.*)$/) && do {
Branch: 1 branch
BranchTrueFalseTotal
$classstring =~ /([^-])-([^-])(.*)$/ and do { my $beg = $1; my $end = $2; my $key = "$beg-$end"; unless (exists $$classhash{lc $key} or exists $$classhash{uc $key}) { $classhash->{$key} = 1; $result .= $key; $isalphaclass = 1 if $beg =~ /[a-z]/i or $end =~ /[a-z]/i; } ; $classstring = $3; last SWITCH } 3 9 12
1488 3 my $beg = $1;
1489 3 my $end = $2;
1490 3 my $key = "${beg}-${end}";
1491 3 ▶ if (!exists $classhash->{lc $key} && !exists $classhash->{uc $key})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $$classhash{lc $key} or exists $$classhash{uc $key}) 2 1 3
Condition66%2/3
exists $$classhash{lc $key} or exists $$classhash{uc $key}
l!l&&r!l&&!r
102
MC/DC50%1/2
exists $$classhash{lc $key} or exists $$classhash{uc $key}
exists $$classhash{lc $key} exists $$classhash{uc $key}
Truth table66%2/3
A or B
A= exists $$classhash{lc $key}B= exists $$classhash{uc $key}
ABresult
1X1
011
000
1492 {
1493 2 $classhash->{$key} = 1;
1494 2 $result .= $key;
1495 2 ▶ $isalphaclass = 1 if $beg =~ /[a-z]/i || $end =~ /[a-z]/i;
Branch: 1 branch
BranchTrueFalseTotal
if $beg =~ /[a-z]/i or $end =~ /[a-z]/i 1 1 2
Condition66%2/3
$beg =~ /[a-z]/i or $end =~ /[a-z]/i
l!l&&r!l&&!r
101
MC/DC50%1/2
$beg =~ /[a-z]/i or $end =~ /[a-z]/i
$beg =~ /[a-z]/i $end =~ /[a-z]/i
Truth table66%2/3
A or B
A= $beg =~ /[a-z]/iB= $end =~ /[a-z]/i
ABresult
1X1
011
000
1496 }
1497 3 $classstring = $3;
1498 3 last SWITCH;
1499 };
1500 9 ▶ ($classstring =~ /(\\.)(.*)$/) && do {
Branch: 1 branch
BranchTrueFalseTotal
$classstring =~ /(\\.)(.*)$/ and do { my $c = $1; unless (exists $characterhash->{$c}) { $characterhash->{$c} = 1; $result .= $c; } ; $classstring = $2; last SWITCH } 1 8 9
1501 1 my $c = $1;
1502 1 ▶ if (!exists $characterhash->{$c})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $characterhash->{$c}) 1 0 1
1503 {
1504 1 $characterhash->{$c} = 1;
1505 1 $result .= $c;
1506 }
1507 1 $classstring = $2;
1508 1 last SWITCH;
1509 };
1510 8 ▶ ($classstring =~ /(.)(.*)$/) && do {
Branch: 1 branch
BranchTrueFalseTotal
$classstring =~ /(.)(.*)$/ and do { my $c = $1; unless (exists $$characterhash{lc $c} or exists $$characterhash{uc $c}) { $characterhash->{$c} = 1; $result .= $c; $isalphaclass = 1 if $c =~ /^[a-z]$/i; } ; $classstring = $2; last SWITCH } 8 0 8
1511 8 my $c = $1;
1512 8 ▶ if (!exists $characterhash->{lc $c} && !exists $characterhash->{uc $c})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $$characterhash{lc $c} or exists $$characterhash{uc $c}) 7 1 8
Condition66%2/3
exists $$characterhash{lc $c} or exists $$characterhash{uc $c}
l!l&&r!l&&!r
017
MC/DC50%1/2
exists $$characterhash{lc $c} or exists $$characterhash{uc $c}
exists $$characterhash{lc $c} exists $$characterhash{uc $c}
Truth table66%2/3
A or B
A= exists $$characterhash{lc $c}B= exists $$characterhash{uc $c}
ABresult
1X1
011
000
1513 {
1514 7 $characterhash->{$c} = 1;
1515 7 $result .= $c;
1516 7 ▶ $isalphaclass = 1 if $c =~ /^[a-z]$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $c =~ /^[a-z]$/i 6 1 7
1517 }
1518 8 $classstring = $2;
1519 8 last SWITCH;
1520 };
1521 }
1522 }
1523  
1524 3 return { isalphaclass => $isalphaclass, classstring => $result };
1525 }
1526  
1527 sub isAlphaLiteral
1528 29 ▶{
Subroutine isAlphaLiteral: called CC=6 SCAR=17.9
Pod undocumented
1529 29 my ($self, $literal ) = @_;
1530  
1531 29 ▶ return 0 if $literal !~ /[a-z]/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $literal =~ /[a-z]/i 21 8 29
1532  
1533 8 my $isAlpha = 0;
1534  
1535 8 ▶ while ( $literal ne "" )
Branch: 1 branch
BranchTrueFalseTotal
if ($literal ne "") 43 8 51
1536 {
1537 SWITCH: {
1538 43 ▶ ($literal =~ /(\\.)(.*)$/) && do {
Branch: 1 branch
BranchTrueFalseTotal
$literal =~ /(\\.)(.*)$/ and do { my $c = $1; $literal = $2; last SWITCH } 4 39 43
1539 4 my $c = $1;
1540 4 $literal = $2;
1541 4 last SWITCH;
1542 };
1543 39 ▶ ($literal =~ /(.)(.*)$/) && do {
Branch: 1 branch
BranchTrueFalseTotal
$literal =~ /(.)(.*)$/ and do { my $c = $1; $literal = $2; $isAlpha = 1 if $c =~ /^[a-z]$/i; last SWITCH } 39 0 39
1544 39 my $c = $1;
1545 39 $literal = $2;
1546 39 ▶ $isAlpha = 1 if $c =~ /^[a-z]$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $c =~ /^[a-z]$/i 25 14 39
1547 39 last SWITCH;
1548 };
1549 }
1550 }
1551  
1552 8 return $isAlpha;
1553 }
1554  
1555 ##
1556 # computeRhs :
1557 ##
1558 sub computeRhs
1559 69 ▶{
Subroutine computeRhs: called CC=24 SCAR=39.2
Pod undocumented
1560 69 my ($self, $rulename, $rhs, $options ) = @_;
1561  
1562 # if ($rulename eq "HEXNUMBER_003")
1563 # {
1564 # printf "found!\n";
1565 # }
1566  
1567 SWITCH:
1568 {
1569 69 ▶ (exists $rhs->{type} && $rhs->{type} eq 'negatedclass') && do {
Branch: 1 branch
BranchTrueFalseTotal
exists $rhs->{"type"} and $rhs->{"type"} eq "negatedclass" and do { mydie("computeRhs : 'value' missing in negatedclass $rulename") unless exists $rhs->{"value"}; my $value = $rhs->{"value"}; $value = $self->translateunicode($rulename, $value); $rhs = {"value", "[$value]"}; last SWITCH } 1 68 69
Condition100%3/3
exists $rhs->{"type"} and $rhs->{"type"} eq "negatedclass"
!ll&&!rl&&r
39291
MC/DC100%2/2
exists $rhs->{"type"} and $rhs->{"type"} eq "negatedclass"
exists $rhs->{"type"} $rhs->{"type"} eq "negatedclass"
Truth table100%3/3
A and B
A= exists $rhs->{"type"}B= $rhs->{"type"} eq "negatedclass"
ABresult
0X0
100
111
1570 1 ▶ mydie "computeRhs : 'value' missing in negatedclass $rulename" if !exists $rhs->{value};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $rhs->{"value"} 0 1 1
1571 1 my $value = $rhs->{value};
1572 1 $value = $self->translateunicode($rulename, $value);
1573 1 $rhs = { value => "[${value}]" };
1574 1 last SWITCH;
1575 };
1576 68 ▶ (exists $rhs->{deletedafterconversiontoclass}) && do {
Branch: 1 branch
BranchTrueFalseTotal
exists $rhs->{"deletedafterconversiontoclass"} and do { $rhs = {"discard", "true"}; last SWITCH } 0 68 68
1577 0 $rhs = { discard => 'true' };
1578 0 last SWITCH;
1579 };
1580 68 ▶ (exists $rhs->{type} && $rhs->{type} eq 'unsupported') && do {
Branch: 1 branch
BranchTrueFalseTotal
exists $rhs->{"type"} and $rhs->{"type"} eq "unsupported" and do { mydie($rhs->{"msg"}); last SWITCH } 0 68 68
Condition66%2/3
exists $rhs->{"type"} and $rhs->{"type"} eq "unsupported"
!ll&&!rl&&r
39290
MC/DC0%0/2
exists $rhs->{"type"} and $rhs->{"type"} eq "unsupported"
exists $rhs->{"type"} $rhs->{"type"} eq "unsupported"
Truth table66%2/3
A and B
A= exists $rhs->{"type"}B= $rhs->{"type"} eq "unsupported"
ABresult
0X0
100
111
1581 0 mydie $rhs->{msg};
1582 0 last SWITCH;
1583 };
1584 68 ▶ (exists $rhs->{type} && $rhs->{type} eq 'class') && do {
Branch: 1 branch
BranchTrueFalseTotal
exists $rhs->{"type"} and $rhs->{"type"} eq "class" and do { my $value = $rhs->{"value"}; $value = $self->translateunicode($rulename, $value); my $modifier = ""; if ($self->testoption("matchcaseinsensitive") and $self->isAlphaLiteral($value)) { my $normclass = $self->normalizeClassString($value); $value = $normclass->{"classstring"}; $modifier = ":ic" if $normclass->{"isalphaclass"}; } ; $rhs = {"value", "[$value]$modifier"}; last SWITCH } 8 60 68
Condition100%3/3
exists $rhs->{"type"} and $rhs->{"type"} eq "class"
!ll&&!rl&&r
39218
MC/DC100%2/2
exists $rhs->{"type"} and $rhs->{"type"} eq "class"
exists $rhs->{"type"} $rhs->{"type"} eq "class"
Truth table100%3/3
A and B
A= exists $rhs->{"type"}B= $rhs->{"type"} eq "class"
ABresult
0X0
100
111
1585 8 my $value = $rhs->{value};
1586 8 $value = $self->translateunicode($rulename, $value);
1587 8 my $modifier = "";
1588 8 ▶ if ($self->testoption('matchcaseinsensitive') && $self->isAlphaLiteral($value))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->testoption("matchcaseinsensitive") and $self->isAlphaLiteral($value)) 3 5 8
Condition66%2/3
$self->testoption("matchcaseinsensitive") and $self->isAlphaLiteral($value)
!ll&&!rl&&r
053
MC/DC50%1/2
$self->testoption("matchcaseinsensitive") and $self->isAlphaLiteral($value)
$self->testoption("matchcaseinsensitive") $self->isAlphaLiteral($value)
Truth table66%2/3
A and B
A= $self->testoption("matchcaseinsensitive")B= $self->isAlphaLiteral($value)
ABresult
0X0
100
111
1589 {
1590 3 my $normclass = $self->normalizeClassString($value);
1591 3 $value = $normclass->{classstring};
1592 3 ▶ $modifier = ':ic' if $normclass->{isalphaclass};
Branch: 1 branch
BranchTrueFalseTotal
if $normclass->{"isalphaclass"} 3 0 3
1593 }
1594 8 $rhs = { value => "[${value}]${modifier}" };
1595 8 last SWITCH;
1596 };
1597 60 ▶ (exists $rhs->{type} && $rhs->{type} eq 'literal') && do {
Branch: 1 branch
BranchTrueFalseTotal
exists $rhs->{"type"} and $rhs->{"type"} eq "literal" and do { my $literal = $rhs->{"value"}; $literal = $self->translateunicode($rulename, $literal); $literal = $literal eq "\\'" ? "[']" : "'${literal}'"; if ($self->testoption("matchcaseinsensitive") and $self->isAlphaLiteral($literal)) { $literal = lc $literal; $literal .= ':i'; } ; $rhs = {"value", $literal}; last SWITCH } 21 39 60
Condition66%2/3
exists $rhs->{"type"} and $rhs->{"type"} eq "literal"
!ll&&!rl&&r
39021
MC/DC50%1/2
exists $rhs->{"type"} and $rhs->{"type"} eq "literal"
exists $rhs->{"type"} $rhs->{"type"} eq "literal"
Truth table66%2/3
A and B
A= exists $rhs->{"type"}B= $rhs->{"type"} eq "literal"
ABresult
0X0
100
111
1598 21 my $literal = $rhs->{value};
1599 21 $literal = $self->translateunicode($rulename, $literal);
1600 21 ▶ $literal = ($literal eq "\\'") ? "[']" : "'${literal}'";
Branch: 1 branch
BranchTrueFalseTotal
$literal eq q[\\'] ? : 0 21 21
1601 21 ▶ if ($self->testoption('matchcaseinsensitive') && $self->isAlphaLiteral($literal))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->testoption("matchcaseinsensitive") and $self->isAlphaLiteral($literal)) 4 17 21
Condition66%2/3
$self->testoption("matchcaseinsensitive") and $self->isAlphaLiteral($literal)
!ll&&!rl&&r
0174
MC/DC50%1/2
$self->testoption("matchcaseinsensitive") and $self->isAlphaLiteral($literal)
$self->testoption("matchcaseinsensitive") $self->isAlphaLiteral($literal)
Truth table66%2/3
A and B
A= $self->testoption("matchcaseinsensitive")B= $self->isAlphaLiteral($literal)
ABresult
0X0
100
111
1602 {
1603 4 $literal = lc $literal;
1604 4 $literal .= ':i';
1605 }
1606 21 $rhs = { value => $literal };
1607 21 last SWITCH;
1608 };
1609 39 ▶ (exists $rhs->{type} && $rhs->{type} eq 'action') && do {
Branch: 1 branch
BranchTrueFalseTotal
exists $rhs->{"type"} and $rhs->{"type"} eq "action" and do { push @{$$options{"comments"};}, ' # Action: ' . $rhs->{"token"}{"action"}; $rhs = {"discard", "true"}; last SWITCH } 0 39 39
Condition33%1/3
exists $rhs->{"type"} and $rhs->{"type"} eq "action"
!ll&&!rl&&r
3900
MC/DC0%0/2
exists $rhs->{"type"} and $rhs->{"type"} eq "action"
exists $rhs->{"type"} $rhs->{"type"} eq "action"
Truth table33%1/3
A and B
A= exists $rhs->{"type"}B= $rhs->{"type"} eq "action"
ABresult
0X0
100
111
1610 0 push @{$options->{comments}}, " # Action: " . $rhs->{token}{action};
1611 0 $rhs = { discard => 'true' };
1612 0 last SWITCH;
1613 };
1614 39 ▶ (exists $rhs->{rhs}) && do {
Branch: 1 branch
BranchTrueFalseTotal
exists $rhs->{"rhs"} and do { $rhs = $rhs->{"rhs"}; mydie("computeRhs: scalar 'token' missing in rhs") if not exists $rhs->{"token"} or ref $rhs->{"token"} ne ""; $rhs = $self->processRedirected($rhs->{"token"}); last SWITCH } 39 0 39
1615 39 $rhs = $rhs->{rhs};
1616 39 ▶ mydie "computeRhs: scalar 'token' missing in rhs" if !exists $rhs->{token} || ref $rhs->{token} ne "";
Branch: 1 branch
BranchTrueFalseTotal
if not exists $rhs->{"token"} or ref $rhs->{"token"} ne "" 0 39 39
Condition33%1/3
not exists $rhs->{"token"} or ref $rhs->{"token"} ne ""
l!l&&r!l&&!r
0039
MC/DC0%0/2
not exists $rhs->{"token"} or ref $rhs->{"token"} ne ""
not exists $rhs->{"token"} ref $rhs->{"token"} ne ""
Truth table33%1/3
not(A) or B
A= not exists $rhs->{"token"}B= ref $rhs->{"token"} ne ""
ABresult
1X1
011
000
1617 39 $rhs = $self->processRedirected($rhs->{token});
1618 39 last SWITCH;
1619 };
1620 0 ▶ (exists $rhs->{token}) && do {
Branch: 1 branch
BranchTrueFalseTotal
exists $rhs->{"token"} and do { $rhs = $self->processRedirected($rhs->{"token"}); last SWITCH } 0 0 0
1621 0 $rhs = $self->processRedirected($rhs->{token});
1622 0 last SWITCH;
1623 };
1624 0 ▶ (exists $rhs->{comments}) && do {
Branch: 1 branch
BranchTrueFalseTotal
exists $rhs->{"comments"} and do { my $cl = $self->renderComment($rulename, $rhs->{"comments"}); push @{$$options{"comments"};}, @$cl; $rhs = {"discard", "true"}; last SWITCH } 0 0 0
1625 0 my $cl = $self->renderComment($rulename, $rhs->{comments});
1626 0 push (@{$options->{comments}}, @$cl );
1627 0 $rhs = { discard => 'true' };
1628 0 last SWITCH;
1629 };
1630 0 do {
1631 0 $self->abortWithError( "computeRhs : don't know how to process rhs for $rulename, modify this rule to make it convertible", $rhs );
1632 };
1633 }
1634  
1635 69 return $rhs;
1636 }
1637  
1638 ##
1639 # printRhs : print a single right hand clause (alternative) of a rule.
1640 # depending on $option->{status} format the clause :
1641 # 0 : prefix the rule name and use '::=' or '~' as operator
1642 # 1 : start an alternative branch
1643 # 2 : add a clause to a branch
1644 ##
1645 sub printRhs
1646 69 ▶{
Subroutine printRhs: called CC=15 SCAR=28.4
Pod undocumented
1647 69 my ( $self, $rulename, $rule, $options ) = @_;
1648  
1649 69 ▶ mydie "printRhs: 'status' not defined for rule $rulename" if !exists $options->{status};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $options->{"status"} 0 69 69
1650  
1651 69 my $status = $options->{status};
1652 69 my $rhs = $self->computeRhs($rulename, $rule, $options);
1653  
1654 69 ▶ return "" if exists $rhs->{discard};
Branch: 1 branch
BranchTrueFalseTotal
if exists $rhs->{"discard"} 0 69 69
1655  
1656 69 ▶ mydie "'options' not well-defined" if ref $options ne 'HASH' || !exists $options->{delimiter};
Branch: 1 branch
BranchTrueFalseTotal
if ref $options ne "HASH" or not exists $options->{"delimiter"} 0 69 69
Condition33%1/3
ref $options ne "HASH" or not exists $options->{"delimiter"}
l!l&&r!l&&!r
0069
MC/DC0%0/2
ref $options ne "HASH" or not exists $options->{"delimiter"}
ref $options ne "HASH" not exists $options->{"delimiter"}
Truth table33%1/3
A or not(B)
A= ref $options ne "HASH"B= not exists $options->{"delimiter"}
ABresult
1X1
011
000
1657  
1658 69 my $delimiter = $options->{delimiter};
1659  
1660 69 my $cardinality = "";
1661 69 ▶ $cardinality = $options->{cardinality} if exists $options->{cardinality};
Branch: 1 branch
BranchTrueFalseTotal
if exists $options->{"cardinality"} 10 59 69
1662 69 ▶ $cardinality =~ s/([+*])\?/$1/ if $cardinality =~ /[+*]\?/ && $self->testoption('shiftlazytogreedy');
Branch: 1 branch
BranchTrueFalseTotal
if $cardinality =~ /[+*]\?/ and $self->testoption("shiftlazytogreedy") 0 69 69
Condition33%1/3
$cardinality =~ /[+*]\?/ and $self->testoption("shiftlazytogreedy")
!ll&&!rl&&r
6900
MC/DC0%0/2
$cardinality =~ /[+*]\?/ and $self->testoption("shiftlazytogreedy")
$cardinality =~ /[+*]\?/ $self->testoption("shiftlazytogreedy")
Truth table33%1/3
A and B
A= $cardinality =~ /[+*]\?/B= $self->testoption("shiftlazytogreedy")
ABresult
0X0
100
111
1663 69 ▶ mydie sprintf "lazy quantifier %s in rule %s not supported by Marpa", $cardinality, $rulename if $cardinality =~ /[+*]\?/;
Branch: 1 branch
BranchTrueFalseTotal
if $cardinality =~ /[+*]\?/ 0 69 69
1664  
1665 # if ($rulename eq "local_xmlindex_clause_001")
1666 # {
1667 # printf "found!\n";
1668 # }
1669  
1670 69 my $definitionop = "::=";
1671 69 ▶ $definitionop = $options->{assignop} if exists $options->{assignop};
Branch: 1 branch
BranchTrueFalseTotal
if exists $options->{"assignop"} 40 29 69
1672  
1673 69 my $result;
1674  
1675 # process optional rules
1676 69 ▶ if ( defined $cardinality && $cardinality eq "?")
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cardinality and $cardinality eq "?") 4 65 69
Condition66%2/3
defined $cardinality and $cardinality eq "?"
!ll&&!rl&&r
0654
MC/DC50%1/2
defined $cardinality and $cardinality eq "?"
defined $cardinality $cardinality eq "?"
Truth table66%2/3
A and B
A= defined $cardinalityB= $cardinality eq "?"
ABresult
0X0
100
111
1677 {
1678 4 $result = sprintf "%s %-3s %s%s\n", $self->pad($rulename), $definitionop, "", "";
1679 4 $cardinality = "";
1680 }
1681  
1682 SWITCH:
1683 {
1684 69 ▶ ($status == 0) && do {
Branch: 1 branch
BranchTrueFalseTotal
$status == 0 and do { $result .= sprintf("%s %-3s %s%s", $self->pad($rulename), $definitionop, $rhs->{"value"}, $cardinality); last SWITCH } 32 37 69
1685 32 $result .= sprintf "%s %-3s %s%s", $self->pad($rulename), $definitionop, $rhs->{value}, $cardinality;
1686 32 last SWITCH;
1687 };
1688 37 ▶ ($status == 1) && do {
Branch: 1 branch
BranchTrueFalseTotal
$status == 1 and do { $result .= sprintf("%s %-3s %s%s", $self->pad(""), $delimiter, $rhs->{"value"}, $cardinality); last SWITCH } 11 26 37
1689 11 $result .= sprintf "%s %-3s %s%s", $self->pad(""), $delimiter, $rhs->{value}, $cardinality;
1690 11 last SWITCH;
1691 };
1692 26 ▶ ($status == 2) && do {
Branch: 1 branch
BranchTrueFalseTotal
$status == 2 and do { $result .= sprintf(' %s%s', $rhs->{"value"}, $cardinality); last SWITCH } 26 0 26
1693 26 $result .= sprintf " %s%s", $rhs->{value}, $cardinality;
1694 26 last SWITCH;
1695 };
1696 0 do {
1697 0 mydie "printRhs : illegal status";
1698 };
1699 }
1700  
1701 69 return $result;
1702 }
1703  
1704 ##
1705 # writeMarpaRuleList : print all alternative branches of a rule
1706 ##
1707 sub writeMarpaRuleList
1708 22 ▶{
Subroutine writeMarpaRuleList: called CC=27 SCAR=49.8
Pod undocumented
1709 22 my ( $self, $rulename, $rule, $options ) = @_;
1710  
1711 # if ($rulename eq "SAFECODEPOINT")
1712 # {
1713 # printf "found!\n";
1714 # }
1715  
1716 22 $options->{status} = 0;
1717  
1718 22 my $outf = $self->{outf};
1719  
1720 22 ▶ mydie "writeMarpaRuleList : 'list' missing from 'rule' in $rulename" if !exists $rule->{list};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $rule->{"list"} 0 22 22
1721  
1722 22 my $list = $rule->{list};
1723 22 my $actiontext;
1724  
1725 22 for my $rulelist (@$list)
1726 {
1727 33 ▶ mydie "writeMarpaRuleList : 'list' missing from 'rulelist' in $rulename" if !exists $rulelist->{list};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $rulelist->{"list"} 0 33 33
1728  
1729 33 ▶ if (exists $rulelist->{metalist})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $rulelist->{"metalist"}) 0 33 33
1730 {
1731 0 my $metalist = $rulelist->{metalist};
1732  
1733 0 for my $cl (@{$metalist->{comments}})
1734 {
1735 0 ▶ $cl = $cl->[0] if ref $cl eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $cl eq "ARRAY" 0 0 0
1736 0 printf $outf "%s\n", $cl;
1737 }
1738 0 ▶ if (exists $metalist->{actions})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $metalist->{"actions"}) 0 0 0
1739 {
1740 0 ▶ if (!$self->testoption('embedactions'))
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->testoption('embedactions')) { } 0 0 0
1741 {
1742 0 for my $cl (@{$metalist->{actions}})
1743 {
1744 0 ▶ $cl = $cl->[0] if ref $cl eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $cl eq "ARRAY" 0 0 0
1745 0 printf $outf "%s\n", $cl;
1746 }
1747 }
1748 else
1749 {
1750 0 $actiontext = "";
1751 0 for my $cl (@{$metalist->{actions}})
1752 {
1753 0 ▶ $cl = $cl->[0] if ref $cl eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $cl eq "ARRAY" 0 0 0
1754 0 $actiontext .= $cl;
1755 }
1756 }
1757 }
1758 }
1759  
1760 33 my $outputline = "";
1761 33 my $linelen = 0;
1762  
1763 33 for my $rhs (@{$rulelist->{list}})
1764 {
1765 59 ▶ my $cardinality = $rhs->{cardinality} if exists $rhs->{cardinality};
Branch: 1 branch
BranchTrueFalseTotal
if exists $rhs->{"cardinality"} 1 58 59
1766  
1767 59 $options->{delimiter} = "|";
1768 59 ▶ $options->{cardinality} = $cardinality if defined $cardinality;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cardinality 1 58 59
1769  
1770 59 ▶ if (exists $rhs->{comments})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $rhs->{"comments"}) 0 59 59
1771 {
1772 0 my $cl = $rhs->{comments};
1773 0 mydie "TODO : comments";
1774 }
1775  
1776 59 my $nextclause;
1777  
1778 SWITCH:
1779 {
1780 59 ▶ (exists $rhs->{type} && $rhs->{type} eq "group" && exists $rhs->{list}) && do {
Branch: 1 branch
BranchTrueFalseTotal
exists $rhs->{"type"} and $rhs->{"type"} eq "group" and exists $rhs->{"list"} and do { if (exists $rhs->{"class4list"}) { $nextclause = $self->printRhs($rulename, $rhs, $options); $options->{"status"} = 2; } else { mydie("writeMarpaRuleList : unexpected embedded 'list'"); } ; last SWITCH } 0 59 59
Condition50%3/6
exists $rhs->{"type"} and $rhs->{"type"} eq "group" and exists $rhs->{"list"}
!ll&&!rl&&r
5900
exists $rhs->{"type"} and $rhs->{"type"} eq "group"
!ll&&!rl&&r
34250
MC/DC0%0/3
exists $rhs->{"type"} and $rhs->{"type"} eq "group" and exists $rhs->{"list"}
exists $rhs->{"type"} $rhs->{"type"} eq "group" exists $rhs->{"list"}
Truth table50%2/4
A and B and C
A= exists $rhs->{"type"}B= $rhs->{"type"} eq "group"C= exists $rhs->{"list"}
ABCresult
0XX0
10X0
1100
1111
1781 0 ▶ if ( exists $rhs->{class4list})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $rhs->{'class4list'}) { } 0 0 0
1782 {
1783 0 $nextclause = $self->printRhs( $rulename, $rhs, $options );
1784 0 $options->{status} = 2;
1785 }
1786 else
1787 {
1788 0 mydie "writeMarpaRuleList : unexpected embedded 'list'";
1789 }
1790 0 last SWITCH;
1791 };
1792 59 do {
1793 59 $nextclause = $self->printRhs( $rulename, $rhs, $options );
1794 59 $options->{status} = 2;
1795 59 last SWITCH;
1796 };
1797 }
1798  
1799 59 $options->{delimiter}= "|";
1800  
1801 59 ▶ if ($linelen + length($nextclause) > $self->{indent} + 3 + 125)
Branch: 1 branch
BranchTrueFalseTotal
if ($linelen + length($nextclause) > $self->{'indent'} + 3 + 125) { } 0 59 59
1802 {
1803 0 $outputline .= "\n" . (' ' x $self->{indent}) . (' ' x 3) . ' ' . $nextclause;
1804 0 $linelen = $self->{indent} + 3 + length($nextclause);
1805 }
1806 else
1807 {
1808 59 $outputline .= $nextclause;
1809 59 $linelen += length($nextclause);
1810 }
1811 }
1812  
1813 33 ▶ if (defined $actiontext)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $actiontext) 0 33 33
1814 {
1815 0 my $padlen = $self->{indent} + 40 - length($outputline);
1816 0 ▶ $padlen = 1 if $padlen < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $padlen < 0 0 0 0
1817 0 $outputline .= ' ' x $padlen . "action => ${actiontext}";
1818 0 $actiontext = undef;
1819 }
1820  
1821 33 $options->{status} = 1;
1822 33 ▶ printf $outf "%s\n", $outputline if length($outputline) > 0;
Branch: 1 branch
BranchTrueFalseTotal
if length $outputline > 0 33 0 33
1823 33 $linelen = 0;
1824 }
1825  
1826 22 ▶ if (exists $options->{comments})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $options->{"comments"}) 0 22 22
1827 {
1828 0 for my $cl (@{$options->{comments}})
1829 {
1830 0 printf $outf "%s\n", $cl;
1831 }
1832 0 delete $options->{comments};
1833 }
1834 }
1835  
1836 ##
1837 # writeMarpaRule : print a complute rule :
1838 # - rule name + 1st branch
1839 # - all subsequent branches
1840 ##
1841 sub writeMarpaRule
1842 32 ▶{
Subroutine writeMarpaRule: called CC=15 SCAR=27.6
Pod undocumented
1843 32 my ($self, $rulename ) = @_;
1844  
1845 32 ▶ $self->dumpMarpaRule($rulename) if $self->{verbosity};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbosity"} 0 32 32
1846  
1847 32 $self->tagMarpaRule($rulename);
1848  
1849 # if ( $rulename eq "IDENTIFIER")
1850 # {
1851 # printf "found!\n";
1852 # }
1853  
1854 32 my $rule = $self->getMarpaRule(undef, $rulename);
1855  
1856 32 ▶ my $cardinality = $rule->{cardinality} if exists $rule->{cardinality};
Branch: 1 branch
BranchTrueFalseTotal
if exists $rule->{"cardinality"} 9 23 32
1857  
1858 32 my $options = { delimiter => "", status => 0 };
1859 32 ▶ $options->{cardinality} = $cardinality if defined $cardinality;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cardinality 9 23 32
1860 32 ▶ $options->{assignop} = '~' if exists $rule->{isLexeme} || exists $rule->{isFragmentOrChild} || exists $rule->{grammarstate};
Branch: 1 branch
BranchTrueFalseTotal
if exists $rule->{"isLexeme"} or exists $rule->{"isFragmentOrChild"} or exists $rule->{"grammarstate"} 23 9 32
Condition100%6/6
exists $rule->{"isLexeme"} or exists $rule->{"isFragmentOrChild"} or exists $rule->{"grammarstate"}
l!l&&r!l&&!r
1589
exists $rule->{"isLexeme"} or exists $rule->{"isFragmentOrChild"}
l!l&&r!l&&!r
51017
MC/DC100%3/3
exists $rule->{"isLexeme"} or exists $rule->{"isFragmentOrChild"} or exists $rule->{"grammarstate"}
exists $rule->{"isLexeme"} exists $rule->{"isFragmentOrChild"} exists $rule->{"grammarstate"}
Truth table100%4/4
A or B or C
A= exists $rule->{"isLexeme"}B= exists $rule->{"isFragmentOrChild"}C= exists $rule->{"grammarstate"}
ABCresult
1XX1
01X1
0011
0000
1861  
1862 32 my $outputline = "";
1863 32 my $outf = $self->{outf};
1864  
1865 32 my $printoutputcreated = 1;
1866  
1867 SWITCH:
1868 {
1869 ##
1870 # discard rules that implement a case-insensitive single-letter literal
1871 # if we are building case-insensitive keyword literals.
1872 ##
1873 32 ▶ ($self->testoption('buildkeywords') && $self->isKeywordLetter($rulename, $rule)) && do {
Branch: 1 branch
BranchTrueFalseTotal
$self->testoption("buildkeywords") and $self->isKeywordLetter($rulename, $rule) and do { $self->deleteMarpaRule($rulename); $printoutputcreated = 0; last SWITCH } 0 32 32
Condition33%1/3
$self->testoption("buildkeywords") and $self->isKeywordLetter($rulename, $rule)
!ll&&!rl&&r
0320
MC/DC0%0/2
$self->testoption("buildkeywords") and $self->isKeywordLetter($rulename, $rule)
$self->testoption("buildkeywords") $self->isKeywordLetter($rulename, $rule)
Truth table33%1/3
A and B
A= $self->testoption("buildkeywords")B= $self->isKeywordLetter($rulename, $rule)
ABresult
0X0
100
111
1874 0 $self->deleteMarpaRule($rulename);
1875 0 $printoutputcreated = 0;
1876 0 last SWITCH;
1877 };
1878 #(exists $rule->{isFragmentOrChild} && $self->testoption('fragment2class') && fragmentEligible2Convert($rule)) && do {
1879 ##
1880 # conditionally translate eligible fragments to classes if the fragment is not tagged with a '?' quantifier
1881 ##
1882 32 ▶ ($self->testoption('fragment2class') && $rulename !~ /^opt_/ && fragmentEligible2Convert($rule)) && do {
Branch: 1 branch
BranchTrueFalseTotal
$self->testoption("fragment2class") and not $rulename =~ /^opt_/ and fragmentEligible2Convert($rule) and do { $self->writeFragmentAsClass($rulename, $rule, $options); last SWITCH } 1 31 32
Condition83%5/6
$self->testoption("fragment2class") and not $rulename =~ /^opt_/ and fragmentEligible2Convert($rule)
!ll&&!rl&&r
4271
$self->testoption("fragment2class") and not $rulename =~ /^opt_/
!ll&&!rl&&r
0428
MC/DC66%2/3
$self->testoption("fragment2class") and not $rulename =~ /^opt_/ and fragmentEligible2Convert($rule)
$self->testoption("fragment2class") not $rulename =~ /^opt_/ fragmentEligible2Convert($rule)
Truth table75%3/4
A and not(B) and C
A= $self->testoption("fragment2class")B= not $rulename =~ /^opt_/C= fragmentEligible2Convert($rule)
ABCresult
0XX0
10X0
1100
1111
1883 1 $self->writeFragmentAsClass($rulename, $rule, $options );
1884 1 last SWITCH;
1885 };
1886 ##
1887 # print a rule with alternative branches
1888 ##
1889 31 ▶ (exists $rule->{list}) && do {
Branch: 1 branch
BranchTrueFalseTotal
exists $rule->{"list"} and do { $self->writeMarpaRuleList($rulename, $rule, $options); last SWITCH } 22 9 31
1890 22 $self->writeMarpaRuleList($rulename, $rule, $options );
1891 22 last SWITCH;
1892 };
1893 ##
1894 # print a simple rule
1895 ##
1896 9 do {
1897 9 $outputline = $self->printRhs( $rulename, $rule, $options );
1898 9 ▶ $printoutputcreated = 0 if !length($outputline);
Branch: 1 branch
BranchTrueFalseTotal
unless length $outputline 0 9 9
1899 9 last SWITCH;
1900 };
1901 }
1902  
1903 32 ▶ printf $outf "%s\n", $outputline if length($outputline) > 0;
Branch: 1 branch
BranchTrueFalseTotal
if length $outputline > 0 9 23 32
1904  
1905 32 return $printoutputcreated;
1906 }
1907  
1908 sub dumpMarpaRule
1909 0 ▶{
Subroutine dumpMarpaRule: not called CC=1 SCAR=6.9
Pod undocumented
1910 0 my ( $self, $rulename ) = @_;
1911  
1912 0 my $marparule = $self->getMarpaRule(undef, $rulename);
1913 0 $self->dumpStructure( sprintf("=== %s\n", $rulename), $marparule);
1914 }
1915  
1916 ##
1917 # 'computeIndentation' : compute the maximum rulename length
1918 ##
1919 sub computeIndentation
1920 1 ▶{
Subroutine computeIndentation: called CC=10 SCAR=23.1
Pod undocumented
1921 1 my ($self) = @_;
1922  
1923 1 my $symboltable = $self->{symboltable};
1924 1 my $ruletable = $symboltable->ruletable;
1925 1 my $subrules = $self->{subrules};
1926  
1927 1 my $indent = -1;
1928 1 for my $rule (@$ruletable)
1929 {
1930 16 ▶ next if !defined $rule || !exists $rule->{name} || !exists $rule->{generationstatus};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rule and exists $rule->{"name"} and exists $rule->{"generationstatus"} 2 14 16
Condition66%4/6
defined $rule and exists $rule->{"name"} and exists $rule->{"generationstatus"}
!ll&&!rl&&r
2014
defined $rule and exists $rule->{"name"}
!ll&&!rl&&r
2014
MC/DC33%1/3
defined $rule and exists $rule->{"name"} and exists $rule->{"generationstatus"}
defined $rule exists $rule->{"name"} exists $rule->{"generationstatus"}
Truth table50%2/4
A and B and C
A= defined $ruleB= exists $rule->{"name"}C= exists $rule->{"generationstatus"}
ABCresult
0XX0
10X0
1100
1111
1931 14 my $rulename = $rule->{name};
1932 14 ▶ $indent = length($rulename) if length($rulename) > $indent;
Branch: 1 branch
BranchTrueFalseTotal
if length $rulename > $indent 1 13 14
1933 14 ▶ next if !exists $subrules->{$rulename};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $subrules->{$rulename} 6 8 14
1934 8 for my $subrulename (@{$subrules->{$rulename}})
1935 {
1936 18 ▶ $indent = length($subrulename) if length($subrulename) > $indent;
Branch: 1 branch
BranchTrueFalseTotal
if length $subrulename > $indent 3 15 18
1937 }
1938 }
1939  
1940 1 ▶ mydie "INTERNAL: couldn't compute rhs indentation" if $indent == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $indent == -1 0 1 1
1941  
1942 1 $self->{indent} = $indent;
1943 }
1944  
1945 sub generateGenericOptions
1946 1 ▶{
Subroutine generateGenericOptions: called CC=1 SCAR=0.0
Pod undocumented
1947 1 my ($self) = @_;
1948 1 my $outf = $self->{outf};
1949 1 printf $outf "%s\n\n", "lexeme default = latm => 1";
1950 }
1951  
1952 sub generateStartClause
1953 1 ▶{
Subroutine generateStartClause: called CC=2 SCAR=7.0
Pod undocumented
1954 1 my ($self) = @_;
1955  
1956 1 my $startrule = $self->symboltable->startrule;
1957 1 ▶ return if !defined $startrule;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $startrule 0 1 1
1958  
1959 1 my $outf = $self->{outf};
1960  
1961 1 printf $outf "%s %-3s %s\n\n", $self->pad(":start"), "::=", $startrule->{name};
1962 }
1963  
1964 sub convertRedirectToDiscard
1965 1 ▶{
Subroutine convertRedirectToDiscard: called CC=5 SCAR=16.6
Pod undocumented
1966 1 my ($self) = @_;
1967  
1968 1 ▶ return if !exists $self->{discarded} || ref $self->{discarded} ne 'ARRAY' || scalar @{$self->{discarded}} < 1;
Branch: 1 branch
BranchTrueFalseTotal
if not exists $self->{"discarded"} or ref $self->{"discarded"} ne "ARRAY" or scalar @{$self->{"discarded"};} < 1 0 1 1
Condition33%2/6
not exists $self->{"discarded"} or ref $self->{"discarded"} ne "ARRAY" or scalar @{$self->{"discarded"};} < 1
l!l&&r!l&&!r
001
not exists $self->{"discarded"} or ref $self->{"discarded"} ne "ARRAY"
l!l&&r!l&&!r
001
MC/DC0%0/3
not exists $self->{"discarded"} or ref $self->{"discarded"} ne "ARRAY" or scalar @{$self->{"discarded"};} < 1
not exists $self->{"discarded"} ref $self->{"discarded"} ne "ARRAY" scalar @{$self->{"discarded"};} < 1
Truth table25%1/4
not(A) or B or C
A= not exists $self->{"discarded"}B= ref $self->{"discarded"} ne "ARRAY"C= scalar @{$self->{"discarded"};} < 1
ABCresult
1XX1
01X1
0011
0000
1969  
1970 1 my $outf = $self->{outf};
1971  
1972 1 printf $outf "# ---\n";
1973 1 printf $outf "# Discard rule from redirect options :\n";
1974 1 printf $outf "%s %-3s %s\n", $self->pad(":discard"), "~", "<discarded redirects>";
1975  
1976 1 my $lhs = "<discarded redirects>";
1977 1 my $delimiter = "~";
1978 1 for my $rulename (@{$self->{discarded}})
1979 {
1980 1 printf $outf "%s %-3s %s\n", $self->pad($lhs), $delimiter, $rulename;
1981 1 $lhs = "";
1982 1 $delimiter = "|";
1983 }
1984  
1985 1 printf $outf "# ---\n";
1986 }
1987  
1988 ## -------------------------------------------------------------------------------------
1989 # 'writeMarpaGrammar' create an output file with the collected rules in Marpa syntax.
1990 # the sequence of rules is identical to that from the original
1991 # input files. Subrules are aligned with parent rules.
1992 ## -------------------------------------------------------------------------------------
1993 sub writeMarpaGrammar
1994 1 ▶{
Subroutine writeMarpaGrammar: called CC=21 SCAR=33.0
Pod undocumented
1995 1 my ($self) = @_;
1996  
1997 1 my $symboltable = $self->{symboltable};
1998 1 my $startrule = $symboltable->startrule;
1999 1 my $startrulename = $startrule->{name};
2000  
2001 1 my $ruletable = $symboltable->ruletable;
2002 1 my $subrules = $self->{subrules};
2003  
2004 1 $self->computeIndentation;
2005  
2006 1 $self->openOutputFile;
2007  
2008 1 $self->generateGenericOptions;
2009 1 $self->generateStartClause;
2010  
2011 # create a ':discard' rule at the top of the output file
2012 # from the rules tagged 'redirect'
2013 1 $self->convertRedirectToDiscard;
2014  
2015 1 my $outf = $self->{outf};
2016  
2017 ##
2018 # print rules in the order of the input file
2019 ##
2020 1 my $status = 0;
2021 1 my $subrulestatus = 0;
2022 1 my $rulegeneratedoutput = 1;
2023  
2024 1 for my $rule (@$ruletable)
2025 {
2026 16 ▶ if (exists $rule->{comment} && !$self->testoption('stripallcomments'))
Branch: 1 branch
BranchTrueFalseTotal
if (exists $rule->{"comment"} and not $self->testoption("stripallcomments")) 0 16 16
Condition33%1/3
exists $rule->{"comment"} and not $self->testoption("stripallcomments")
!ll&&!rl&&r
1600
MC/DC0%0/2
exists $rule->{"comment"} and not $self->testoption("stripallcomments")
exists $rule->{"comment"} not $self->testoption("stripallcomments")
Truth table33%1/3
A and not(B)
A= exists $rule->{"comment"}B= not $self->testoption("stripallcomments")
ABresult
0X0
100
111
2027 {
2028 0 my $comment = $rule->{comment};
2029 0 ▶ $comment = [$comment] if ref $comment ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $comment ne "ARRAY" 0 0 0
2030 0 my $cl = $self->renderComment("grammar", $comment);
2031 0 for my $s (@$cl)
2032 {
2033 0 printf $outf "%s\n", $s;
2034 }
2035 }
2036  
2037 16 ▶ next if !defined $rule || !exists $rule->{name} || !exists $rule->{generationstatus};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rule and exists $rule->{"name"} and exists $rule->{"generationstatus"} 2 14 16
Condition66%4/6
defined $rule and exists $rule->{"name"} and exists $rule->{"generationstatus"}
!ll&&!rl&&r
2014
defined $rule and exists $rule->{"name"}
!ll&&!rl&&r
0214
MC/DC33%1/3
defined $rule and exists $rule->{"name"} and exists $rule->{"generationstatus"}
defined $rule exists $rule->{"name"} exists $rule->{"generationstatus"}
Truth table50%2/4
A and B and C
A= defined $ruleB= exists $rule->{"name"}C= exists $rule->{"generationstatus"}
ABCresult
0XX0
10X0
1100
1111
2038  
2039 14 my $rulename = $rule->{name};
2040  
2041 14 ▶ if ( !$status )
Branch: 1 branch
BranchTrueFalseTotal
unless ($status) 1 13 14
2042 {
2043 1 ▶ printf "WARNING : first rule '%s' is not startrule '%s'\n", $rulename, $startrulename if $rulename ne $startrulename;
Branch: 1 branch
BranchTrueFalseTotal
if $rulename ne $startrulename 0 1 1
2044 1 $status = 1;
2045 }
2046  
2047 ##
2048 # create a block of text for a rule with its subrules
2049 ##
2050 14 ▶ printf $outf "\n" if exists $subrules->{$rulename} && !$subrulestatus && $rulegeneratedoutput;
Branch: 1 branch
BranchTrueFalseTotal
if exists $subrules->{$rulename} and not $subrulestatus and $rulegeneratedoutput 4 10 14
Condition83%5/6
exists $subrules->{$rulename} and not $subrulestatus and $rulegeneratedoutput
!ll&&!rl&&r
1004
exists $subrules->{$rulename} and not $subrulestatus
!ll&&!rl&&r
644
MC/DC66%2/3
exists $subrules->{$rulename} and not $subrulestatus and $rulegeneratedoutput
exists $subrules->{$rulename} not $subrulestatus $rulegeneratedoutput
Truth table75%3/4
A and not(B) and C
A= exists $subrules->{$rulename}B= not $subrulestatusC= $rulegeneratedoutput
ABCresult
0XX0
10X0
1100
1111
2051 14 $subrulestatus = 0;
2052  
2053 14 $rulegeneratedoutput = $self->writeMarpaRule($rulename);
2054  
2055 ##
2056 # print the generated subrules immediately after the parent rule
2057 ##
2058 14 ▶ if (exists $subrules->{$rulename})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $subrules->{$rulename}) 8 6 14
2059 {
2060 8 my $subrulegeneratedoutput = 0;
2061  
2062 8 for my $subrulename (@{$subrules->{$rulename}})
2063 {
2064 18 $subrulegeneratedoutput += $self->writeMarpaRule($subrulename);
2065 }
2066  
2067 8 ▶ printf $outf "\n" if $subrulegeneratedoutput;
Branch: 1 branch
BranchTrueFalseTotal
if $subrulegeneratedoutput 8 0 8
2068 8 $subrulestatus = 1;
2069 }
2070 }
2071  
2072 ##
2073 # print the rest (if any)
2074 ##
2075 1 for my $rulename (sort keys %{$self->{rules}})
2076 {
2077 32 my $g4rule = $symboltable->rule($rulename);
2078 32 ▶ next if !exists $g4rule->{generationstatus};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $g4rule->{"generationstatus"} 18 14 32
2079  
2080 14 my $marparule = $self->getMarpaRule(undef, $rulename);
2081 14 ▶ next if exists $marparule->{status};
Branch: 1 branch
BranchTrueFalseTotal
if exists $marparule->{"status"} 14 0 14
2082  
2083 0 ▶ printf "%s\n", $rulename if $self->{verbosity};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbosity"} 0 0 0
2084 0 $self->writeMarpaRule($rulename);
2085 }
2086  
2087 1 $self->closeOutputFile;
2088 }
2089  
2090 # --------------------------------------------------- #
2091 # driver #
2092 # --------------------------------------------------- #
2093  
2094 sub generate
2095 1 ▶{
Subroutine generate: called CC=2 SCAR=7.0
Pod undocumented
2096 1 my ($self, $symboltable) = @_;
2097  
2098 1 $self->{symboltable} = $symboltable;
2099  
2100 1 $self->translateG4Grammar;
2101 1 ▶ $self->dumpStructure("Rules", $self->{rules}) if $self->{verbosity} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbosity"} > 1 0 1 1
2102 1 $self->writeMarpaGrammar;
2103 }
2104  
2105 2 1;
2106  
2107 # ABSTRACT: translate parsed antlr4 rules to Marpa2 syntax
2108  
2109 =head1 SYNOPSIS
2110 use MarpaX::G4::MarpaGen;
2111 my $generator = new MarpaX::MarpaGen;
2112 $generator->generate($symboltable);
2113 =head1 DESCRIPTION
2114 Translate the rules from the symbol table created from the imported ANTLR4 grammar
2115 into Marpa syntax and write them to output.
2116  
2117 use MarpaX::Symboltable;
2118 my $symboltable = new MarpaX::Symboltable;
2119  
2120 my $grammartext = readFile($infile);
2121 my $data = MarpaX::G4::parse_rules($grammartext);
2122 $symboltable->importParseTree($data);
2123 $symboltable->validateSymbolTable();
2124  
2125 my $generator = new MarpaX::MarpaGen;
2126  
2127 $generator->stripallcomments if exists $options->{c};
2128 $generator->embedactions if exists $options->{e};
2129 $generator->fragment2class if exists $options->{f};
2130 $generator->shiftlazytogreedy if exists $options->{g};
2131 $generator->buildkeywords if exists $options->{k};
2132 $generator->stripactions if exists $options->{p};
2133 $generator->setVerbosity(2) if exists $options->{t};
2134 $generator->matchcaseinsensitive if exists $options->{u} || exists $options->{k};
2135  
2136 my $outputfile = '-';
2137 $outputfile = $options->{o} if exists $options->{o};
2138 $generator->setoutputfile($outputfile);
2139  
2140 $generator->generate($symboltable);
2141 =cut
« lib/MarpaX/G4/Symboltable.pm ↑ Summary lib/MarpaX/G4/Parser.pm »