| 1 | # ----------------------------------------------------------------------------------------------------- # | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # MarpaX::Symboltable # | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # manage a symbol table with rules parsed from an antlr4 grammar. # | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # # | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # ----------------------------------------------------------------------------------------------------- # | ||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | package MarpaX::G4::Symboltable; | ||||||||||||||||||||||||||||||||||||||||||
| 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 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use MarpaX::G4::Parser; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | sub new | ||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | my $invocant = shift; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | my $self = {}; # initiate our handy hashref | |||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | bless($self,$class); # make it usable | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | $self->{symboltable} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | $self->{startrule} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | $self->{currentidx} = -1; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | $self->{ruletable} = []; | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | ▶ | sub symbols { my ($self) = @_; return keys %{$self->{symboltable}}; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
symbols: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 3 | ▶ | sub startrule { my ($self) = @_; return $self->{startrule}; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
startrule: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | ▶ | sub ruletable { my ($self) = @_; return $self->{ruletable}; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ruletable: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | sub setStartRule | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setStartRule: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | my ($self, $rulename) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | die "can't set non-existent rule $rulename as start rule" if !exists $self->{symboltable}{$rulename}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | my $symbol = $self->{symboltable}{$rulename}; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | $self->{startrule} = { name => $rulename, index => $symbol->{index} }; | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | sub rule | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 85 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rule: called CC=5 SCAR=17.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 85 | my ($self, $rulename) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 85 | ▶ | $self->addEOF() if $rulename eq "EOF" && !exists $self->{symboltable}{$rulename}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$rulename eq "EOF" and not exists $self->{"symboltable"}{$rulename}
MC/DC0%0/2
$rulename eq "EOF" and not exists $self->{"symboltable"}{$rulename}
$rulename eq "EOF"
not exists $self->{"symboltable"}{$rulename}
Truth table33%1/3
A and not(B)
A= $rulename eq "EOF"B= not exists $self->{"symboltable"}{$rulename}
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 85 | ▶ | return undef if !defined $rulename || !exists $self->{symboltable}{$rulename}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $rulename and exists $self->{"symboltable"}{$rulename}
MC/DC50%1/2
defined $rulename and exists $self->{"symboltable"}{$rulename}
defined $rulename
exists $self->{"symboltable"}{$rulename}
Truth table66%2/3
A and B
A= defined $rulenameB= exists $self->{"symboltable"}{$rulename}
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 67 | return $self->{symboltable}{$rulename}; | |||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | sub tagrule | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 28 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tagrule: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 28 | my ($self, $rulename, $status) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 28 | ▶ | die "trying to tag nonexistent rule '$rulename'" if !exists $self->{symboltable}{$rulename}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 28 | my $symbol = $self->{symboltable}{$rulename}; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 28 | ▶ | $symbol->{generationstatus} = defined($status) ? $status : 'todo'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 59 | # create a synthetic 'EOF' token, so that the grammar won't fail. | ||||||||||||||||||||||||||||||||||||||||||
| 60 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 61 | sub addEOF | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
addEOF: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $self->addRule( -1, | |||||||||||||||||||||||||||||||||||||||||
| 66 | { | ||||||||||||||||||||||||||||||||||||||||||
| 67 | name => 'EOF', | ||||||||||||||||||||||||||||||||||||||||||
| 68 | type => 'fragment', | ||||||||||||||||||||||||||||||||||||||||||
| 69 | generationstatus => 'synthetic', | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 'rightsides' => [ | ||||||||||||||||||||||||||||||||||||||||||
| 71 | { | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 'rhs' => { | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 'token' => { | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 'value' => '\z', | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 'type' => 'literal' | ||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 80 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | sub rulestatus | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 23 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rulestatus: called CC=5 SCAR=17.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 23 | my ($self, $rulename, $status) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 23 | ▶ | $self->addEOF() if $rulename eq "EOF" && !exists $self->{symboltable}{$rulename}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$rulename eq "EOF" and not exists $self->{"symboltable"}{$rulename}
MC/DC0%0/2
$rulename eq "EOF" and not exists $self->{"symboltable"}{$rulename}
$rulename eq "EOF"
not exists $self->{"symboltable"}{$rulename}
Truth table33%1/3
A and not(B)
A= $rulename eq "EOF"B= not exists $self->{"symboltable"}{$rulename}
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 23 | ▶ | die "trying to query nonexistent rule '$rulename'" if !exists $self->{symboltable}{$rulename}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 23 | my $symbol = $self->{symboltable}{$rulename}; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 23 | ▶ | return exists $symbol->{generationstatus} ? $symbol->{generationstatus} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | ## ----------- | ||||||||||||||||||||||||||||||||||||||||||
| 95 | # import the parse tree into the symbol table | ||||||||||||||||||||||||||||||||||||||||||
| 96 | ## ----------- | ||||||||||||||||||||||||||||||||||||||||||
| 97 | sub importParseTree | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
importParseTree: called CC=8 SCAR=23.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 1 | my ($self, $tree) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 1 | ▶ | die "parse tree must be an array of rules" if ref($tree) ne "ARRAY"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 1 | my $ruleindex = $self->{currentidx}; | |||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | for my $rule (@$tree) | |||||||||||||||||||||||||||||||||||||||||
| 105 | { | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 16 | ++$ruleindex; | |||||||||||||||||||||||||||||||||||||||||
| 107 | 16 | ▶ | die "rule[$ruleindex] is not a hash" if ref($rule) ne "HASH"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | SWITCH: { | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 16 | ▶ | (exists $rule->{name}) && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 14 | my $name = $rule->{name}; | |||||||||||||||||||||||||||||||||||||||||
| 112 | # printf "rule[$ruleindex] : %s\n", $name; | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 14 | $self->addRule($ruleindex, $rule); | |||||||||||||||||||||||||||||||||||||||||
| 114 | 14 | ▶ | $self->{startrule} = { name => $name, index => $ruleindex } if !defined $self->{startrule}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 14 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||
| 116 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 2 | ▶ | (exists $rule->{grammarspec}) && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | # printf "rule[$ruleindex] : grammar %s\n", $rule->{grammarspec}; | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 2 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||
| 120 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | (exists $rule->{comment}) && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | # printf "rule[$ruleindex] : comment\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | $self->addComment($ruleindex, $rule); | |||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||
| 125 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | do { | |||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | die "rule[$ruleindex] : can't process"; | |||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||
| 129 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | $self->{currentidx} = $ruleindex; | |||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | sub addRule | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 14 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
addRule: called CC=4 SCAR=14.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 14 | my ($self, $ruleindex, $rule) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 14 | my $name = $rule->{name}; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 14 | my $symboltable = \%{$self->{symboltable}}; | |||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | SWITCH: { | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 14 | ▶ | (exists $rule->{rightsides}) && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 14 | ▶ | die "$name is a duplicate rule" if exists $symboltable->{$name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 14 | $rule->{index} = $ruleindex; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 14 | $symboltable->{$name} = $rule; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 14 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||
| 149 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | do { | |||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | die "can't import rule[$ruleindex] : $name"; | |||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||
| 153 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | # add the rule to the index-based lookup table if it is not a synthetic rule. | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 14 | ▶ | $self->{ruletable}->[$ruleindex] = $rule if $ruleindex != -1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | sub addComment | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
addComment: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | my ($self, $ruleindex, $rule) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | $self->{ruletable}->[$ruleindex] = $rule; | |||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | ## ----------- | ||||||||||||||||||||||||||||||||||||||||||
| 167 | # recursively walk the symbol table to verify consistency | ||||||||||||||||||||||||||||||||||||||||||
| 168 | ## ----------- | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | sub walkgroup | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
walkgroup: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | my ($rulename, $tokengroup) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | my $namelist = []; | |||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | my $definition = $tokengroup->{definition}; | |||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | for my $e (@$definition) | |||||||||||||||||||||||||||||||||||||||||
| 178 | { | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | if (ref $e->{token} eq "") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | { | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | push @$namelist, $e->{token}; | |||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | else | ||||||||||||||||||||||||||||||||||||||||||
| 184 | { | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | if (ref $e eq "HASH" && exists $e->{token}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $e eq "HASH" and exists $e->{"token"}
MC/DC0%0/2
ref $e eq "HASH" and exists $e->{"token"}
ref $e eq "HASH"
exists $e->{"token"}
Truth table0%0/3
A and B
A= ref $e eq "HASH"B= exists $e->{"token"}
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | { | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | my $sr = walktoken($rulename, $e->{token}); | |||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | push (@$namelist, @$sr); | |||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||
| 190 | else | ||||||||||||||||||||||||||||||||||||||||||
| 191 | { | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | $Data::Dumper::Indent = 1; | |||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | print Dumper($tokengroup); | |||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | die "can't process group for rule $rulename"; | |||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | return $namelist; | |||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | sub walktoken | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
walktoken: not called CC=29 SCAR=67.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | my ($rulename, $token) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | my $namelist = []; | |||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | SWITCH: | ||||||||||||||||||||||||||||||||||||||||||
| 209 | { | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | (ref $token eq "HASH" && exists $token->{type} && $token->{type} eq "rulegroup") && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/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 table0%0/4
A and B and C
A= ref $token eq "HASH"B= exists $token->{"type"}C= $token->{"type"} eq "rulegroup"
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | my $sr = walkgroup($rulename, $token->{token}); | |||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | push (@$namelist, @$sr); | |||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||
| 214 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | (ref $token eq "HASH" && exists $token->{type} && $token->{type} eq "tokengroup") && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
ref $token eq "HASH" and exists $token->{"type"} and $token->{"type"} eq "tokengroup"
ref $token eq "HASH" and exists $token->{"type"}
MC/DC0%0/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 table0%0/4
A and B and C
A= ref $token eq "HASH"B= exists $token->{"type"}C= $token->{"type"} eq "tokengroup"
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | my $sr = walkgroup($rulename, $token->{token}); | |||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | push (@$namelist, @$sr); | |||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||
| 219 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | (ref $token eq "HASH" && exists $token->{token}) && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/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 table0%0/3
A and B
A= ref $token eq "HASH"B= exists $token->{"token"}
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | my $nestedtoken = $token->{token}; | |||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | my $sr = walktoken($rulename, $nestedtoken); | |||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | push (@$namelist, @$sr); | |||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||
| 225 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | (ref $token eq "") && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | push @$namelist, $token; | |||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||
| 229 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | (ref $token eq "HASH" && exists $token->{type} && $token->{type} eq "literal") && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
ref $token eq "HASH" and exists $token->{"type"} and $token->{"type"} eq "literal"
ref $token eq "HASH" and exists $token->{"type"}
MC/DC0%0/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 table0%0/4
A and B and C
A= ref $token eq "HASH"B= exists $token->{"type"}C= $token->{"type"} eq "literal"
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||
| 232 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | (ref $token eq "HASH" && exists $token->{type} && $token->{type} eq "class") && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
ref $token eq "HASH" and exists $token->{"type"} and $token->{"type"} eq "class"
ref $token eq "HASH" and exists $token->{"type"}
MC/DC0%0/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 table0%0/4
A and B and C
A= ref $token eq "HASH"B= exists $token->{"type"}C= $token->{"type"} eq "class"
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||
| 235 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | (ref $token eq "HASH" && exists $token->{type} && $token->{type} eq "regex") && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/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 table0%0/4
A and B and C
A= ref $token eq "HASH"B= exists $token->{"type"}C= $token->{"type"} eq "regex"
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||
| 238 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | (ref $token eq "HASH" && exists $token->{type} && $token->{type} eq "range") && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/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 table0%0/4
A and B and C
A= ref $token eq "HASH"B= exists $token->{"type"}C= $token->{"type"} eq "range"
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||
| 241 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | (ref $token eq "HASH" && exists $token->{type} && $token->{type} eq "value") && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/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 table0%0/4
A and B and C
A= ref $token eq "HASH"B= exists $token->{"type"}C= $token->{"type"} eq "value"
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||
| 244 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 245 | 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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||
| 247 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 248 | 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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||
| 250 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | do { | |||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | $Data::Dumper::Indent = 1; | |||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | print Dumper($token); | |||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | die "can't process token for rule $rulename"; | |||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||
| 256 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | return $namelist; | |||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | sub walknonterminal | ||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
walknonterminal: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | my ( $rulename, $nonterminal ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | my $namelist = []; | |||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | SWITCH: | ||||||||||||||||||||||||||||||||||||||||||
| 269 | { | ||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | (exists $nonterminal->{rhs}) && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | my $rhs = $nonterminal->{rhs}; | |||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | my $sr = walktoken($rulename, $rhs); | |||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | push (@$namelist, @$sr); | |||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||
| 275 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | do { | |||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | $Data::Dumper::Indent = 1; | |||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | print Dumper($nonterminal); | |||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | die "can't process nonterminal for rule $rulename"; | |||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||
| 281 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | return $namelist; | |||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | sub walksubrule | ||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
walksubrule: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | my ($rulename, $rule) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | if (ref $rule ne "HASH" || !exists $rule->{rightsides}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $rule ne "HASH" or not exists $rule->{"rightsides"}
MC/DC0%0/2
ref $rule ne "HASH" or not exists $rule->{"rightsides"}
ref $rule ne "HASH"
not exists $rule->{"rightsides"}
Truth table0%0/3
A or not(B)
A= ref $rule ne "HASH"B= not exists $rule->{"rightsides"}
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | { | ||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | $Data::Dumper::Indent = 1; | |||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | print Dumper($rule); | |||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | die "rule '$rulename' is not a hash"; | |||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | my $rhs = $rule->{rightsides}; | |||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | return [] if !defined $rhs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | if (ref $rhs ne "ARRAY") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | { | ||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | $Data::Dumper::Indent = 1; | |||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | print Dumper($rhs); | |||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | die "'rhs' is not an array ref in '$rulename'"; | |||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | my $namelist = []; | |||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | for my $r (@$rhs) | |||||||||||||||||||||||||||||||||||||||||
| 312 | { | ||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | my $sr = walknonterminal($rulename, $r); | |||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | push (@$namelist, @$sr); | |||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | return $namelist; | |||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | sub joinReferences | ||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
joinReferences: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | my ($sr) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | my $temp = {}; | |||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | my $result = ""; | |||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | my $delim = ""; | |||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | for my $s (@$sr) | |||||||||||||||||||||||||||||||||||||||||
| 329 | { | ||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | if (!exists $temp->{$s}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | { | ||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | $temp->{$s} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | my $len = 16 - length($s); | |||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | my $ts = $s; | |||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | if ($len < 0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | { | ||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | $len = 0; | |||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | $ts = substr($ts, 0, 16); | |||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | my $pad = ""; | |||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | $pad = ' ' x $len if $len > 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | $result .= $delim . $ts . $pad; | |||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | $delim = " "; | |||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||
| 350 | sub verifySymbolNames | ||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
verifySymbolNames: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | my ($self, $rulename, $symbolnames ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | my $symboltable = \%{$self->{symboltable}}; | |||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | for my $sn (@$symbolnames) | |||||||||||||||||||||||||||||||||||||||||
| 357 | { | ||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | if (!exists $symboltable->{$sn}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 359 | { | ||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | printf "[%-1s][%-45s][%-2s] missing from symbol table : %s\n", "", $rulename, "", $sn; | |||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||
| 365 | sub validateSymbolTable | ||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validateSymbolTable: not called CC=20 SCAR=60.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | my $symboltable = \%{$self->{symboltable}}; | |||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | printf "===\n=== Composite Rules\n===\n\n"; | |||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | printf <<'END_OF_SOURCE'; | |||||||||||||||||||||||||||||||||||||||||
| 373 | +-------------------------------------------------------- rule name | ||||||||||||||||||||||||||||||||||||||||||
| 374 | +--!-------------------------------------------------------- Fragment (F), Lexeme (L) or regular rule | ||||||||||||||||||||||||||||||||||||||||||
| 375 | ! ! +--------- redirected (->) or contributing rule | ||||||||||||||||||||||||||||||||||||||||||
| 376 | ! ! ! +----- number of rule references | ||||||||||||||||||||||||||||||||||||||||||
| 377 | ! ! ! ! +- list of rule references | ||||||||||||||||||||||||||||||||||||||||||
| 378 | ! ! ! ! ! | ||||||||||||||||||||||||||||||||||||||||||
| 379 | V V V V V | ||||||||||||||||||||||||||||||||||||||||||
| 380 | END_OF_SOURCE | ||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | for my $name (sort keys %$symboltable) | |||||||||||||||||||||||||||||||||||||||||
| 383 | { | ||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | my $rule = $symboltable->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | SWITCH: | ||||||||||||||||||||||||||||||||||||||||||
| 387 | { | ||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | (exists $rule->{name}) && do | |||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | my $name = $rule->{name}; | |||||||||||||||||||||||||||||||||||||||||
| 391 | # if ($name eq "alter_table_properties") | ||||||||||||||||||||||||||||||||||||||||||
| 392 | # { | ||||||||||||||||||||||||||||||||||||||||||
| 393 | # printf "found!\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 394 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | my $symbolreferences = walksubrule($name, $rule); | |||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | ▶ | if (scalar @$symbolreferences > 0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 398 | { | ||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | my $strReferences = joinReferences($symbolreferences); | |||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | my $type = ""; | |||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | ▶ | $type = "L" if exists $rule->{isLexeme} || (exists $rule->{grammarstate} && $rule->{grammarstate} eq "lexer"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
exists $rule->{"isLexeme"} or exists $rule->{"grammarstate"} and $rule->{"grammarstate"} eq "lexer"
exists $rule->{"grammarstate"} and $rule->{"grammarstate"} eq "lexer"
MC/DC0%0/3
exists $rule->{"isLexeme"} or exists $rule->{"grammarstate"} and $rule->{"grammarstate"} eq "lexer"
exists $rule->{"isLexeme"}
exists $rule->{"grammarstate"}
$rule->{"grammarstate"} eq "lexer"
Truth table0%0/4
A or B and C
A= exists $rule->{"isLexeme"}B= exists $rule->{"grammarstate"}C= $rule->{"grammarstate"} eq "lexer"
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | ▶ | $type = "F" if exists $rule->{type} && $rule->{type} eq "fragment"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $rule->{"type"} and $rule->{"type"} eq "fragment"
MC/DC0%0/2
exists $rule->{"type"} and $rule->{"type"} eq "fragment"
exists $rule->{"type"}
$rule->{"type"} eq "fragment"
Truth table0%0/3
A and B
A= exists $rule->{"type"}B= $rule->{"type"} eq "fragment"
| |||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | ▶ | printf "[%-1s][%-45s][%-2s][%2d] %s\n", $type, $name, (exists $rule->{redirect}) ? "->" : "", scalar @$symbolreferences, $strReferences; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | $self->verifySymbolNames( $name, $symbolreferences ); | |||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||
| 407 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 408 | do | ||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | { | |||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | die "can't process rule"; | |||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||
| 412 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | printf "\n===\n=== Basic Rules\n===\n\n"; | |||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | printf <<'END_OF_SOURCE'; | |||||||||||||||||||||||||||||||||||||||||
| 418 | +-------------------------------------------------------- rule name | ||||||||||||||||||||||||||||||||||||||||||
| 419 | +--!-------------------------------------------------------- Fragment (F), Lexeme (L) or regular rule | ||||||||||||||||||||||||||||||||||||||||||
| 420 | ! ! +--------- redirected (->) or contributing rule | ||||||||||||||||||||||||||||||||||||||||||
| 421 | ! ! ! +----- n/a | ||||||||||||||||||||||||||||||||||||||||||
| 422 | ! ! ! ! | ||||||||||||||||||||||||||||||||||||||||||
| 423 | V V V V | ||||||||||||||||||||||||||||||||||||||||||
| 424 | END_OF_SOURCE | ||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | for my $name (sort keys %$symboltable) | |||||||||||||||||||||||||||||||||||||||||
| 427 | { | ||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | my $rule = $symboltable->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||
| 430 | SWITCH: | ||||||||||||||||||||||||||||||||||||||||||
| 431 | { | ||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | (exists $rule->{name}) && do | |||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | my $name = $rule->{name}; | |||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | my $symbolreferences = walksubrule($name, $rule); | |||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | ▶ | if ($name eq "TILDE_OPERATOR_PART") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 438 | { | ||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | printf "found!\n"; | |||||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | ▶ | if (scalar @$symbolreferences == 0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 442 | { | ||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | my $type = ""; | |||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | ▶ | $type = "L" if exists $rule->{isLexeme} || (exists $rule->{grammarstate} && $rule->{grammarstate} eq "lexer"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
exists $rule->{"isLexeme"} or exists $rule->{"grammarstate"} and $rule->{"grammarstate"} eq "lexer"
exists $rule->{"grammarstate"} and $rule->{"grammarstate"} eq "lexer"
MC/DC0%0/3
exists $rule->{"isLexeme"} or exists $rule->{"grammarstate"} and $rule->{"grammarstate"} eq "lexer"
exists $rule->{"isLexeme"}
exists $rule->{"grammarstate"}
$rule->{"grammarstate"} eq "lexer"
Truth table0%0/4
A or B and C
A= exists $rule->{"isLexeme"}B= exists $rule->{"grammarstate"}C= $rule->{"grammarstate"} eq "lexer"
| |||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | ▶ | $type = "F" if exists $rule->{type} && $rule->{type} eq "fragment"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $rule->{"type"} and $rule->{"type"} eq "fragment"
MC/DC0%0/2
exists $rule->{"type"} and $rule->{"type"} eq "fragment"
exists $rule->{"type"}
$rule->{"type"} eq "fragment"
Truth table0%0/3
A and B
A= exists $rule->{"type"}B= $rule->{"type"} eq "fragment"
| |||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | printf "[%-1s][%-45s][%-2s][%2s] %s\n", $type, $name, (exists $rule->{redirect}) ? "->" : "", "", ""; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||
| 449 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 450 | do | ||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | { | |||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | die "can't process rule"; | |||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | last SWITCH; | |||||||||||||||||||||||||||||||||||||||||
| 454 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | printf "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||
| 461 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||
| 463 | # ABSTRACT: manage symbol table of rules parsed from antlr grammar | ||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||
| 465 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 466 | use MarpaX::G4::Symboltable; | ||||||||||||||||||||||||||||||||||||||||||
| 467 | my $symboltable = new MarpaX::G4::Symboltable; | ||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||
| 469 | my $grammartext = readFile($infile); | ||||||||||||||||||||||||||||||||||||||||||
| 470 | my $data = MarpaX::G4::Parser::parse_rules($grammartext); | ||||||||||||||||||||||||||||||||||||||||||
| 471 | $symboltable->importParseTree($data); | ||||||||||||||||||||||||||||||||||||||||||
| 472 | $symboltable->validateSymbolTable(); | ||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||
| 474 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 475 | Import the rules from the ANTLR4 parse tree into a symbol table. | ||||||||||||||||||||||||||||||||||||||||||
| 476 | 'validateSymbolTable' does a depth-first tree traversal of the symbol table to produce a report of productions and terminal symbols. | ||||||||||||||||||||||||||||||||||||||||||
| 477 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||