| 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
MC/DC0%0/2
ref $invocant || $invocant
ref $invocant
$invocant
Truth table33%1/3
A || B
A= ref $invocantB= $invocant
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 189 | $option = lc $option; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 189 | ▶ | return undef if !exists $self->{generationoptions}{$option}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | my $rules = $self->{rules}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | mydie "INTERNAL: can't delete undefined rule $subrulename" if !exists $rules->{$subrulename}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | $parent = "<ROOT>" if !defined $parent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 5 | for my $sr (@{$subrules->{$rulename}}) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 9 | ▶ | return 1 if $sr eq $subrulename; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 14 | ▶ | $level = -1 if !defined $level; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 360 | my $modifier = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 360 | ▶ | $modifier = $token->{$tag} if exists $token->{$tag}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 1 | my $mxelement; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 1 | ▶ | if (! exists $mxtoken->{class4list} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 1 | ▶ | $mxelement->{isFragmentOrChild} = $mxtoken->{isFragmentOrChild} if exists $mxtoken->{isFragmentOrChild}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
exists $mxtoken->{"rhs"} and exists $mxtoken->{"rhs"}{"token"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | my $token = $mxtoken->{rhs}{token}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | if (ref $token eq "") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | push @{$literaltoken->{definition}}, {token => {type => 'literal', value => $uctoken}, alternative=> 'true'} if length($uctoken) > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 4 | ▶ | return 1 if $string =~ /^\\[^u]$/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 3 | ▶ | return 1 if $string =~ /^\\u[0-9A-F]{4,4}$/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 3 | ▶ | return 1 if $string =~ /^\\u\{[0-9A-F]{5,5}\}$/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition22%2/9
$rulename =~ /^[a-z]$/i and $s =~ /([a-z])([a-z])/i and uc "$1" eq "$2" || lc "$1" eq "$2"
$rulename =~ /^[a-z]$/i and $s =~ /([a-z])([a-z])/i
uc "$1" eq "$2" or lc "$1" eq "$2"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition83%5/6
$string =~ /([a-z])([a-z])/i and uc "$1" eq "$2" || lc "$1" eq "$2"
uc "$1" eq "$2" or lc "$1" eq "$2"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 29 | ▶ | return substr($string, 0, 1) if $string !~ /[a-z]/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 8 | ▶ | return substr($string, 0, 1) if $string =~ /[0-9]/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$begr->{"type"} ne "literal" or $endr->{"type"} ne "literal"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
isSingleChar($begr) and isSingleChar($endr)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 120 | ▶ | if ( !exists $mxelement->{class4list} || $tracker->{status} == -1 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not exists $mxelement->{"class4list"} or $tracker->{"status"} == -1
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 60 | ▶ | if ( !exists $mxelement->{keywordfragment} || $tracker->{status} == -1 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not exists $mxelement->{"keywordfragment"} or $tracker->{"status"} == -1
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
defined $cardinality and $cardinality eq "?"
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 "?"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 18 | ▶ | $mxelement->{isFragmentOrChild} = $context->{subruleindex}{$rulename}{isFragmentOrChild} if exists $context->{subruleindex}{$rulename}{isFragmentOrChild}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | # wrap cardinality "?" into an 'opt_' rule | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 18 | ▶ | $mxelement->{cardinality} = $cardinality if defined $cardinality && $cardinality eq "?"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $cardinality and $cardinality eq "?"
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 "?"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
exists $mxelement->{"class4list"} and not defined $cardinality
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 18 | ▶ | $mxalias->{grammarstate} = $context->{subruleindex}{$rulename}{grammarstate} if exists $context->{subruleindex}{$rulename}{grammarstate}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 18 | ▶ | $mxalias->{isFragmentOrChild} = $context->{subruleindex}{$rulename}{isFragmentOrChild} if exists $context->{subruleindex}{$rulename}{isFragmentOrChild}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
ref $token eq "HASH" and exists $token->{"comment"} and not $self->testoption("stripallcomments")
ref $token eq "HASH" and exists $token->{"comment"}
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | ▶ | mydie "comment not a plain string in rule $rulename" if ref $token->{comment} ne ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition83%5/6
ref $token eq "HASH" and exists $token->{"type"} and $token->{"type"} eq "tokengroup"
ref $token eq "HASH" and exists $token->{"type"}
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%4/6
ref $token eq "HASH" and exists $token->{"type"} and $token->{"type"} eq "rulegroup"
ref $token eq "HASH" and exists $token->{"type"}
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition83%5/6
ref $token eq "HASH" and exists $token->{"type"} and $token->{"type"} eq "literal"
ref $token eq "HASH" and exists $token->{"type"}
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 21 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 10 | ▶ | (ref $token eq 'HASH' && exists $token->{type} && $token->{type} eq 'class') && do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
ref $token eq "HASH" and exists $token->{"type"} and $token->{"type"} eq "class"
ref $token eq "HASH" and exists $token->{"type"}
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
ref $token eq "HASH" and exists $token->{"type"} and $token->{"type"} eq "regex"
ref $token eq "HASH" and exists $token->{"type"}
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
ref $token eq "HASH" and exists $token->{"type"} and $token->{"type"} eq "range"
ref $token eq "HASH" and exists $token->{"type"}
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
ref $token eq "HASH" and exists $token->{"type"} and $token->{"type"} eq "value"
ref $token eq "HASH" and exists $token->{"type"}
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
ref $token eq "HASH" and exists $token->{"token"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
ref $token eq "HASH" and exists $token->{"action"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
ref $token eq "HASH" and exists $token->{"comment"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 40 | ▶ | $mxToken->{comments} = $comments if scalar @$comments > 0 && !$self->testoption('stripallcomments'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
scalar @$comments > 0 and not $self->testoption("stripallcomments")
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 0 | my $mxToken = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | SWITCH: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 0 | ▶ | (exists $nonterminal->{rhs}) && do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 6 | ▶ | return 0 if $cardinality eq "?"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 6 | ▶ | $cardinality =~ s/([+*])\?/$1/ if $cardinality =~ /[+*]\?/ && $self->testoption('shiftlazytogreedy'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$cardinality =~ /[+*]\?/ and $self->testoption("shiftlazytogreedy")
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 6 | ▶ | $options = {} if !defined $options; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 6 | my $abortatfirstlevel = exists $options->{abortatfirstlevel}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | SWITCH: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 6 | ▶ | (exists $mxtoken->{rhs}) && do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 5 | ▶ | mydie "'token' must be a scalar in 'rhs' in rule $rulename" if !exists $rhs->{token} || ref $rhs->{token} ne ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not exists $rhs->{"token"} or ref $rhs->{"token"} ne ""
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 ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 5 | ▶ | return 0 if !defined $self->checkMarpaRuleExists($rhs->{token}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 5 | my $rc = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 5 | ▶ | if ($abortatfirstlevel) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 5 | my $rule = $self->getMarpaRule($rulename, $subrulename); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 5 | ▶ | if ($cardinality ne "?") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | 0 | ▶ | mydie "can't retag subrule $subrulename twice in rule $rulename" if exists $rule->{cardinality}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
exists $mxtoken->{"type"} and $mxtoken->{"type"} eq "group"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 0 | ▶ | mydie "group rhs must contain 'list' in $rulename" if !exists $mxtoken->{list}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
ref $al ne "HASH" or not exists $al->{"list"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
exists $le->{"type"} and not $le->{"type"} =~ /literal|class/
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/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
exists $mxtoken->{"type"} and $mxtoken->{"type"} eq "literal"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
exists $mxtoken->{"type"} and $mxtoken->{"type"} eq "class"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | 1 | ▶ | mydie "'class' can't be multiplied twice in $rulename" if exists $mxtoken->{cardinality}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
exists $mxtoken->{"type"} and $mxtoken->{"type"} eq "negatedclass"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 0 | ▶ | mydie "'negatedclass' can't be multiplied twice in $rulename" if exists $mxtoken->{cardinality}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
exists $rhs->{"type"} and $rhs->{"type"} eq "literal"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 4 | my $newliteral = $rhs->{value}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 4 | ▶ | if (defined $literal) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 2 | ▶ | $filtered = 1 if $matchfound; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 2 | $literal = $newliteral; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 12 | ▶ | push @$filteredlist, $branch if !$matchfound; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 6 | ▶ | return $alternativelists if !$filtered; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%4/6
ref $e eq "HASH" and exists $e->{"rhs"} and not exists $e->{"token"}
ref $e eq "HASH" and exists $e->{"rhs"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | 60 | ▶ | $e = { token => $e } if ref $e eq 'HASH' && exists $e->{type} && exists $e->{definition}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
ref $e eq "HASH" and exists $e->{"type"} and exists $e->{"definition"}
ref $e eq "HASH" and exists $e->{"type"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
exists $e->{"comment"} or exists $e->{"action"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | 0 | ▶ | if (exists $e->{comment} && !$self->testoption('stripallcomments')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $e->{"comment"} and not $self->testoption("stripallcomments")
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
exists $e->{"action"} and not $self->testoption("stripactions")
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | 0 | ▶ | push @{$metalist->{actions}}, $self->testoption('embedactions') ? $e->{action} : $self->renderComment($rulename, [$e->{action}]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
ref $e eq "HASH" and not exists $e->{"token"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
exists $e->{"type"} and $e->{"type"} eq "regex"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | 11 | ▶ | if (scalar @$currentlist > 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%4/6
$self->testoption("buildkeywords") and $keywordfragment->{"status"} == 0 and $keyword =~ /^[a-z]/i
$self->testoption("buildkeywords") and $keywordfragment->{"status"} == 0
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | 11 | ▶ | $newlist->{metalist} = $metalist if exists $metalist->{state}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
ref $e ne "HASH" or not exists $e->{"token"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
exists $mxelement->{"type"} and $mxelement->{"type"} eq "ignore"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | 39 | my $keywordfragment = $self->isKeywordFragment($rulename, $mxelement); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | 39 | ▶ | $mxelement->{keywordfragment} = $keywordfragment if defined $keywordfragment; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | # collect embedded comments in the alternative branch state | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | 60 | ▶ | if (exists $mxelement->{comments}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | 60 | ▶ | if ( defined $negation ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
scalar @$rhslist <= 1 and $self->retagSimpleRule($rulename, $mxelement, $cardinality, $context)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $alternative and scalar @$rhslist > 1
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$cardinality ne "?" and not $self->retagSimpleRule($rulename, $mxelement, $cardinality, $context, {"abortatfirstlevel", "true"})
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"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | 0 | ▶ | mydie "INTERNAL: no destination for cardinality found in rule '$rulename'" if scalar @$rhslist > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | 0 | ▶ | $mxelement->{cardinality} = $cardinality if $cardinality ne "?"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%4/6
$self->testoption("buildkeywords") and $keywordfragment->{"status"} == 0 and $keywordfragment->{"value"} =~ /^[a-z]/i
$self->testoption("buildkeywords") and $keywordfragment->{"status"} == 0
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | 23 | my $newlist = { list => $currentlist }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | 23 | ▶ | $newlist->{class4list} = $class4list->{value} if $class4list->{status} != -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | 23 | ▶ | $newlist->{isLexeme} = 1 if $groupisLexeme->{status} == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | 23 | ▶ | $newlist->{metalist} = $metalist if exists $metalist->{state}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | 23 | ▶ | $grouplist->{isLexeme} = 1 if $groupisLexeme->{status} == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
ref $tokengroup ne "HASH" or not exists $tokengroup->{"definition"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | 9 | my $mxrule; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | SWITCH: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | 9 | ▶ | ($rulestatus eq "inprogress") && do {$mxrule = $symboltable->rule( $rulename ); last SWITCH; }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | 6 | ▶ | ($rulestatus eq "done") && do {$mxrule = $self->getMarpaRule( undef, $rulename ); last SWITCH; }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | ($rulestatus eq "synthetic" && !$self->checkMarpaRuleExists($rulename)) && do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$rulestatus eq "synthetic" and not $self->checkMarpaRuleExists($rulename)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1154 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1155 | 14 | ▶ | $self->abortWithError( "rhs is not an array ref in $rulename", $rightside ) if ref $rightside ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | 14 | ▶ | $context->{subruleindex}{$rulename}{grammarstate} = $rule->{grammarstate} if exists $rule->{grammarstate} && $rule->{grammarstate} eq "lexer"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $rule->{"grammarstate"} and $rule->{"grammarstate"} eq "lexer"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | 14 | ▶ | $context->{subruleindex}{$rulename}{isFragmentOrChild} = 'true' if exists $rule->{type} && $rule->{type} eq "fragment"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $rule->{"type"} and $rule->{"type"} eq "fragment"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
exists $rule->{"grammarstate"} and $rule->{"grammarstate"} eq "lexer"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1173 | 14 | ▶ | $mxrightside->{isFragmentOrChild} = 'true' if exists $rule->{type} && $rule->{type} eq "fragment"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $rule->{"type"} and $rule->{"type"} eq "fragment"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1174 | 14 | ▶ | if (exists $rule->{redirect}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1239 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1240 | 0 | ▶ | if (!$status) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
exists $rule->{"grammarstate"} and $rule->{"grammarstate"} =~ /lexer/i
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1249 | $rulename; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1253 | 1 | ▶ | printf "\n\n" if $status; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
not exists $rule->{"generationstatus"} and exists $rule->{"redirect"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1317 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1318 | 1 | my $outf; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1319 | 1 | ▶ | mydie("cannot open output file $outputfile") unless open( $outf, ">$outputfile" ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1378 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1379 | 39 | my $rule = $self->getMarpaRule(undef, $token); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1380 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1381 | 39 | ▶ | if ($self->testoption('matchcaseinsensitive') && $self->isKeywordLetter($token, $rule)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->testoption("matchcaseinsensitive") and $self->isKeywordLetter($token, $rule)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1428 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1429 | 2 | my $fourmatch = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1430 | 2 | my $bracedmatch = $4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1431 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1432 | SWITCH: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1433 | 2 | ▶ | (defined $fourmatch) && do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1472 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1473 | SWITCH: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1474 | 12 | ▶ | ($classstring =~ /(\\[ux][0-9a-f]+)-(\\[ux][0-9a-f]+)(.*)$/i) && do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
exists $$classhash{lc $key} or exists $$classhash{uc $key}
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}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$beg =~ /[a-z]/i or $end =~ /[a-z]/i
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1496 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1497 | 3 | $classstring = $3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1498 | 3 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1499 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1500 | 9 | ▶ | ($classstring =~ /(\\.)(.*)$/) && do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1501 | 1 | my $c = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1502 | 1 | ▶ | if (!exists $characterhash->{$c}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1511 | 8 | my $c = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1512 | 8 | ▶ | if (!exists $characterhash->{lc $c} && !exists $characterhash->{uc $c}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $$characterhash{lc $c} or exists $$characterhash{uc $c}
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}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1513 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1514 | 7 | $characterhash->{$c} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1515 | 7 | $result .= $c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1516 | 7 | ▶ | $isalphaclass = 1 if $c =~ /^[a-z]$/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1532 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1533 | 8 | my $isAlpha = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1534 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1535 | 8 | ▶ | while ( $literal ne "" ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1536 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1537 | SWITCH: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1538 | 43 | ▶ | ($literal =~ /(\\.)(.*)$/) && do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1539 | 4 | my $c = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1540 | 4 | $literal = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1541 | 4 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1542 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1543 | 39 | ▶ | ($literal =~ /(.)(.*)$/) && do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1544 | 39 | my $c = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1545 | 39 | $literal = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1546 | 39 | ▶ | $isAlpha = 1 if $c =~ /^[a-z]$/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
exists $rhs->{"type"} and $rhs->{"type"} eq "negatedclass"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1570 | 1 | ▶ | mydie "computeRhs : 'value' missing in negatedclass $rulename" if !exists $rhs->{value}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1577 | 0 | $rhs = { discard => 'true' }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1578 | 0 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1579 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1580 | 68 | ▶ | (exists $rhs->{type} && $rhs->{type} eq 'unsupported') && do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $rhs->{"type"} and $rhs->{"type"} eq "unsupported"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1581 | 0 | mydie $rhs->{msg}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1582 | 0 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1583 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1584 | 68 | ▶ | (exists $rhs->{type} && $rhs->{type} eq 'class') && do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $rhs->{"type"} and $rhs->{"type"} eq "class"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$self->testoption("matchcaseinsensitive") and $self->isAlphaLiteral($value)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1589 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1590 | 3 | my $normclass = $self->normalizeClassString($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1591 | 3 | $value = $normclass->{classstring}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1592 | 3 | ▶ | $modifier = ':ic' if $normclass->{isalphaclass}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
exists $rhs->{"type"} and $rhs->{"type"} eq "literal"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1598 | 21 | my $literal = $rhs->{value}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1599 | 21 | $literal = $self->translateunicode($rulename, $literal); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1600 | 21 | ▶ | $literal = ($literal eq "\\'") ? "[']" : "'${literal}'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1601 | 21 | ▶ | if ($self->testoption('matchcaseinsensitive') && $self->isAlphaLiteral($literal)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->testoption("matchcaseinsensitive") and $self->isAlphaLiteral($literal)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
exists $rhs->{"type"} and $rhs->{"type"} eq "action"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
not exists $rhs->{"token"} or ref $rhs->{"token"} ne ""
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 ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1617 | 39 | $rhs = $self->processRedirected($rhs->{token}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1618 | 39 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1619 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1620 | 0 | ▶ | (exists $rhs->{token}) && do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1621 | 0 | $rhs = $self->processRedirected($rhs->{token}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1622 | 0 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1623 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1624 | 0 | ▶ | (exists $rhs->{comments}) && do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1655 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1656 | 69 | ▶ | mydie "'options' not well-defined" if ref $options ne 'HASH' || !exists $options->{delimiter}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $options ne "HASH" or not exists $options->{"delimiter"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1657 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1658 | 69 | my $delimiter = $options->{delimiter}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1659 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1660 | 69 | my $cardinality = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1661 | 69 | ▶ | $cardinality = $options->{cardinality} if exists $options->{cardinality}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1662 | 69 | ▶ | $cardinality =~ s/([+*])\?/$1/ if $cardinality =~ /[+*]\?/ && $self->testoption('shiftlazytogreedy'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$cardinality =~ /[+*]\?/ and $self->testoption("shiftlazytogreedy")
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1663 | 69 | ▶ | mydie sprintf "lazy quantifier %s in rule %s not supported by Marpa", $cardinality, $rulename if $cardinality =~ /[+*]\?/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1672 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1673 | 69 | my $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1674 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1675 | # process optional rules | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1676 | 69 | ▶ | if ( defined $cardinality && $cardinality eq "?") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $cardinality and $cardinality eq "?"
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 "?"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1728 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1729 | 33 | ▶ | if (exists $rulelist->{metalist}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1736 | 0 | printf $outf "%s\n", $cl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1737 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1738 | 0 | ▶ | if (exists $metalist->{actions}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1739 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1740 | 0 | ▶ | if (!$self->testoption('embedactions')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1741 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1742 | 0 | for my $cl (@{$metalist->{actions}}) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1743 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1744 | 0 | ▶ | $cl = $cl->[0] if ref $cl eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1766 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1767 | 59 | $options->{delimiter} = "|"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1768 | 59 | ▶ | $options->{cardinality} = $cardinality if defined $cardinality; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1769 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1770 | 59 | ▶ | if (exists $rhs->{comments}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%3/6
exists $rhs->{"type"} and $rhs->{"type"} eq "group" and exists $rhs->{"list"}
exists $rhs->{"type"} and $rhs->{"type"} eq "group"
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1781 | 0 | ▶ | if ( exists $rhs->{class4list}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1814 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1815 | 0 | my $padlen = $self->{indent} + 40 - length($outputline); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1816 | 0 | ▶ | $padlen = 1 if $padlen < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1823 | 33 | $linelen = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1824 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1825 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1826 | 22 | ▶ | if (exists $options->{comments}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1857 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1858 | 32 | my $options = { delimiter => "", status => 0 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1859 | 32 | ▶ | $options->{cardinality} = $cardinality if defined $cardinality; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1860 | 32 | ▶ | $options->{assignop} = '~' if exists $rule->{isLexeme} || exists $rule->{isFragmentOrChild} || exists $rule->{grammarstate}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
exists $rule->{"isLexeme"} or exists $rule->{"isFragmentOrChild"} or exists $rule->{"grammarstate"}
exists $rule->{"isLexeme"} or exists $rule->{"isFragmentOrChild"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$self->testoption("buildkeywords") and $self->isKeywordLetter($rulename, $rule)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition83%5/6
$self->testoption("fragment2class") and not $rulename =~ /^opt_/ and fragmentEligible2Convert($rule)
$self->testoption("fragment2class") and not $rulename =~ /^opt_/
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1899 | 9 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1900 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1901 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1902 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1903 | 32 | ▶ | printf $outf "%s\n", $outputline if length($outputline) > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%4/6
defined $rule and exists $rule->{"name"} and exists $rule->{"generationstatus"}
defined $rule and exists $rule->{"name"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1931 | 14 | my $rulename = $rule->{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1932 | 14 | ▶ | $indent = length($rulename) if length($rulename) > $indent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1933 | 14 | ▶ | next if !exists $subrules->{$rulename}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1934 | 8 | for my $subrulename (@{$subrules->{$rulename}}) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1935 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1936 | 18 | ▶ | $indent = length($subrulename) if length($subrulename) > $indent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1937 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1938 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1939 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1940 | 1 | ▶ | mydie "INTERNAL: couldn't compute rhs indentation" if $indent == -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
not exists $self->{"discarded"} or ref $self->{"discarded"} ne "ARRAY" or scalar @{$self->{"discarded"};} < 1
not exists $self->{"discarded"} or ref $self->{"discarded"} ne "ARRAY"
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
exists $rule->{"comment"} and not $self->testoption("stripallcomments")
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2027 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2028 | 0 | my $comment = $rule->{comment}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2029 | 0 | ▶ | $comment = [$comment] if ref $comment ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%4/6
defined $rule and exists $rule->{"name"} and exists $rule->{"generationstatus"}
defined $rule and exists $rule->{"name"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2038 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2039 | 14 | my $rulename = $rule->{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2040 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2041 | 14 | ▶ | if ( !$status ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2042 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2043 | 1 | ▶ | printf "WARNING : first rule '%s' is not startrule '%s'\n", $rulename, $startrulename if $rulename ne $startrulename; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition83%5/6
exists $subrules->{$rulename} and not $subrulestatus and $rulegeneratedoutput
exists $subrules->{$rulename} and not $subrulestatus
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2079 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2080 | 14 | my $marparule = $self->getMarpaRule(undef, $rulename); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2081 | 14 | ▶ | next if exists $marparule->{status}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2082 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2083 | 0 | ▶ | printf "%s\n", $rulename if $self->{verbosity}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||