blib/lib/Parse/Earley.pm

filter: Statementstmt 17.4% 41 / 235 Branchbran 14.1% 15 / 106 Conditioncond 4.0% 3 / 75 MC/DCmcdc 2.7% 1 / 37 Subroutinesub 47.0% 8 / 17 Podpod 0.0% 0 / 11 totaltotal 14.1% 68 / 481 CC 88 SCAR 54.1
CC
88
Cov
14%
scan
506.0
advance
342.0
complete
272.0
CRAP 223.7
↑ Summary
1 package Parse::Earley;
2  
3 #Parse::Earley
4 #By Luke Palmer
5 #Copyright (C) 2002, Luke Palmer. All rights reserved.
6 #This module is free software. It may used, redistributed, and/or modified
7 #under the terms of the Perl Artistic Licence:
8 # http://www.perl.com/perl/misc/Artistic.html
9  
10 1 ▶use Text::Balanced qw( extract_quotelike extract_codeblock
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 extract_bracketed extract_multiple );
12 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 our $VERSION = '0.15';
17 1 our $DEBUG;
18  
19 sub new($)
20 1 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
21 1 my $self = bless {
22 rules => { },
23 sets => { }, # Sparse array by pos()
24 set => [ ], # Not an index, rather, something to be pushed
25 ncset => [ ],
26 skip => qr/\s*/,
27 no_code => undef,
28 } => shift
29 }
30  
31 sub pushset(\$$)
32 0 ▶{
Subroutine pushset: not called CC=3 SCAR=24.8
Pod undocumented
33 # rule lhs dot pos ref
34 0 my ($self, $set) = @_;
35 0 my $change = 0;
36 0 for my $state (@$set) {
37 0 my $s = $self->{sets}{$state->{pos}};
38 # unless (grep { $_->{rule} == $state->{rule} &&
39 # $_->{lhs} eq $state->{lhs} &&
40 # $_->{dot} == $state->{dot} &&
41 # $_->{pos} == $state->{pos} &&
42 # $_->{ref} == $state->{ref} }
43 0 ▶ unless (grep { $_ == $state }
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$_ == $state;} @{$self->{"sets"}{$state->{"pos"}};}) 0 0 0
44 0 @{$self->{sets}{$state->{pos}}} ) {
45 0 push @{$self->{sets}{$state->{pos}}}, $state;
46 0 $change++;
47 }
48 }
49 0 return $change;
50 }
51  
52 # XXX: This is a I<really> simple processor: make it better
53 sub grammar(\$$)
54 1 ▶{
Subroutine grammar: called CC=20 SCAR=39.6
Pod undocumented
55 1 my ($self, $g) = @_;
56 1 local $_ = $g; # XXX: Pseudo hack. I don't know why I can't
57 # extract_multiple($g, ...)
58 my @toks = extract_multiple($_, [
59 qr/[a-zA-Z_]\w*\s*:/, # LHS
60 qr/[a-zA-Z_]\w*/, # Nonterminal
61 14 ▶ sub { scalar extract_quotelike($_); },
Subroutine __ANON__: called CC=1 SCAR=0.0
62 13 ▶ sub { scalar extract_bracketed($_, '<>') },
Subroutine __ANON__: called CC=1 SCAR=0.0
63 13 ▶ sub { scalar extract_codeblock($_, '{}') },
Subroutine __ANON__: called CC=1 SCAR=0.0
64 1 qr/\|/,
65 qr/#.*/m,
66 ]);
67 1 my @rulebuf;
68 my $curule;
69 1 my $errors;
70 1 my $noskip_f;
71 1 my $lineno;
72  
73 1 for (@toks)
74 {
75 19 $lineno++ for (/\n/g);
76
77 19 my %cp = (line => $lineno);
78 19 ▶ if ($noskip_f) {
Branch: 1 branch
BranchTrueFalseTotal
if ($noskip_f) 0 19 19
79 0 $noskip_f = 0;
80 0 %cp = (%cp, noskip => 1);
81 }
82
83 19 s/^\s+//;
84 19 s/\s+$//;
85
86 19 ▶ if (/^(\w+)\s*:$/) { # LHS
Branch: 9 branches
BranchTrueFalseTotal
if (/^(\w+)\s*:$/) { } 4 15 19
elsif (/^\|$/) { } 0 15 15
elsif (/^(\w+)$/) { } 5 10 15
elsif (/^['"]/) { } 1 9 10
elsif (/^q/) { } 0 9 9
elsif (m[^/(.*)/$] or /^m.(.*).$/) { } 0 9 9
elsif (/^<\s*(.*)\s*>$/) { } 0 9 9
elsif (/^{/) { } 0 9 9
elsif (/^#/ or /^\s*$/) { } 7 2 9
87 4 push @{$self->{rules}{$curule}}, [ @rulebuf ];
88 4 undef @rulebuf;
89 4 $curule = $1;
90 }
91 elsif (/^\|$/) {
92 0 push @{$self->{rules}{$curule}}, [ @rulebuf ];
93 0 undef @rulebuf;
94 }
95 elsif (/^(\w+)$/) { # Nonterminal
96 5 push @rulebuf, { %cp,
97 match => $1,
98 type => 'nonterminal' };
99 }
100 elsif (/^['"]/) { # Terminal
101 1 push @rulebuf, { %cp,
102 match => eval "$_",
103 type => 'literal' };
104 }
105 elsif (/^q/) {
106 0 push @rulebuf, { %cp,
107 match => eval "$_",
108 type => 'literal' };
109 }
110 ▶ elsif (/^\/(.*)\/$/ || /^m.(.*).$/) {
Condition33%1/3
m[^/(.*)/$] or /^m.(.*).$/
l!l&&r!l&&!r
009
MC/DC0%0/2
m[^/(.*)/$] or /^m.(.*).$/
m[^/(.*)/$] /^m.(.*).$/
Truth table33%1/3
A or B
A= m[^/(.*)/$]B= /^m.(.*).$/
ABresult
1X1
011
000
111 0 push @rulebuf, { %cp,
112 match => qr/$1/,
113 type => 'regex' };
114 }
115 elsif (/^<\s*(.*)\s*>$/) {
116 0 my $dir = $1;
117 0 ▶ if ($dir eq 'noskip') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir eq 'noskip') { } 0 0 0
118 0 $noskip_f = 1;
119 }
120 else {
121 0 $errors .= "Unrecognized directive: <$dir> at line $lineno\n";
122 }
123 }
124 elsif (/^{/) {
125 0 ▶ if ($self->{no_code}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'no_code'}) { } 0 0 0
elsif (@rulebuf) { } 0 0 0
126 0 $errors .= "Code not allowed\n";
127 }
128 elsif (@rulebuf) {
129 0 $rulebuf[$#rulebuf]{code} = eval "sub $_";
130 0 ▶ $errors .= "$@\n" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
131 }
132 else {
133 0 $errors .= "Condition does not follow anything at line $lineno\n";
134 }
135 }
136 ▶ elsif (/^#/ || /^\s*$/) {
Condition66%2/3
/^#/ or /^\s*$/
l!l&&r!l&&!r
072
MC/DC50%1/2
/^#/ or /^\s*$/
/^#/ /^\s*$/
Truth table66%2/3
A or B
A= /^#/B= /^\s*$/
ABresult
1X1
011
000
137 }
138 else {
139 2 $errors .= "Unrecognized pattern '$_' at line $lineno\n";
140 }
141 }
142 1 push @{$self->{rules}{$curule}}, [ @rulebuf ];
143 1 ▶ if ($errors) {
Branch: 1 branch
BranchTrueFalseTotal
if ($errors) { } 1 0 1
144 1 croak $errors;
145 }
146 else {
147 0 return 1;
148 }
149 }
150  
151 sub start(\$$)
152 0 ▶{
Subroutine start: not called CC=2 SCAR=17.9
Pod undocumented
153 0 my ($self, $rule) = @_;
154 0 my @newset;
155 0 $self->{sets} = { };
156 0 $self->{set} = [ ];
157 0 $self->{ncset} = [ ];
158 0 for (@{$self->{rules}{$rule}}) {
159 0 push @newset, { rule => $_,
160 lhs => $rule,
161 dot => 0,
162 pos => 0,
163 ref => 0 };
164 }
165 0 push @{$self->{ncset}}, @newset;
166 0 $self->pushset(\@newset);
167 }
168  
169 sub advance(\$$)
170 0 ▶{
Subroutine advance: not called CC=18 SCAR=58.3
Pod undocumented
171 0 my ($self, $str) = @_;
172  
173 0 $self->pushset($self->{ncset});
174 0 $self->{set} = $self->{ncset};
175 0 $self->{ncset} = [ ];
176  
177 0 for (@{$self->{set}}) {
178 #This is the main huffmanized switch.
179 #The heart of the algorithm is here.
180
181 0 my $p = $_->{rule}[$_->{dot}];
182 0 ▶ if ($p) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p) { } 0 0 0
183 0 ▶ if ($p->{type} eq 'nonterminal') {
Branch: 1 branch
BranchTrueFalseTotal
if ($p->{'type'} eq 'nonterminal') { } 0 0 0
184 0 $self->predict($_);
185 }
186 else {
187 0 $self->scan($_, $str);
188 }
189 }
190 else {
191 0 $self->complete($_);
192 }
193 }
194
195 0 ▶ if ($DEBUG) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Parse::Earley::DEBUG) 0 0 0
196 0 my $displen = 7;
197 0 my $sp = ' ' x 4;
198 0 for (qw(set ncset)) {
199 0 ▶ print /nc/ ? 'advance(): NEXT SET' : 'advance(): CURRENT SET';
Branch: 1 branch
BranchTrueFalseTotal
/nc/ ? : 0 0 0
200 0 print "\n";
201 0 for my $state (@{$self->{$_}}) {
202 0 print $sp;
203 0 my (@p);
204 0 ▶ if ($state->{pos} < $displen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state->{'pos'} < $displen) { } 0 0 0
205 0 $p[0] = substr($str, 0, $state->{pos});
206 }
207 else {
208 0 $p[0] = substr($str, $state->{pos}-$displen, $displen);
209 }
210 0 $p[1] = substr($str, $state->{pos}, 5);
211 0 ▶ s/(.)/ord($1)<32 || ord($1)>127 ? '.' : $1/seg for @p;
Branch: 1 branch
BranchTrueFalseTotal
ord $1 < 32 || ord $1 > 127 ? : 0 0 0
Condition0%0/3
ord $1 < 32 or ord $1 > 127
l!l&&r!l&&!r
000
MC/DC0%0/2
ord $1 < 32 or ord $1 > 127
ord $1 < 32 ord $1 > 127
Truth table0%0/3
A or B
A= ord $1 < 32B= ord $1 > 127
ABresult
1X1
011
000
212 0 printf "\%${displen}s * \%-${displen}s\%s", $p[0], $p[1], $sp;
213 0 print "($state->{pos}) $state->{lhs}: ";
214 0 ▶ for (my $i= 0; $i < @{$state->{rule}} || $i <= $state->{dot}; $i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$state->{"rule"};} or $i <= $state->{"dot"}) 0 0 0
Condition0%0/3
$i < @{$state->{"rule"};} or $i <= $state->{"dot"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$i < @{$state->{"rule"};} or $i <= $state->{"dot"}
$i < @{$state->{"rule"};} $i <= $state->{"dot"}
Truth table0%0/3
A or B
A= $i < @{$state->{"rule"};}B= $i <= $state->{"dot"}
ABresult
1X1
011
000
215 0 ▶ if ($state->{dot} == $i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state->{"dot"} == $i) 0 0 0
216 0 print "* ";
217 }
218 0 ▶ if (exists $state->{rule}[$i]) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $state->{"rule"}[$i]) 0 0 0
219 0 my $t = $state->{rule}[$i]{type};
220 0 my $p = $state->{rule}[$i]{match};
221 0 ▶ if ($t eq 'literal') {
Branch: 2 branches
BranchTrueFalseTotal
if ($t eq 'literal') { } 0 0 0
elsif ($t eq 'regex') { } 0 0 0
222 0 print "'$p' "
223 }
224 elsif ($t eq 'regex') {
225 0 $p =~ s/^.*?://; # Get rid of the qr// stuff
226 0 $p =~ s/\)$//;
227 0 print "/$p/ "
228
229 }
230 else {
231 0 print "$p ";
232 }
233 }
234 }
235 0 print "($state->{ref})\n";
236 }
237 }
238
239 }
240
241 }
242  
243 #This function checks for matching the entire input. Sub matches
244 #are seldom of use, and so they are discarded (as they make the
245 #parse graph needlessly huge).
246 sub matches(\$$$)
247 0 ▶{
Subroutine matches: not called CC=4 SCAR=30.0
Pod undocumented
248 0 my ($self, $str, $rule) = @_;
249 0 $str =~ s/$self->{skip}$//;
250 0 ▶ my $cset = $self->{sets}{length($str)} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $cset = $self->{"sets"}{length $str} or return 0 0 0
251 0 return grep { $_->{lhs} eq $rule &&
252 0 $_->{dot} == @{$_->{rule}} &&
253 0 ▶ $_->{ref} == 0 }
Condition0%0/6
$_->{'lhs'} eq $rule && $_->{'dot'} == @{$_->{'rule'};} && $_->{'ref'} == 0
!ll&&!rl&&r
000
$_->{"lhs"} eq $rule and $_->{"dot"} == @{$_->{"rule"};}
!ll&&!rl&&r
000
MC/DC0%0/3
$_->{'lhs'} eq $rule && $_->{'dot'} == @{$_->{'rule'};} && $_->{'ref'} == 0
$_->{"lhs"} eq $rule $_->{"dot"} == @{$_->{"rule"};} $_->{'ref'} == 0
Truth table0%0/4
A and B && C
A= $_->{"lhs"} eq $ruleB= $_->{"dot"} == @{$_->{"rule"};}C= $_->{'ref'} == 0
ABCresult
0XX0
10X0
1100
1111
254 @$cset;
255 }
256  
257 sub matches_all(\$$$)
258 0 ▶{
Subroutine matches_all: not called CC=2 SCAR=17.9
Pod undocumented
259 0 my ($self, $str, $rule) = @_;
260 0 my $cset = $self->{ncset};
261 0 ▶ unless (@$cset) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$cset) 0 0 0
262 0 return $self->matches($str, $rule);
263 }
264 0 return;
265 }
266  
267 sub fails(\$$$)
268 0 ▶{
Subroutine fails: not called CC=3 SCAR=24.8
Pod undocumented
269 0 my ($self, $str, $rule) = @_;
270 0 ▶ if ($self->matches($str, $rule)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->matches($str, $rule)) { } 0 0 0
271 0 return 0;
272 }
273 else {
274 0 ▶ return @{$self->{set}} ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
@{$self->{'set'};} ? : 0 0 0
275 }
276 }
277  
278 sub predict(\$$)
279 0 ▶{
Subroutine predict: not called CC=7 SCAR=40.3
Pod undocumented
280 0 my ($self, $state) = @_;
281 0 my $cset = $self->{set};
282 0 my $p = $state->{rule}[$state->{dot}];
283
284 0 ▶ unless ($self->{rules}{$p->{match}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"rules"}{$p->{"match"}}) 0 0 0
285 0 croak "No definition for nonterminal '$p->{match}'\n";
286 }
287 0 my @newset = @{$self->{rules}{$p->{match}}};
288 @newset = map {
289 0 my $m = $_;
290 0 ▶ unless (grep { $_->{rule} == $m &&
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_->{'rule'} == $m and $_->{'lhs'} eq $p->{'match'} and $_->{'dot'} == 0 and $_->{'pos'} == $state->{'pos'} and $_->{'ref'} == $state->{'pos'};} @$cset) { } 0 0 0
291 $_->{lhs} eq $p->{match} &&
292 $_->{dot} == 0 &&
293 $_->{pos} == $state->{pos} &&
294 0 ▶ $_->{ref} == $state->{pos} } @$cset) {
Condition0%0/12
$_->{'rule'} == $m && $_->{'lhs'} eq $p->{'match'} && $_->{'dot'} == 0 && $_->{'pos'} == $state->{'pos'} && $_->{'ref'} == $state->{'pos'}
!ll&&!rl&&r
000
$_->{"rule"} == $m and $_->{"lhs"} eq $p->{"match"} and $_->{"dot"} == 0 and $_->{"pos"} == $state->{"pos"}
!ll&&!rl&&r
000
$_->{"rule"} == $m and $_->{"lhs"} eq $p->{"match"} and $_->{"dot"} == 0
!ll&&!rl&&r
000
$_->{"rule"} == $m and $_->{"lhs"} eq $p->{"match"}
!ll&&!rl&&r
000
MC/DC0%0/5
$_->{'rule'} == $m && $_->{'lhs'} eq $p->{'match'} && $_->{'dot'} == 0 && $_->{'pos'} == $state->{'pos'} && $_->{'ref'} == $state->{'pos'}
$_->{"rule"} == $m $_->{"lhs"} eq $p->{"match"} $_->{"dot"} == 0 $_->{"pos"} == $state->{"pos"} $_->{'ref'} == $state->{'pos'}
Truth table0%0/6
A and B and C and D && E
A= $_->{"rule"} == $mB= $_->{"lhs"} eq $p->{"match"}C= $_->{"dot"} == 0D= $_->{"pos"} == $state->{"pos"}E= $_->{'ref'} == $state->{'pos'}
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
295 { rule => $m,
296 lhs => $p->{match},
297 dot => 0,
298 pos => $state->{pos},
299 ref => $state->{pos} }
300 0 }
301 else {
302 ()
303 0 }
304 } @newset;
305 0 push @$cset, @newset;
306 0 $self->pushset(\@newset);
307 }
308  
309  
310 sub scan(\$$$)
311 0 ▶{
Subroutine scan: not called CC=22 SCAR=62.3
Pod undocumented
312 0 my ($self, $state, $str) = @_;
313 0 my $cset = $self->{set};
314 0 my $skipos = $state->{pos};
315 0 my $p = $state->{rule}[$state->{dot}];
316  
317 0 ▶ unless ($state->{rule}[$state->{dot}]{noskip}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($state->{"rule"}[$state->{"dot"}]{"noskip"}) 0 0 0
318 0 pos $str = $skipos;
319 0 $str =~ /\G$self->{skip}/g; # Terminal Seperator!
320 0 $skipos = pos $str;
321 }
322  
323 0 ▶ if ($p->{type} eq 'literal') {
Branch: 2 branches
BranchTrueFalseTotal
if ($p->{'type'} eq 'literal') { } 0 0 0
elsif ($p->{'type'} eq 'regex') { } 0 0 0
324 0 my $tok = substr($str, $skipos, length $p->{match});
325 0 my $res = 1;
326 0 ▶ if ($p->{code}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p->{"code"}) 0 0 0
327 0 local $_ = $tok;
328 0 $res = eval { $p->{code}() };
329 0 ▶ croak "$@ near line $p->{line} of grammar\n" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
330 }
331 0 ▶ if ($res and $tok eq $p->{match}){
Branch: 1 branch
BranchTrueFalseTotal
if ($res and $tok eq $p->{"match"}) 0 0 0
Condition0%0/3
$res and $tok eq $p->{"match"}
!ll&&!rl&&r
000
MC/DC0%0/2
$res and $tok eq $p->{"match"}
$res $tok eq $p->{"match"}
Truth table0%0/3
A and B
A= $resB= $tok eq $p->{"match"}
ABresult
0X0
100
111
332 my $push = {
333 rule => $state->{rule},
334 lhs => $state->{lhs},
335 dot => $state->{dot}+1,
336 pos => $skipos+length $p->{match},
337 ref => $state->{ref},
338 0 tok => $tok ,
339 left => [ $state ] };
340 0 ▶ unless (grep {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$_->{"rule"} == $push->{"rule"} and $_->{"lhs"} eq $push->{"lhs"} and $_->{"dot"} == $push->{"dot"} and $_->{"pos"} == $push->{"pos"} and $_->{"ref"} == $push->{"ref"};} @{$$self{"ncset"};}) 0 0 0
341 $_->{rule} == $push->{rule} &&
342 $_->{lhs} eq $push->{lhs} &&
343 $_->{dot} == $push->{dot} &&
344 $_->{pos} == $push->{pos} &&
345 0 ▶ $_->{ref} == $push->{ref} } @{$self->{ncset}} ) {
Condition0%0/12
$_->{'rule'} == $push->{'rule'} && $_->{'lhs'} eq $push->{'lhs'} && $_->{'dot'} == $push->{'dot'} && $_->{'pos'} == $push->{'pos'} && $_->{'ref'} == $push->{'ref'}
!ll&&!rl&&r
000
$_->{"rule"} == $push->{"rule"} and $_->{"lhs"} eq $push->{"lhs"} and $_->{"dot"} == $push->{"dot"} and $_->{"pos"} == $push->{"pos"}
!ll&&!rl&&r
000
$_->{"rule"} == $push->{"rule"} and $_->{"lhs"} eq $push->{"lhs"} and $_->{"dot"} == $push->{"dot"}
!ll&&!rl&&r
000
$_->{"rule"} == $push->{"rule"} and $_->{"lhs"} eq $push->{"lhs"}
!ll&&!rl&&r
000
MC/DC0%0/5
$_->{'rule'} == $push->{'rule'} && $_->{'lhs'} eq $push->{'lhs'} && $_->{'dot'} == $push->{'dot'} && $_->{'pos'} == $push->{'pos'} && $_->{'ref'} == $push->{'ref'}
$_->{"rule"} == $push->{"rule"} $_->{"lhs"} eq $push->{"lhs"} $_->{"dot"} == $push->{"dot"} $_->{"pos"} == $push->{"pos"} $_->{'ref'} == $push->{'ref'}
Truth table0%0/6
A and B and C and D && E
A= $_->{"rule"} == $push->{"rule"}B= $_->{"lhs"} eq $push->{"lhs"}C= $_->{"dot"} == $push->{"dot"}D= $_->{"pos"} == $push->{"pos"}E= $_->{'ref'} == $push->{'ref'}
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
346 0 push @{$self->{ncset}}, $push;
347 # push @{$self->{sets}{$push->{pos}}}, $push;
348 }
349 }
350 }
351 elsif ($p->{type} eq 'regex') {
352 0 pos $str = $skipos;
353 0 ▶ if ($str =~ /\G($p->{match})/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /\G($p->{"match"})/g) 0 0 0
354 0 my $tok = $1;
355 0 ▶ if ($p->{code}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p->{"code"}) 0 0 0
356 0 local $_ = $tok;
357 0 my $res = eval { $p->{code}() };
358 0 ▶ croak "$@ near line $p->{line} of grammar\n" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
359 0 ▶ return unless $res; # Should make this some sort of break
Branch: 1 branch
BranchTrueFalseTotal
unless $res 0 0 0
360 }
361 my $push = {
362 rule => $state->{rule},
363 lhs => $state->{lhs},
364 dot => $state->{dot}+1,
365 pos => pos $str,
366 ref => $state->{ref},
367 0 tok => $tok,
368 left => [ $state ] };
369 0 ▶ unless (grep {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$_->{"rule"} == $push->{"rule"} and $_->{"lhs"} eq $push->{"lhs"} and $_->{"dot"} == $push->{"dot"} and $_->{"pos"} == $push->{"pos"} and $_->{"ref"} == $push->{"ref"};} @{$$self{"ncset"};}) 0 0 0
370 $_->{rule} == $push->{rule} &&
371 $_->{lhs} eq $push->{lhs} &&
372 $_->{dot} == $push->{dot} &&
373 $_->{pos} == $push->{pos} &&
374 0 ▶ $_->{ref} == $push->{ref} } @{$self->{ncset}} ) {
Condition0%0/12
$_->{'rule'} == $push->{'rule'} && $_->{'lhs'} eq $push->{'lhs'} && $_->{'dot'} == $push->{'dot'} && $_->{'pos'} == $push->{'pos'} && $_->{'ref'} == $push->{'ref'}
!ll&&!rl&&r
000
$_->{"rule"} == $push->{"rule"} and $_->{"lhs"} eq $push->{"lhs"} and $_->{"dot"} == $push->{"dot"} and $_->{"pos"} == $push->{"pos"}
!ll&&!rl&&r
000
$_->{"rule"} == $push->{"rule"} and $_->{"lhs"} eq $push->{"lhs"} and $_->{"dot"} == $push->{"dot"}
!ll&&!rl&&r
000
$_->{"rule"} == $push->{"rule"} and $_->{"lhs"} eq $push->{"lhs"}
!ll&&!rl&&r
000
MC/DC0%0/5
$_->{'rule'} == $push->{'rule'} && $_->{'lhs'} eq $push->{'lhs'} && $_->{'dot'} == $push->{'dot'} && $_->{'pos'} == $push->{'pos'} && $_->{'ref'} == $push->{'ref'}
$_->{"rule"} == $push->{"rule"} $_->{"lhs"} eq $push->{"lhs"} $_->{"dot"} == $push->{"dot"} $_->{"pos"} == $push->{"pos"} $_->{'ref'} == $push->{'ref'}
Truth table0%0/6
A and B and C and D && E
A= $_->{"rule"} == $push->{"rule"}B= $_->{"lhs"} eq $push->{"lhs"}C= $_->{"dot"} == $push->{"dot"}D= $_->{"pos"} == $push->{"pos"}E= $_->{'ref'} == $push->{'ref'}
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
375 0 push @{$self->{ncset}}, $push;
376 0 push @{$self->{sets}{$push->{pos}}}, $push;
377 }
378 }
379 }
380 }
381  
382 sub complete(\$$)
383 0 ▶{
Subroutine complete: not called CC=16 SCAR=56.1
Pod undocumented
384 0 my ($self, $state) = @_;
385 0 my $cset = $self->{set};
386 my @newset = grep {
387 (exists $_->{rule}[$_->{dot}] &&
388 0 ▶ $_->{rule}[$_->{dot}]{match}) eq $state->{lhs} }
Condition0%0/3
exists $_->{'rule'}[$_->{'dot'}] && $_->{'rule'}[$_->{'dot'}]{'match'}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $_->{'rule'}[$_->{'dot'}] && $_->{'rule'}[$_->{'dot'}]{'match'}
exists $_->{'rule'}[$_->{'dot'}] $_->{'rule'}[$_->{'dot'}]{'match'}
Truth table0%0/3
A && B
A= exists $_->{'rule'}[$_->{'dot'}]B= $_->{'rule'}[$_->{'dot'}]{'match'}
ABresult
0X0
100
111
389 0 @{$self->{sets}{$state->{ref}}};
390 0 my @reval;
391 @newset = map {
392 0 my $m = $_;
393 0 my @g;
394 0 ▶ unless (@g = grep { $_->{rule} == $m->{rule} &&
Branch: 1 branch
BranchTrueFalseTotal
if (@g = grep({$_->{'rule'} == $m->{'rule'} and $_->{'lhs'} eq $m->{'lhs'} and $_->{'dot'} == $m->{'dot'} + 1 and $_->{'pos'} == $state->{'pos'} and $_->{'ref'} == $m->{'ref'};} @$cset)) { } 0 0 0
395 $_->{lhs} eq $m->{lhs} &&
396 $_->{dot} == $m->{dot}+1 &&
397 $_->{pos} == $state->{pos} &&
398 0 ▶ $_->{ref} == $m->{ref} } @$cset) {
Condition0%0/12
$_->{'rule'} == $m->{'rule'} && $_->{'lhs'} eq $m->{'lhs'} && $_->{'dot'} == $m->{'dot'} + 1 && $_->{'pos'} == $state->{'pos'} && $_->{'ref'} == $m->{'ref'}
!ll&&!rl&&r
000
$_->{"rule"} == $m->{"rule"} and $_->{"lhs"} eq $m->{"lhs"} and $_->{"dot"} == $m->{"dot"} + 1 and $_->{"pos"} == $state->{"pos"}
!ll&&!rl&&r
000
$_->{"rule"} == $m->{"rule"} and $_->{"lhs"} eq $m->{"lhs"} and $_->{"dot"} == $m->{"dot"} + 1
!ll&&!rl&&r
000
$_->{"rule"} == $m->{"rule"} and $_->{"lhs"} eq $m->{"lhs"}
!ll&&!rl&&r
000
MC/DC0%0/5
$_->{'rule'} == $m->{'rule'} && $_->{'lhs'} eq $m->{'lhs'} && $_->{'dot'} == $m->{'dot'} + 1 && $_->{'pos'} == $state->{'pos'} && $_->{'ref'} == $m->{'ref'}
$_->{"rule"} == $m->{"rule"} $_->{"lhs"} eq $m->{"lhs"} $_->{"dot"} == $m->{"dot"} + 1 $_->{"pos"} == $state->{"pos"} $_->{'ref'} == $m->{'ref'}
Truth table0%0/6
A and B and C and D && E
A= $_->{"rule"} == $m->{"rule"}B= $_->{"lhs"} eq $m->{"lhs"}C= $_->{"dot"} == $m->{"dot"} + 1D= $_->{"pos"} == $state->{"pos"}E= $_->{'ref'} == $m->{'ref'}
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
399
400 my $push = { rule => $m->{rule},
401 lhs => $m->{lhs},
402 dot => $m->{dot}+1,
403 pos => $state->{pos},
404 ref => $m->{ref},
405 0 down => [ $state ],
406 left => [ $m ],
407 };
408 0 ▶ if ($m->{rule}[$m->{dot}]{code}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m->{'rule'}[$m->{'dot'}]{'code'}) { } 0 0 0
409 0 local $_ = $state;
410 0 my $res = eval { $m->{rule}[$m->{dot}]{code}() };
411 0 ▶ croak "$@ near line $m->{rule}[$m->{dot}]{line} "
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
412 ."of grammar\n" if $@;
413 0 ▶ $res ? $push : ()
Branch: 1 branch
BranchTrueFalseTotal
$res ? : 0 0 0
414 }
415 else {
416 0 $push
417 }
418 }
419 else {
420 0 for (@g) {
421 0 ▶ unless (grep { $_ == $state } @{$_->{down}} and
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$_ == $state;} @{$$_{"down"};} and grep {$_ == $m;} @{$$_{"left"};}) 0 0 0
Condition0%0/3
grep {$_ == $state;} @{$$_{"down"};} and grep {$_ == $m;} @{$$_{"left"};}
!ll&&!rl&&r
000
MC/DC0%0/2
grep {$_ == $state;} @{$$_{"down"};} and grep {$_ == $m;} @{$$_{"left"};}
grep {$_ == $state;} @{$$_{"down"};} grep {$_ == $m;} @{$$_{"left"};}
Truth table0%0/3
A and B
A= grep {$_ == $state;} @{$$_{"down"};}B= grep {$_ == $m;} @{$$_{"left"};}
ABresult
0X0
100
111
422 0 grep { $_ == $m } @{$_->{left}}) {
423 0 my $succ = 1;
424 0 ▶ if ($m->{rule}[$m->{dot}]{code}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m->{"rule"}[$m->{"dot"}]{"code"}) 0 0 0
425 0 my $left;
426 0 local $_ = $state;
427 0 $succ = eval { $m->{rule}[$m->{dot}]{code}() };
428 0 ▶ croak "$@ near line $m->{rule}[$m->{dot}]{line} "
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
429 ."of grammar\n" if $@;
430 }
431 0 ▶ if ($succ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($succ) 0 0 0
432 0 push @{$_->{down}}, $state;
433 0 push @{$_->{left}}, $m;
434 }
435 }
436 }
437 ()
438 0 }
439 } @newset;
440 0 push @$cset, @newset;
441 0 $self->pushset(\@newset);
442 }
443  
444 1 1;
445  
446 __END__
↑ Summary