| 1 | package Math::Logic::Predicate; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Parse::RecDescent; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | our $GRAMMAR = join '', <DATA>; | |||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | our $DEBUG; | |||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | our $VERSION = 0.03; | |||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | sub new($) | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | my ($class) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | bless { | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | pred => { }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 125 | ▶ | nonterm => sub { $_[0] =~ /^[_A-Z]/ }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | no_code => undef, | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | parser => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | } => $class | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | sub rules(\$) : lvalue | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rules: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | shift->{pred} | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | } | |||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | sub parse(\$$;$) | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 11 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=6 SCAR=18.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 11 | my ($self, $expr, $auto) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 32 | 11 | ▶ | $self->{parser} ||= new Parse::RecDescent($GRAMMAR) or confess; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"parser"} ||= "Parse::RecDescent"->new($Math::Logic::Predicate::GRAMMAR)
MC/DC0%0/2
$self->{"parser"} ||= "Parse::RecDescent"->new($Math::Logic::Predicate::GRAMMAR)
$self->{"parser"}
"Parse::RecDescent"->new($Math::Logic::Predicate::GRAMMAR)
Truth table66%2/3
A ||= B
A= $self->{"parser"}B= "Parse::RecDescent"->new($Math::Logic::Predicate::GRAMMAR)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 11 | $self->{parser}{LG} = $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 34 | 11 | my $ret; | |||||||||||||||||||||||||||||||||||||||||||||
| 35 | 11 | ▶ | if ($auto) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 3 | $ret = $self->{parser}->auto($expr); | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 8 | $ret = $self->{parser}->statement($expr); | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 11 | ▶ | if ($ret) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 11 | ▶ | return wantarray ? @$ret : $ret->[0]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | return | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | } | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | sub newproc(\$$$;$$$) | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 72 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
newproc: called CC=8 SCAR=23.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 72 | my ($self, $rule, $args, $context, $next, $prev) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | 72 | ▶ | $context ||= 'true'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$context ||= "true"
MC/DC0%0/1
$context ||= "true"
$context
Truth table50%1/2
A
A= $context
| |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 72 | ▶ | unless (grep { $context == $_ } qw(true false and or sub bind)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | croak "'$context' is not a valid context type"; | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 72 | my $ret = { | |||||||||||||||||||||||||||||||||||||||||||||
| 57 | context => $context, | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | rule => $rule, | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | args => $args, | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 72 | $ret->{next} = $next; | |||||||||||||||||||||||||||||||||||||||||||||
| 63 | 72 | $ret->{fail} = $prev; | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | 72 | ▶ | unless ($context eq 'true' || $context eq 'false' || $context eq 'bind') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$context eq "true" or $context eq "false" or $context eq "bind"
$context eq "true" or $context eq "false"
MC/DC33%1/3
$context eq "true" or $context eq "false" or $context eq "bind"
$context eq "true"
$context eq "false"
$context eq "bind"
Truth table50%2/4
A or B or C
A= $context eq "true"B= $context eq "false"C= $context eq "bind"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 66 | ▶ | $ret->{next}{fail} ||= $ret if $next; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ret->{"next"}{"fail"} ||= $ret
MC/DC0%0/2
$ret->{"next"}{"fail"} ||= $ret
$ret->{"next"}{"fail"}
$ret
Truth table0%0/3
A ||= B
A= $ret->{"next"}{"fail"}B= $ret
| |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | $ret | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 72 | } | |||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | sub add(\$$) | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 13 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add: called CC=8 SCAR=22.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 13 | my ($self, $proc) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 13 | ▶ | if (ref $proc) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 10 | ▶ | croak "You can't add an undefined rule" unless $proc; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 10 | ▶ | croak "You can't add queries to the database" if $proc->{rule} eq '^QUERY'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 10 | ▶ | croak "You can't add variable predicates"if $self->{nonterm}($proc->{rule}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 10 | ▶ | if (@{$proc->{args}}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 10 | ▶ | $self->{pred}{$proc->{rule}} = { } unless $self->{pred}{$proc->{rule}}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | $self->{pred}{$proc->{rule}} = [ ] unless $self->{pred}{$proc->{rule}}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 10 | $self->addproc_h($proc, 0, $self->{pred}{$proc->{rule}}); | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | 10 | $proc | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 3 | $self->parse($proc, 'auto') | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | sub retract(\$$) | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
retract: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 2 | my ($self, $proc) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 2 | ▶ | $proc = $self->parse($proc) unless ref $proc; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 2 | my ($pad, $frame) = ( {}, {} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 102 | 2 | ▶ | while ($self->lookup($proc, $frame, $pad, 'delete')) { } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | sub addproc_h(\$$$$) | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 25 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
addproc_h: called CC=11 SCAR=24.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 25 | my ($self, $proc, $argn, $href) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 109 | 25 | ▶ | if (local $_ = $proc->{args}[$argn]) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 15 | ▶ | my $r = $self->{nonterm}($_) ? '_' : $_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 15 | ▶ | unless ($href->{$r}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 15 | ▶ | if ($argn == $#{$proc->{args}}) { # Last argument | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 10 | $href->{$r} = [ ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 5 | $href->{$r} = { }; | |||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 15 | delete $href->{'^SORT'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 15 | $self->addproc_h($proc, $argn+1, $href->{$r}); | |||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | # Don't duplicate | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 10 | ▶ | if ($proc->{context} eq 'true' || | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$proc->{"context"} eq "true" or $proc->{"context"} eq "false"
MC/DC50%1/2
$proc->{"context"} eq "true" or $proc->{"context"} eq "false"
$proc->{"context"} eq "true"
$proc->{"context"} eq "false"
Truth table66%2/3
A or B
A= $proc->{"context"} eq "true"B= $proc->{"context"} eq "false"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | $proc->{context} eq 'false') { # Don't duplicate | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | return if grep { $_->{context} eq $proc->{context} } @$href; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | # Is this rule directly recursive? | ||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 10 | ▶ | if ($proc->{context} eq 'bind') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 2 | my $cptr = $proc->{next}; | |||||||||||||||||||||||||||||||||||||||||||||
| 131 | 2 | ▶ | while ($cptr) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 2 | ▶ | if ($cptr->{rule} eq $proc->{rule}) { #If so... | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | push @$href, $proc; | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 2 | $cptr = $cptr->{next}; | |||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 10 | unshift @$href, $proc; | |||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 25 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | sub lookup(\$$$$;$) | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 17 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lookup: called CC=29 SCAR=33.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 17 | my ($self, $proc, $lse, $pad, $delete) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 17 | my $rule = $proc->{rule}; | |||||||||||||||||||||||||||||||||||||||||||||
| 149 | 17 | ▶ | $rule = $pad->{$rule} if $self->{nonterm}($rule); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 17 | ▶ | $lse->{fail}++,return if $lse->{fail}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 17 | ▶ | $lse->{fail}++,return unless $rule && $self->{pred}{$rule}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$rule and $self->{"pred"}{$rule}
MC/DC0%0/2
$rule and $self->{"pred"}{$rule}
$rule
$self->{"pred"}{$rule}
Truth table33%1/3
A and B
A= $ruleB= $self->{"pred"}{$rule}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 17 | ▶ | $lse->{pred_stack} ||= [ $self->{pred}{$rule} ]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$lse->{"pred_stack"} ||= [$self->{"pred"}{$rule}]
MC/DC100%1/1
$lse->{"pred_stack"} ||= [$self->{"pred"}{$rule}]
$lse->{"pred_stack"}
Truth table100%2/2
A
A= $lse->{"pred_stack"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 17 | ▶ | $lse->{iter_stack} ||= [ 0 ]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$lse->{"iter_stack"} ||= [0]
MC/DC100%1/1
$lse->{"iter_stack"} ||= [0]
$lse->{"iter_stack"}
Truth table100%2/2
A
A= $lse->{"iter_stack"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 17 | ▶ | $lse->{bind_stack} ||= [ 0 ]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$lse->{"bind_stack"} ||= [0]
MC/DC100%1/1
$lse->{"bind_stack"} ||= [0]
$lse->{"bind_stack"}
Truth table100%2/2
A
A= $lse->{"bind_stack"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 17 | ▶ | $lse->{pos} ||= 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$lse->{"pos"} ||= 0
MC/DC100%1/1
$lse->{"pos"} ||= 0
$lse->{"pos"}
Truth table100%2/2
A
A= $lse->{"pos"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 17 | my $pred = $lse->{pred_stack}; | |||||||||||||||||||||||||||||||||||||||||||||
| 160 | 17 | my $iter = $lse->{iter_stack}; | |||||||||||||||||||||||||||||||||||||||||||||
| 161 | 17 | my $bind = $lse->{bind_stack}; | |||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 17 | ▶ | while (@$pred) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 47 | my $p; | |||||||||||||||||||||||||||||||||||||||||||||
| 166 | 47 | ▶ | unless ($lse->{pos} == @{$proc->{args}}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 29 | $p = $proc->{args}[$lse->{pos}]; | |||||||||||||||||||||||||||||||||||||||||||||
| 168 | 13 | $pred->[0]{'^SORT'} = [ sort keys %{$pred->[0]} ] | |||||||||||||||||||||||||||||||||||||||||||||
| 169 | 29 | ▶ | unless $pred->[0]{'^SORT'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 47 | my $state = 'push'; | |||||||||||||||||||||||||||||||||||||||||||||
| 172 | 47 | ▶ | $p = exists $pad->{$p} ? $pad->{$p} : $p; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 47 | ▶ | if ($lse->{pos} == @{$proc->{args}}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 18 | ▶ | $state = 'pop' if $iter->[0] == @{$pred->[0]}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 177 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 29 | ▶ | if ($self->{nonterm}($p)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 9 | ▶ | $state = 'pop' if $iter->[0] == @{$pred->[0]{'^SORT'}}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 181 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 20 | my $len = exists($pred->[0]{$p}) + exists($pred->[0]{_}); | |||||||||||||||||||||||||||||||||||||||||||||
| 183 | 20 | ▶ | $state = 'pop' if $iter->[0] >= $len; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 47 | ▶ | if ($state eq 'pop') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 19 | my $free = shift @$bind; | |||||||||||||||||||||||||||||||||||||||||||||
| 189 | 19 | shift @$iter; | |||||||||||||||||||||||||||||||||||||||||||||
| 190 | 19 | shift @$pred; | |||||||||||||||||||||||||||||||||||||||||||||
| 191 | 19 | ▶ | delete $pad->{$free} if $free; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 19 | $lse->{pos}--; | |||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 19 | ▶ | unless (@$iter) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 7 | $lse->{fail}++; | |||||||||||||||||||||||||||||||||||||||||||||
| 197 | 7 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 200 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 28 | my $ind; | |||||||||||||||||||||||||||||||||||||||||||||
| 202 | 28 | my $pi = $iter->[0]++; | |||||||||||||||||||||||||||||||||||||||||||||
| 203 | 28 | ▶ | unless (defined $p) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 10 | ▶ | if ($delete) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 3 | delete $pred->[1]{'^SORT'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 206 | 3 | return splice @{$pred->[0]}, --$iter->[0], 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 208 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 7 | return $pred->[0][$pi]; | |||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 212 | elsif ($self->{nonterm}($p)) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 7 | $ind = $pred->[0]{'^SORT'}[$pi]; | |||||||||||||||||||||||||||||||||||||||||||||
| 214 | # No binding to anonymous vars | ||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 7 | ▶ | unless ($p eq '_' || $ind eq '_' || | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$p eq "_" or $ind eq "_" or exists $pad->{$p}
$p eq "_" or $ind eq "_"
MC/DC66%2/3
$p eq "_" or $ind eq "_" or exists $pad->{$p}
$p eq "_"
$ind eq "_"
exists $pad->{$p}
Truth table75%3/4
A or B or C
A= $p eq "_"B= $ind eq "_"C= exists $pad->{$p}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 216 | exists $pad->{$p}) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 3 | $pad->{$p} = $ind; | |||||||||||||||||||||||||||||||||||||||||||||
| 218 | 3 | unshift @$bind, $p; | |||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 220 | else { # Still need a frame, though | ||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 4 | unshift @$bind, (undef); | |||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 224 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 11 | ▶ | if ($pi) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | $ind = '_'; | |||||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 228 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 11 | ▶ | $ind = exists $pred->[0]{$p} ? $p : '_'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 11 | unshift @$bind, 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 18 | unshift @$pred, $pred->[0]{$ind}; | |||||||||||||||||||||||||||||||||||||||||||||
| 234 | 18 | unshift @$iter, 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 235 | 18 | $lse->{pos}++; | |||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 16 | ▶ | sub copy_pad(\$$$$$;$) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
copy_pad: called CC=10 SCAR=23.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 16 | my ($self, $srule, $scon, $drule, $dcon, $bindtrack) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 16 | ▶ | return unless @{$srule->{args}} == @{$drule->{args}}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||
| 245 | # I want perl6 parallel iteration!! | ||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 16 | ▶ | for (my $i = 0; $i < @{$drule->{args}}; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 22 | ▶ | if ($self->{nonterm}($drule->{args}[$i])) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 12 | my $bind = $srule->{args}[$i]; | |||||||||||||||||||||||||||||||||||||||||||||
| 249 | 12 | ▶ | $bind = $scon->{pad}{$bind} if $self->{nonterm}($bind); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 12 | ▶ | if (defined $bind && $drule->{args}[$i] ne '_' && | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $bind and $drule->{"args"}[$i] ne "_" and not exists $dcon->{"pad"}{$drule->{"args"}[$i]}
defined $bind and $drule->{"args"}[$i] ne "_"
MC/DC66%2/3
defined $bind and $drule->{"args"}[$i] ne "_" and not exists $dcon->{"pad"}{$drule->{"args"}[$i]}
defined $bind
$drule->{"args"}[$i] ne "_"
not exists $dcon->{"pad"}{$drule->{"args"}[$i]}
Truth table75%3/4
A and B and not(C)
A= defined $bindB= $drule->{"args"}[$i] ne "_"C= not exists $dcon->{"pad"}{$drule->{"args"}[$i]}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 251 | !exists $dcon->{pad}{$drule->{args}[$i]}) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 4 | $dcon->{pad}{$drule->{args}[$i]} = $bind; | |||||||||||||||||||||||||||||||||||||||||||||
| 253 | 4 | ▶ | $dcon->{stack}[0]{bindings} ||= [ ]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$dcon->{"stack"}[0]{"bindings"} ||= []
MC/DC100%1/1
$dcon->{"stack"}[0]{"bindings"} ||= []
$dcon->{"stack"}[0]{"bindings"}
Truth table100%2/2
A
A= $dcon->{"stack"}[0]{"bindings"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 3 | push @{$dcon->{stack}[0]{bindings}}, | |||||||||||||||||||||||||||||||||||||||||||||
| 255 | 4 | ▶ | $drule->{args}[$i] if $bindtrack; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 16 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||
| 262 | # Returns a context or undef | ||||||||||||||||||||||||||||||||||||||||||||||
| 263 | # Changes are reflected in the pad | ||||||||||||||||||||||||||||||||||||||||||||||
| 264 | sub match(\$$;$$) | ||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 17 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
match: called CC=60 SCAR=54.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 17 | my ($self, $proc, $state, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 17 | ▶ | $proc = $self->parse($proc) unless ref $proc; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 17 | my $cptr; # Pointer to frame of chain | |||||||||||||||||||||||||||||||||||||||||||||
| 271 | 17 | my $res = 0; # Did the last thing executed succeed (1,0)? | |||||||||||||||||||||||||||||||||||||||||||||
| 272 | 17 | my $dir = 1; # Are we going forward or backtracking (1,0)? | |||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 17 | ▶ | $state ||= { pad => {}, stack => [] }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$state ||= {"pad", {}, "stack", []}
MC/DC100%1/1
$state ||= {"pad", {}, "stack", []}
$state
Truth table100%2/2
A
A= $state
| |||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 17 | ▶ | return $state if $proc->{context} eq 'true'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 12 | ▶ | return undef if $proc->{context} eq 'false'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 12 | ▶ | if ($proc->{context} eq 'bind' && $proc->{code}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$proc->{"context"} eq "bind" and $proc->{"code"}
MC/DC50%1/2
$proc->{"context"} eq "bind" and $proc->{"code"}
$proc->{"context"} eq "bind"
$proc->{"code"}
Truth table66%2/3
A and B
A= $proc->{"context"} eq "bind"B= $proc->{"code"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 2 | ▶ | $state->{stack}[0]{bindings} ||= []; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$state->{"stack"}[0]{"bindings"} ||= []
MC/DC100%1/1
$state->{"stack"}[0]{"bindings"} ||= []
$state->{"stack"}[0]{"bindings"}
Truth table100%2/2
A
A= $state->{"stack"}[0]{"bindings"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 2 | delete $state->{pad}{$_} for @{$state->{stack}[0]{bindings}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 282 | 2 | @{$state->{stack}[0]{bindings}} = (); | |||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 2 | my @nt = grep { $self->{nonterm}($_) } @{$proc->{args}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 2 | ▶ | unless ($proc->{bindcode}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 1 | my $ev; | |||||||||||||||||||||||||||||||||||||||||||||
| 289 | 1 | $ev = "package main; no strict; my \%r;\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 290 | 1 | $ev .= 'my ($pad, $stack) = @_;'; | |||||||||||||||||||||||||||||||||||||||||||||
| 291 | $ev .= "local \$$_ = \$pad->{$_};" | ||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 1 | ."\$r{$_} = \$$_ =~ s/^'//;\n" for @nt; | |||||||||||||||||||||||||||||||||||||||||||||
| 293 | 1 | $ev .= <<'EOC'; | |||||||||||||||||||||||||||||||||||||||||||||
| 294 | local $track = !$stack->{track}; | ||||||||||||||||||||||||||||||||||||||||||||||
| 295 | $stack->{track} = 1; | ||||||||||||||||||||||||||||||||||||||||||||||
| 296 | $stack->{local} ||= { }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 297 | local $local = $stack->{local}; | ||||||||||||||||||||||||||||||||||||||||||||||
| 298 | my $res = $proc->{code}(); | ||||||||||||||||||||||||||||||||||||||||||||||
| 299 | EOC | ||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 1 | for (@nt) { | |||||||||||||||||||||||||||||||||||||||||||||
| 301 | 1 | $ev .= <<EOC; | |||||||||||||||||||||||||||||||||||||||||||||
| 302 | if (defined \$$_) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 303 | \$$_ = q{'}.\$$_ if \$r{$_} || \$$_ =~ /\\W/; | ||||||||||||||||||||||||||||||||||||||||||||||
| 304 | push \@{\$stack->{bindings}}, '$_' | ||||||||||||||||||||||||||||||||||||||||||||||
| 305 | unless exists \$pad->{$_}; | ||||||||||||||||||||||||||||||||||||||||||||||
| 306 | \$pad->{$_} = \$$_; | ||||||||||||||||||||||||||||||||||||||||||||||
| 307 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 308 | delete \$pad->{$_} | ||||||||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 310 | EOC | ||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 1 | $ev .= "\$res\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 313 | 1 | ▶ | $proc->{bindcode} = eval "sub { $ev }"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 1 | ▶ | confess $@ if $@; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 2 | $res = $proc->{bindcode}($state->{pad}, $state->{stack}[0]); | |||||||||||||||||||||||||||||||||||||||||||||
| 318 | 2 | ▶ | return $res ? $state : undef | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 10 | ▶ | if ($state->{stack}[0]{ptr}) { # Anything meaningful on the stack? | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 3 | ▶ | print "$indent Loading stack...\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 3 | delete $state->{pad}{$_} for @{$state->{stack}[0]{bindings}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 324 | 3 | @{$state->{stack}[0]{bindings}} = (); | |||||||||||||||||||||||||||||||||||||||||||||
| 325 | 3 | $cptr = $state->{stack}[0]{ptr}; | |||||||||||||||||||||||||||||||||||||||||||||
| 326 | 3 | $dir = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 328 | else { # Put something there | ||||||||||||||||||||||||||||||||||||||||||||||
| 329 | # $proc is the name of the rule; we want $proc->{next} | ||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 7 | $state->{stack}[0]{ptr} = $cptr = $proc->{next}; | |||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 10 | ▶ | while ($cptr) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 13 | $state->{stack}[0]{ptr} = $cptr; # Tell the stack where we are | |||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||
| 336 | # If we're backtracking, and we skipped on the forward, skip back too | ||||||||||||||||||||||||||||||||||||||||||||||
| 337 | goto skip if $cptr->{context} eq 'or' and $state->{stack}[0]{skip} | ||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 13 | ▶ | and not $dir; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$cptr->{"context"} eq "or" and $state->{"stack"}[0]{"skip"} and not $dir
$cptr->{"context"} eq "or" and $state->{"stack"}[0]{"skip"}
MC/DC0%0/3
$cptr->{"context"} eq "or" and $state->{"stack"}[0]{"skip"} and not $dir
$cptr->{"context"} eq "or"
$state->{"stack"}[0]{"skip"}
not $dir
Truth table25%1/4
A and B and not(C)
A= $cptr->{"context"} eq "or"B= $state->{"stack"}[0]{"skip"}C= not $dir
| |||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||
| 340 | goto skip if $cptr->{context} eq 'sub' | ||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 13 | ▶ | and not $dir and not $state->{stack}[0]{last}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$cptr->{"context"} eq "sub" and not $dir and not $state->{"stack"}[0]{"last"}
$cptr->{"context"} eq "sub" and not $dir
MC/DC0%0/3
$cptr->{"context"} eq "sub" and not $dir and not $state->{"stack"}[0]{"last"}
$cptr->{"context"} eq "sub"
not $dir
not $state->{"stack"}[0]{"last"}
Truth table25%1/4
A and not(B) and not(C)
A= $cptr->{"context"} eq "sub"B= not $dirC= not $state->{"stack"}[0]{"last"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 13 | ▶ | goto skip if $cptr->{context} eq 'sub' && not $res; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$cptr->{"context"} eq "sub" and not $res
MC/DC0%0/2
$cptr->{"context"} eq "sub" and not $res
$cptr->{"context"} eq "sub"
not $res
Truth table33%1/3
A and not(B)
A= $cptr->{"context"} eq "sub"B= not $res
| |||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||
| 344 | # On forward success in an or chain, skip the current rule | ||||||||||||||||||||||||||||||||||||||||||||||
| 345 | goto skip if $cptr->{context} eq 'or' and $res and $dir | ||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 13 | ▶ | and $state->{stack}[0]{skip} = 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition37%3/8
$cptr->{"context"} eq "or" and $res and $dir and $state->{"stack"}[0]{"skip"} = 1
$cptr->{"context"} eq "or" and $res and $dir
$cptr->{"context"} eq "or" and $res
MC/DC0%0/3
$cptr->{"context"} eq "or" and $res and $dir and $state->{"stack"}[0]{"skip"} = 1
$cptr->{"context"} eq "or"
$res
$dir
Truth table25%1/4
A and B and C
A= $cptr->{"context"} eq "or"B= $resC= $dir
| |||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 13 | $state->{stack}[0]{skip} = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||
| 350 | # In true context, just go forward | ||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 13 | ▶ | if ($cptr->{context} eq 'true') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | $res = $dir = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | goto retry; | |||||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||
| 356 | # In false context, just go backward (duh) | ||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 13 | ▶ | if ($cptr->{context} eq 'false') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | $res = $dir = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | goto retry; | |||||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||
| 362 | # If we don't have something to try, try to get something to try | ||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 13 | my $try = $state->{stack}[0]{rule}; | |||||||||||||||||||||||||||||||||||||||||||||
| 364 | 13 | my $frame = $state->{stack}[0]{frame}; | |||||||||||||||||||||||||||||||||||||||||||||
| 365 | 13 | ▶ | unless ($frame) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 366 | print "$indent Look: $cptr->{rule}(", | ||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | join(', ', map { "$_($state->{pad}{$_})" } @{$cptr->{args}}), | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 368 | ")\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 12 | $try = $self->lookup($cptr, $state->{stack}[0], $state->{pad}); | |||||||||||||||||||||||||||||||||||||||||||||
| 370 | # Fail entirely if we couldn't find anything new | ||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 12 | ▶ | unless ($try) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 5 | ▶ | print "$indent Lost\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 5 | $res = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 374 | 5 | goto retry; | |||||||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | ▶ | print "$indent Find: $try->{rule}(", join(', ', @{$try->{args}}), | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 377 | ")\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 7 | ▶ | if ($try->{context} eq 'bind') { # Only if it's complex | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 2 | $state->{stack}[0]{rule} = $try; | |||||||||||||||||||||||||||||||||||||||||||||
| 381 | 2 | $state->{stack}[0]{frame} = $frame = { stack => [], pad => {} }; | |||||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||
| 385 | # Give them variables they need and we have | ||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 8 | $self->copy_pad($cptr, $state => $try, $frame); | |||||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||||||
| 388 | print "$indent Try: $cptr->{rule}(", join(', ', | ||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | map { $_ . "($state->{pad}{$_})" } @{$cptr->{args}}), ")\n" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 390 | if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 8 | ▶ | unless ( $res = ! !$self->match($try, $frame, "$indent ") ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | ▶ | print "$indent Fail\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | undef $state->{stack}[0]{frame}; # Clear the frame | |||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | next; # Try again | |||||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 8 | ▶ | $dir = 1 if $res; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||||||
| 401 | # Get their variables if they bound any we want | ||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 8 | $self->copy_pad($try, $frame => $cptr, $state, 'bind'); | |||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||
| 404 | print "$indent Match: $cptr->{rule}(", join(', ', | ||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | ▶ | map { $_ . "($state->{pad}{$_})" } @{$cptr->{args}}), ")\n" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 406 | if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||
| 408 | retry: | ||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 13 | ▶ | if ($cptr->{context} eq 'sub') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | ▶ | if ($dir) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | ▶ | if ($res && $state->{stack}[1]{last}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$res and $state->{"stack"}[1]{"last"}
MC/DC0%0/2
$res and $state->{"stack"}[1]{"last"}
$res
$state->{"stack"}[1]{"last"}
Truth table0%0/3
A and B
A= $resB= $state->{"stack"}[1]{"last"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | $dir = $res = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 414 | elsif (!$state->{stack}[1]{last}) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | $dir = $res = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | ▶ | if ($cptr->{next} && | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$cptr->{"next"} and $cptr->{"next"}{"context"} eq "or" || $cptr->{"next"}{"context"} eq "sub"
$cptr->{"next"}{"context"} eq "or" or $cptr->{"next"}{"context"} eq "sub"
MC/DC0%0/3
$cptr->{"next"} and $cptr->{"next"}{"context"} eq "or" || $cptr->{"next"}{"context"} eq "sub"
$cptr->{"next"}
$cptr->{"next"}{"context"} eq "or"
$cptr->{"next"}{"context"} eq "sub"
Truth table0%0/4
A and B or C
A= $cptr->{"next"}B= $cptr->{"next"}{"context"} eq "or"C= $cptr->{"next"}{"context"} eq "sub"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 417 | ($cptr->{next}{context} eq 'or' | ||||||||||||||||||||||||||||||||||||||||||||||
| 418 | || $cptr->{next}{context} eq 'sub')) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | ▶ | $dir = 1 unless $state->{stack}[0]{fail} > 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 422 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | $dir = $res = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 427 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 13 | $dir = $res; | |||||||||||||||||||||||||||||||||||||||||||||
| 429 | 13 | ▶ | if ($cptr->{next} && | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$cptr->{"next"} and $cptr->{"next"}{"context"} eq "or" || $cptr->{"next"}{"context"} eq "sub"
$cptr->{"next"}{"context"} eq "or" or $cptr->{"next"}{"context"} eq "sub"
MC/DC0%0/3
$cptr->{"next"} and $cptr->{"next"}{"context"} eq "or" || $cptr->{"next"}{"context"} eq "sub"
$cptr->{"next"}
$cptr->{"next"}{"context"} eq "or"
$cptr->{"next"}{"context"} eq "sub"
Truth table50%2/4
A and B or C
A= $cptr->{"next"}B= $cptr->{"next"}{"context"} eq "or"C= $cptr->{"next"}{"context"} eq "sub"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 430 | ($cptr->{next}{context} eq 'or' | ||||||||||||||||||||||||||||||||||||||||||||||
| 431 | || $cptr->{next}{context} eq 'sub')) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | ▶ | $dir = 1 unless $state->{stack}[0]{fail} > 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||||||
| 436 | skip: | ||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 13 | ▶ | if ($dir) { # If we're going forward | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 8 | $state->{stack}[0]{last} = $res; | |||||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 8 | $cptr = $cptr->{next}; | |||||||||||||||||||||||||||||||||||||||||||||
| 441 | 8 | unshift @{$state->{stack}}, { }; # Establish new stack frame | |||||||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 443 | else { # We're going backward | ||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 5 | $cptr = $cptr->{fail}; | |||||||||||||||||||||||||||||||||||||||||||||
| 445 | 5 | for (@{$state->{stack}[0]{bind_stack}}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | delete $state->{pad}{$_}; | |||||||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 5 | @{$state->{stack}[0]{bind_stack}} = (); | |||||||||||||||||||||||||||||||||||||||||||||
| 449 | 5 | shift @{$state->{stack}}; # Clear the frame | |||||||||||||||||||||||||||||||||||||||||||||
| 450 | # Unbind any variables in the new frame | ||||||||||||||||||||||||||||||||||||||||||||||
| 451 | # in order to rebind them this run. | ||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 5 | delete $state->{pad}{$_} for @{$state->{stack}[0]{bindings}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 453 | 5 | @{$state->{stack}[0]{bindings}} = (); | |||||||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 10 | shift @{$state->{stack}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 458 | 10 | ▶ | $res ? $state : undef; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 4 | ▶ | sub get(\$$$) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 4 | my ($self, $iter, $sym) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 463 | 4 | ▶ | if (exists $iter->{pad}{$sym}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 4 | my $ret = $iter->{pad}{$sym}; | |||||||||||||||||||||||||||||||||||||||||||||
| 465 | 4 | $ret =~ s/^'//; | |||||||||||||||||||||||||||||||||||||||||||||
| 466 | 4 | $ret | |||||||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 468 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 469 | undef | ||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | } | |||||||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 1 | 1 | |||||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||||||
| 475 | __DATA__ | ||||||||||||||||||||||||||||||||||||||||||||||