| 1 | # Copyright © 2006, 2007, 2008, 2009, 2010, 2011, 2012 Casiano Rodriguez-Leon. | ||||||||||||||||||||||||||||
| 2 | # Copyright © 2017 William N. Braswell, Jr. | ||||||||||||||||||||||||||||
| 3 | # All Rights Reserved. | ||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||
| 5 | # Parse::Yapp is Copyright © 1998, 1999, 2000, 2001, Francois Desarmenien. | ||||||||||||||||||||||||||||
| 6 | # Parse::Yapp is Copyright © 2017 William N. Braswell, Jr. | ||||||||||||||||||||||||||||
| 7 | # All Rights Reserved. | ||||||||||||||||||||||||||||
| 8 | package Parse::Eyapp::Node; | ||||||||||||||||||||||||||||
| 9 | 64 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 64 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 64 | ▶ | no warnings 'recursion'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 64 | ▶ | use Parse::Eyapp::YATW; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 64 | ▶ | use List::Util qw(first); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 64 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 64 | our $FILENAME=__FILE__; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 2 | ▶ | sub firstval(&@) { | ||||||||||||||||||||||||||
|
Subroutine
firstval: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 20 | 2 | my $handler = shift; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 2 | return (grep { $handler->($_) } @_)[0] | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 7 | ▶ | sub lastval(&@) { | ||||||||||||||||||||||||||
|
Subroutine
lastval: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 26 | 7 | my $handler = shift; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 7 | return (grep { $handler->($_) } @_)[-1] | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | #################################################################### | ||||||||||||||||||||||||||||
| 32 | # Usage : | ||||||||||||||||||||||||||||
| 33 | # line: %name PROG | ||||||||||||||||||||||||||||
| 34 | # exp <%name EXP + ';'> | ||||||||||||||||||||||||||||
| 35 | # { @{$lhs->{t}} = map { $_->{t}} ($lhs->child(0)->children()); } | ||||||||||||||||||||||||||||
| 36 | # ; | ||||||||||||||||||||||||||||
| 37 | # Returns : The array of children of the node. When the tree is a | ||||||||||||||||||||||||||||
| 38 | # translation scheme the CODE references are also included | ||||||||||||||||||||||||||||
| 39 | # Parameters : the node (method) | ||||||||||||||||||||||||||||
| 40 | # See Also : Children | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 1963 | ▶ | sub children { | ||||||||||||||||||||||||||
|
Subroutine
children: called CC=3 SCAR=11.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 43 | 1963 | my $self = CORE::shift; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 1963 | ▶ | return () unless UNIVERSAL::can($self, 'children'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | @{$self->{children}} = @_ if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 1963 | @{$self->{children}} | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | #################################################################### | ||||||||||||||||||||||||||||
| 51 | # Usage : line: %name PROG | ||||||||||||||||||||||||||||
| 52 | # (exp) <%name EXP + ';'> | ||||||||||||||||||||||||||||
| 53 | # { @{$lhs->{t}} = map { $_->{t}} ($_[1]->Children()); } | ||||||||||||||||||||||||||||
| 54 | # | ||||||||||||||||||||||||||||
| 55 | # Returns : The true children of the node, excluding CODE CHILDREN | ||||||||||||||||||||||||||||
| 56 | # Parameters : The Node object | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 128 | ▶ | sub Children { | ||||||||||||||||||||||||||
|
Subroutine
Children: called CC=3 SCAR=11.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 59 | 128 | my $self = CORE::shift; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 128 | ▶ | return () unless UNIVERSAL::can($self, 'children'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | @{$self->{children}} = @_ if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 128 | grep { !UNIVERSAL::isa($_, 'CODE') } @{$self->{children}} | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | #################################################################### | ||||||||||||||||||||||||||||
| 68 | # Returns : Last non CODE child | ||||||||||||||||||||||||||||
| 69 | # Parameters : the node object | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 1 | ▶ | sub Last_child { | ||||||||||||||||||||||||||
|
Subroutine
Last_child: called CC=5 SCAR=18.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 72 | 1 | my $self = CORE::shift; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 1 | ▶ | return unless UNIVERSAL::can($self, 'children') and @{$self->{children}}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
UNIVERSAL::can($self, "children") and @{$self->{"children"};}
MC/DC0%0/2
UNIVERSAL::can($self, "children") and @{$self->{"children"};}
UNIVERSAL::can($self, "children")
@{$self->{"children"};}
Truth table33%1/3
A and B
A= UNIVERSAL::can($self, "children")B= @{$self->{"children"};}
| |||||||||||||||||||||||||||||
| 75 | 1 | my $i = -1; | |||||||||||||||||||||||||||
| 76 | 1 | ▶ | $i-- while defined($self->{children}->[$i]) and UNIVERSAL::isa($self->{children}->[$i], 'CODE'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->{"children"}[$i] and UNIVERSAL::isa($self->{"children"}[$i], "CODE")
MC/DC0%0/2
defined $self->{"children"}[$i] and UNIVERSAL::isa($self->{"children"}[$i], "CODE")
defined $self->{"children"}[$i]
UNIVERSAL::isa($self->{"children"}[$i], "CODE")
Truth table33%1/3
A and B
A= defined $self->{"children"}[$i]B= UNIVERSAL::isa($self->{"children"}[$i], "CODE")
| |||||||||||||||||||||||||||||
| 77 | 1 | return $self->{children}->[$i]; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | sub last_child { | ||||||||||||||||||||||||||
|
Subroutine
last_child: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 81 | 0 | my $self = CORE::shift; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | return unless UNIVERSAL::can($self, 'children') and @{$self->{children}}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
UNIVERSAL::can($self, "children") and @{$self->{"children"};}
MC/DC0%0/2
UNIVERSAL::can($self, "children") and @{$self->{"children"};}
UNIVERSAL::can($self, "children")
@{$self->{"children"};}
Truth table0%0/3
A and B
A= UNIVERSAL::can($self, "children")B= @{$self->{"children"};}
| |||||||||||||||||||||||||||||
| 84 | 0 | ${$self->{children}}[-1]; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | #################################################################### | ||||||||||||||||||||||||||||
| 88 | # Usage : $node->child($i) | ||||||||||||||||||||||||||||
| 89 | # my $transform = Parse::Eyapp::Treeregexp->new( STRING => q{ | ||||||||||||||||||||||||||||
| 90 | # commutative_add: PLUS($x, ., $y, .) | ||||||||||||||||||||||||||||
| 91 | # => { my $t = $x; $_[0]->child(0, $y); $_[0]->child(2, $t)} | ||||||||||||||||||||||||||||
| 92 | # } | ||||||||||||||||||||||||||||
| 93 | # Purpose : Setter-getter to modify a specific child of a node | ||||||||||||||||||||||||||||
| 94 | # Returns : Child with index $i. Returns undef if the child does not exists | ||||||||||||||||||||||||||||
| 95 | # Parameters : Method: the node and the index of the child. The new value is used | ||||||||||||||||||||||||||||
| 96 | # as a setter. | ||||||||||||||||||||||||||||
| 97 | # Throws : Croaks if the index parameter is not provided | ||||||||||||||||||||||||||||
| 98 | 1291 | ▶ | sub child { | ||||||||||||||||||||||||||
|
Subroutine
child: called CC=4 SCAR=14.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 99 | 1291 | my ($self, $index, $value) = @_; | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | #croak "$self is not a Parse::Eyapp::Node" unless $self->isa('Parse::Eyapp::Node'); | ||||||||||||||||||||||||||||
| 102 | 1291 | ▶ | return undef unless UNIVERSAL::can($self, 'child'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 1291 | ▶ | croak "Index not provided" unless defined($index); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 1291 | ▶ | $self->{children}[$index] = $value if defined($value); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 1291 | $self->{children}[$index]; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | ▶ | sub descendant { | ||||||||||||||||||||||||||
|
Subroutine
descendant: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 109 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 110 | 0 | my $coord = shift; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | my @pos = split /\./, $coord; | |||||||||||||||||||||||||||
| 113 | 0 | my $t = $self; | |||||||||||||||||||||||||||
| 114 | 0 | my $x = shift(@pos); # discard the first empty dot | |||||||||||||||||||||||||||
| 115 | 0 | for (@pos) { | |||||||||||||||||||||||||||
| 116 | 0 | ▶ | croak "Error computing descendant: $_ is not a number\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
/\d+/ and $_ < $t->children
MC/DC0%0/2
/\d+/ and $_ < $t->children
/\d+/
$_ < $t->children
Truth table0%0/3
A and B
A= /\d+/B= $_ < $t->children
| |||||||||||||||||||||||||||||
| 117 | unless m{\d+} and $_ < $t->children; | ||||||||||||||||||||||||||||
| 118 | 0 | $t = $t->child($_); | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | 0 | return $t; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | #################################################################### | ||||||||||||||||||||||||||||
| 124 | # Usage : $node->s(@transformationlist); | ||||||||||||||||||||||||||||
| 125 | # Example : The following example simplifies arithmetic expressions | ||||||||||||||||||||||||||||
| 126 | # using method "s": | ||||||||||||||||||||||||||||
| 127 | # > cat Timeszero.trg | ||||||||||||||||||||||||||||
| 128 | # /* Operator "and" has higher priority than comma "," */ | ||||||||||||||||||||||||||||
| 129 | # whatever_times_zero: TIMES(@b, NUM($x) and { $x->{attr} == 0 }) => { $_[0] = $NUM } | ||||||||||||||||||||||||||||
| 130 | # | ||||||||||||||||||||||||||||
| 131 | # > treereg Timeszero | ||||||||||||||||||||||||||||
| 132 | # > cat arrays.pl | ||||||||||||||||||||||||||||
| 133 | # !/usr/bin/perl -w | ||||||||||||||||||||||||||||
| 134 | # use strict; | ||||||||||||||||||||||||||||
| 135 | # use Rule6; | ||||||||||||||||||||||||||||
| 136 | # use Parse::Eyapp::Treeregexp; | ||||||||||||||||||||||||||||
| 137 | # use Timeszero; | ||||||||||||||||||||||||||||
| 138 | # | ||||||||||||||||||||||||||||
| 139 | # my $parser = new Rule6(); | ||||||||||||||||||||||||||||
| 140 | # my $t = $parser->Run; | ||||||||||||||||||||||||||||
| 141 | # $t->s(@Timeszero::all); | ||||||||||||||||||||||||||||
| 142 | # | ||||||||||||||||||||||||||||
| 143 | # | ||||||||||||||||||||||||||||
| 144 | # Returns : Nothing | ||||||||||||||||||||||||||||
| 145 | # Parameters : The object (is a method) and the list of transformations to apply. | ||||||||||||||||||||||||||||
| 146 | # The list may be a list of Parse::Eyapp:YATW objects and/or CODE | ||||||||||||||||||||||||||||
| 147 | # references | ||||||||||||||||||||||||||||
| 148 | # Throws : No exceptions | ||||||||||||||||||||||||||||
| 149 | # Comments : The set of transformations is repeatedly applied to the node | ||||||||||||||||||||||||||||
| 150 | # until there are no changes. | ||||||||||||||||||||||||||||
| 151 | # The function may hang if the set of transformations | ||||||||||||||||||||||||||||
| 152 | # matches forever. | ||||||||||||||||||||||||||||
| 153 | # See Also : The "s" method for Parse::Eyapp::YATW objects | ||||||||||||||||||||||||||||
| 154 | # (i.e. transformation objects) | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 24 | ▶ | sub s { | ||||||||||||||||||||||||||
|
Subroutine
s: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 157 | 24 | my @patterns = @_[1..$#_]; | |||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | # Make them Parse::Eyapp:YATW objects if they are CODE references | ||||||||||||||||||||||||||||
| 160 | 24 | ▶ | @patterns = map { ref($_) eq 'CODE'? | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | Parse::Eyapp::YATW->new( | ||||||||||||||||||||||||||||
| 162 | PATTERN => $_, | ||||||||||||||||||||||||||||
| 163 | #PATTERN_ARGS => [], | ||||||||||||||||||||||||||||
| 164 | ) | ||||||||||||||||||||||||||||
| 165 | : | ||||||||||||||||||||||||||||
| 166 | $_ | ||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | @patterns; | ||||||||||||||||||||||||||||
| 169 | 24 | my $changes; | |||||||||||||||||||||||||||
| 170 | 24 | ▶ | do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | 50 | $changes = 0; | |||||||||||||||||||||||||||
| 172 | 50 | foreach (@patterns) { | |||||||||||||||||||||||||||
| 173 | 87 | $_->{CHANGES} = 0; | |||||||||||||||||||||||||||
| 174 | 87 | $_->s($_[0]); | |||||||||||||||||||||||||||
| 175 | 87 | $changes += $_->{CHANGES}; | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | } while ($changes); | ||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | #################################################################### | ||||||||||||||||||||||||||||
| 182 | # Usage : ???? | ||||||||||||||||||||||||||||
| 183 | # Purpose : bud = Bottom Up Decoration: Decorates the tree with flowers :-) | ||||||||||||||||||||||||||||
| 184 | # The purpose is to decorate the AST with attributes during | ||||||||||||||||||||||||||||
| 185 | # the context-dependent analysis, mainly type-checking. | ||||||||||||||||||||||||||||
| 186 | # Returns : ???? | ||||||||||||||||||||||||||||
| 187 | # Parameters : The transformations. | ||||||||||||||||||||||||||||
| 188 | # Throws : no exceptions | ||||||||||||||||||||||||||||
| 189 | # Comments : The tree is traversed bottom-up. The set of | ||||||||||||||||||||||||||||
| 190 | # transformations is applied to each node in the order | ||||||||||||||||||||||||||||
| 191 | # supplied by the user. As soon as one succeeds | ||||||||||||||||||||||||||||
| 192 | # no more transformations are applied. | ||||||||||||||||||||||||||||
| 193 | # See Also : n/a | ||||||||||||||||||||||||||||
| 194 | # To Do : Avoid closure. Save @patterns inside the object | ||||||||||||||||||||||||||||
| 195 | { | ||||||||||||||||||||||||||||
| 196 | 64 | my @patterns; | |||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 0 | ▶ | sub bud { | ||||||||||||||||||||||||||
|
Subroutine
bud: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 199 | 0 | @patterns = @_[1..$#_]; | |||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 0 | ▶ | @patterns = map { ref($_) eq 'CODE'? | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 202 | Parse::Eyapp::YATW->new( | ||||||||||||||||||||||||||||
| 203 | PATTERN => $_, | ||||||||||||||||||||||||||||
| 204 | #PATTERN_ARGS => [], | ||||||||||||||||||||||||||||
| 205 | ) | ||||||||||||||||||||||||||||
| 206 | : | ||||||||||||||||||||||||||||
| 207 | $_ | ||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | @patterns; | ||||||||||||||||||||||||||||
| 210 | 0 | _bud($_[0], undef, undef); | |||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 0 | ▶ | sub _bud { | ||||||||||||||||||||||||||
|
Subroutine
_bud: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||
| 214 | 0 | my $node = $_[0]; | |||||||||||||||||||||||||||
| 215 | 0 | my $index = $_[2]; | |||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | # Is an odd leaf. Not actually a Parse::Eyapp::Node. Decorate it and leave | ||||||||||||||||||||||||||||
| 218 | 0 | ▶ | if (!ref($node) or !UNIVERSAL::can($node, "children")) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $node and UNIVERSAL::can($node, "children")
MC/DC0%0/2
ref $node and UNIVERSAL::can($node, "children")
ref $node
UNIVERSAL::can($node, "children")
Truth table0%0/3
A and B
A= ref $nodeB= UNIVERSAL::can($node, "children")
| |||||||||||||||||||||||||||||
| 219 | 0 | for my $p (@patterns) { | |||||||||||||||||||||||||||
| 220 | 0 | ▶ | return if $p->pattern->( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 221 | $_[0], # Node being visited | ||||||||||||||||||||||||||||
| 222 | $_[1], # Father of this node | ||||||||||||||||||||||||||||
| 223 | $index, # Index of this node in @Father->children | ||||||||||||||||||||||||||||
| 224 | $p, # The YATW pattern object | ||||||||||||||||||||||||||||
| 225 | ); | ||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | }; | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | # Recursively decorate subtrees | ||||||||||||||||||||||||||||
| 230 | 0 | my $i = 0; | |||||||||||||||||||||||||||
| 231 | 0 | for (@{$node->{children}}) { | |||||||||||||||||||||||||||
| 232 | 0 | $_->_bud($_, $_[0], $i); | |||||||||||||||||||||||||||
| 233 | 0 | $i++; | |||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | # Decorate the node | ||||||||||||||||||||||||||||
| 237 | #Change YATW object to be the first argument? | ||||||||||||||||||||||||||||
| 238 | 0 | for my $p (@patterns) { | |||||||||||||||||||||||||||
| 239 | 0 | ▶ | return if $p->pattern->($_[0], $_[1], $index, $p); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||
| 242 | } # closure for @patterns | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | #################################################################### | ||||||||||||||||||||||||||||
| 245 | # Usage : | ||||||||||||||||||||||||||||
| 246 | # @t = Parse::Eyapp::Node->new( q{TIMES(NUM(TERMINAL), NUM(TERMINAL))}, | ||||||||||||||||||||||||||||
| 247 | # sub { | ||||||||||||||||||||||||||||
| 248 | # our ($TIMES, @NUM, @TERMINAL); | ||||||||||||||||||||||||||||
| 249 | # $TIMES->{type} = "binary operation"; | ||||||||||||||||||||||||||||
| 250 | # $NUM[0]->{type} = "int"; | ||||||||||||||||||||||||||||
| 251 | # $NUM[1]->{type} = "float"; | ||||||||||||||||||||||||||||
| 252 | # $TERMINAL[1]->{attr} = 3.5; | ||||||||||||||||||||||||||||
| 253 | # }, | ||||||||||||||||||||||||||||
| 254 | # ); | ||||||||||||||||||||||||||||
| 255 | # Purpose : Multi-Constructor | ||||||||||||||||||||||||||||
| 256 | # Returns : Array of pointers to the objects created | ||||||||||||||||||||||||||||
| 257 | # in scalar context a pointer to the first node | ||||||||||||||||||||||||||||
| 258 | # Parameters : The class plus the string description and attribute handler | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | { | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | 64 | my %cache; | |||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | 0 | ▶ | sub m_bless { | ||||||||||||||||||||||||||
|
Subroutine
m_bless: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | 0 | my $key = join "",@_; | |||||||||||||||||||||||||||
| 267 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 268 | 0 | ▶ | return $cache{$key} if exists $cache{$key}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | 0 | my $b = bless { children => \@_}, $class; | |||||||||||||||||||||||||||
| 271 | 0 | $cache{$key} = $b; | |||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | 0 | return $b; | |||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | 64 | ▶ | sub _bless { | ||||||||||||||||||||||||||
|
Subroutine
_bless: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 278 | 152 | my $class = shift; | |||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | 152 | my $b = bless { children => \@_ }, $class; | |||||||||||||||||||||||||||
| 281 | 152 | return $b; | |||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | 0 | ▶ | sub hexpand { | ||||||||||||||||||||||||||
|
Subroutine
hexpand: not called CC=5 SCAR=30.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 285 | 0 | my $class = CORE::shift; | |||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | 0 | ▶ | my $handler = CORE::pop if ref($_[-1]) eq 'CODE'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 288 | 0 | my $n = m_bless(@_); | |||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | 0 | my $newnodeclass = CORE::shift; | |||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | 64 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 293 | 0 | ▶ | push @{$newnodeclass."::ISA"}, 'Parse::Eyapp::Node' unless $newnodeclass->isa('Parse::Eyapp::Node'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | 0 | ▶ | if (defined($handler) and UNIVERSAL::isa($handler, "CODE")) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $handler and UNIVERSAL::isa($handler, "CODE")
MC/DC0%0/2
defined $handler and UNIVERSAL::isa($handler, "CODE")
defined $handler
UNIVERSAL::isa($handler, "CODE")
Truth table0%0/3
A and B
A= defined $handlerB= UNIVERSAL::isa($handler, "CODE")
| |||||||||||||||||||||||||||||
| 296 | 0 | $handler->($n); | |||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | 0 | $n; | |||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | 0 | ▶ | sub hnew { | ||||||||||||||||||||||||||
|
Subroutine
hnew: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 303 | 0 | my $blesser = \&m_bless; | |||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | 0 | return _new($blesser, @_); | |||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | # Regexp for a full Perl identifier | ||||||||||||||||||||||||||||
| 309 | 61 | ▶ | sub _new { | ||||||||||||||||||||||||||
|
Subroutine
_new: called CC=21 SCAR=30.7
| |||||||||||||||||||||||||||||
| 310 | 61 | my $blesser = CORE::shift; | |||||||||||||||||||||||||||
| 311 | 61 | my $class = CORE::shift; | |||||||||||||||||||||||||||
| 312 | 61 | local $_ = CORE::shift; # string: tree description | |||||||||||||||||||||||||||
| 313 | 61 | ▶ | my $handler = CORE::shift if ref($_[0]) eq 'CODE'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | 61 | my %classes; | |||||||||||||||||||||||||||
| 317 | my $b; | ||||||||||||||||||||||||||||
| 318 | #TODO: Shall I receive a prefix? | ||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | 61 | my (@stack, @index, @results, %results, @place, $open); | |||||||||||||||||||||||||||
| 321 | #skip white spaces | ||||||||||||||||||||||||||||
| 322 | 61 | s{\A\s+}{}; | |||||||||||||||||||||||||||
| 323 | 61 | ▶ | while ($_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 324 | # If is a leaf is followed by parenthesis or comma or an ID | ||||||||||||||||||||||||||||
| 325 | s{\A([A-Za-z_][A-Za-z0-9_:]*)\s*([),])} | ||||||||||||||||||||||||||||
| 326 | {$1()$2} # ... then add an empty pair of parenthesis | ||||||||||||||||||||||||||||
| 327 | 551 | ▶ | and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 328 | 51 | next; | |||||||||||||||||||||||||||
| 329 | }; | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | # If is a leaf is followed by an ID | ||||||||||||||||||||||||||||
| 332 | s{\A([A-Za-z_][A-Za-z0-9_:]*)\s+([A-Za-z_])} | ||||||||||||||||||||||||||||
| 333 | {$1()$2} # ... then add an empty pair of parenthesis | ||||||||||||||||||||||||||||
| 334 | 500 | ▶ | and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 335 | 0 | next; | |||||||||||||||||||||||||||
| 336 | }; | ||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | # If is a leaf at the end | ||||||||||||||||||||||||||||
| 339 | s{\A([A-Za-z_][A-Za-z0-9_:]*)\s*$} | ||||||||||||||||||||||||||||
| 340 | {$1()} # ... then add an empty pair of parenthesis | ||||||||||||||||||||||||||||
| 341 | 500 | ▶ | and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 342 | 18 | $classes{$1} = 1; | |||||||||||||||||||||||||||
| 343 | 18 | next; | |||||||||||||||||||||||||||
| 344 | }; | ||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | # Is an identifier | ||||||||||||||||||||||||||||
| 347 | s{\A([A-Za-z_][A-Za-z0-9_:]*)}{} | ||||||||||||||||||||||||||||
| 348 | 482 | ▶ | and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 349 | 152 | $classes{$1} = 1; | |||||||||||||||||||||||||||
| 350 | 152 | CORE::push @stack, $1; | |||||||||||||||||||||||||||
| 351 | 152 | next; | |||||||||||||||||||||||||||
| 352 | }; | ||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | # Open parenthesis: mark the position for when parenthesis closes | ||||||||||||||||||||||||||||
| 355 | s{\A[(]}{} | ||||||||||||||||||||||||||||
| 356 | 330 | ▶ | and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 357 | 152 | my $pos = scalar(@stack); | |||||||||||||||||||||||||||
| 358 | 152 | CORE::push @index, $pos; | |||||||||||||||||||||||||||
| 359 | 152 | $place[$pos] = $open++; | |||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | # Warning! I don't know what I am doing | ||||||||||||||||||||||||||||
| 362 | 152 | next; | |||||||||||||||||||||||||||
| 363 | }; | ||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | # Skip commas | ||||||||||||||||||||||||||||
| 366 | 178 | ▶ | s{\A,}{} and next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | # Closing parenthesis: time to build a node | ||||||||||||||||||||||||||||
| 369 | 163 | ▶ | s{\A[)]}{} and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 370 | 152 | ▶ | croak "Syntax error! Closing parenthesis has no left partner!" unless @index; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 371 | 152 | my $begin = pop @index; # check if empty! | |||||||||||||||||||||||||||
| 372 | 152 | my @children = splice(@stack, $begin); | |||||||||||||||||||||||||||
| 373 | 152 | my $class = pop @stack; | |||||||||||||||||||||||||||
| 374 | 152 | ▶ | croak "Syntax error! Any couple of parenthesis must be preceded by an identifier" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $class and $class =~ /^[a-zA-Z_][\w:]*$/
MC/DC0%0/2
defined $class and $class =~ /^[a-zA-Z_][\w:]*$/
defined $class
$class =~ /^[a-zA-Z_][\w:]*$/
Truth table33%1/3
A and B
A= defined $classB= $class =~ /^[a-zA-Z_][\w:]*$/
| |||||||||||||||||||||||||||||
| 375 | unless (defined($class) and $class =~ m{^[a-zA-Z_][\w:]*$}); | ||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||
| 377 | 152 | $b = $blesser->($class, @children); | |||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||
| 379 | 152 | CORE::push @stack, $b; | |||||||||||||||||||||||||||
| 380 | 152 | $results[$place[$begin]] = $b; | |||||||||||||||||||||||||||
| 381 | 152 | CORE::push @{$results{$class}}, $b; | |||||||||||||||||||||||||||
| 382 | 152 | next; | |||||||||||||||||||||||||||
| 383 | }; | ||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | 11 | ▶ | last unless $_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | #skip white spaces | ||||||||||||||||||||||||||||
| 388 | 11 | ▶ | croak "Error building Parse::Eyapp::Node tree at '$_'." unless s{\A\s+}{}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 389 | } # while | ||||||||||||||||||||||||||||
| 390 | 61 | ▶ | croak "Syntax error! Open parenthesis has no right partner!" if @index; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 391 | { | ||||||||||||||||||||||||||||
| 392 | 64 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 393 | 61 | for (keys(%classes)) { | |||||||||||||||||||||||||||
| 394 | 144 | ▶ | push @{$_."::ISA"}, 'Parse::Eyapp::Node' unless $_->isa('Parse::Eyapp::Node'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||
| 397 | 61 | ▶ | if (defined($handler) and UNIVERSAL::isa($handler, "CODE")) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $handler and UNIVERSAL::isa($handler, "CODE")
MC/DC50%1/2
defined $handler and UNIVERSAL::isa($handler, "CODE")
defined $handler
UNIVERSAL::isa($handler, "CODE")
Truth table66%2/3
A and B
A= defined $handlerB= UNIVERSAL::isa($handler, "CODE")
| |||||||||||||||||||||||||||||
| 398 | 10 | $handler->(@results); | |||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||
| 400 | 61 | ▶ | return wantarray? @results : $b; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||
| 403 | 61 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 404 | 61 | my $blesser = \&_bless; | |||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||
| 406 | 61 | _new($blesser, @_); | |||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||
| 409 | ## Used by _subtree_list | ||||||||||||||||||||||||||||
| 410 | #sub compute_hierarchy { | ||||||||||||||||||||||||||||
| 411 | # my @results = @{shift()}; | ||||||||||||||||||||||||||||
| 412 | # | ||||||||||||||||||||||||||||
| 413 | # # Compute the hierarchy | ||||||||||||||||||||||||||||
| 414 | # my $b; | ||||||||||||||||||||||||||||
| 415 | # my @r = @results; | ||||||||||||||||||||||||||||
| 416 | # while (@results) { | ||||||||||||||||||||||||||||
| 417 | # $b = pop @results; | ||||||||||||||||||||||||||||
| 418 | # my $d = $b->{depth}; | ||||||||||||||||||||||||||||
| 419 | # my $f = lastval { $_->{depth} < $d} @results; | ||||||||||||||||||||||||||||
| 420 | # | ||||||||||||||||||||||||||||
| 421 | # $b->{father} = $f; | ||||||||||||||||||||||||||||
| 422 | # $b->{children} = []; | ||||||||||||||||||||||||||||
| 423 | # unshift @{$f->{children}}, $b; | ||||||||||||||||||||||||||||
| 424 | # } | ||||||||||||||||||||||||||||
| 425 | # $_->{father} = undef for @results; | ||||||||||||||||||||||||||||
| 426 | # bless $_, "Parse::Eyapp::Node::Match" for @r; | ||||||||||||||||||||||||||||
| 427 | # return @r; | ||||||||||||||||||||||||||||
| 428 | #} | ||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||
| 430 | # Matches | ||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||
| 432 | 3 | ▶ | sub m { | ||||||||||||||||||||||||||
|
Subroutine
m: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 433 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 434 | 3 | ▶ | my @patterns = @_ or croak "Expected a pattern!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 435 | croak "Error in method m of Parse::Eyapp::Node. Expected Parse::Eyapp:YATW patterns" | ||||||||||||||||||||||||||||
| 436 | 3 | ▶ | unless $a = first { !UNIVERSAL::isa($_, "Parse::Eyapp:YATW") } @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||
| 438 | # array context: return all matches | ||||||||||||||||||||||||||||
| 439 | 3 | local $a = 0; | |||||||||||||||||||||||||||
| 440 | 3 | my %index = map { ("$_", $a++) } @patterns; | |||||||||||||||||||||||||||
| 441 | 3 | my @stack = ( | |||||||||||||||||||||||||||
| 442 | Parse::Eyapp::Node::Match->new( | ||||||||||||||||||||||||||||
| 443 | node => $self, | ||||||||||||||||||||||||||||
| 444 | depth => 0, | ||||||||||||||||||||||||||||
| 445 | dewey => "", | ||||||||||||||||||||||||||||
| 446 | patterns =>[] | ||||||||||||||||||||||||||||
| 447 | ) | ||||||||||||||||||||||||||||
| 448 | ); | ||||||||||||||||||||||||||||
| 449 | 3 | my @results; | |||||||||||||||||||||||||||
| 450 | 3 | ▶ | do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 451 | 27 | my $mn = CORE::shift(@stack); | |||||||||||||||||||||||||||
| 452 | 27 | my %n = %$mn; | |||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||
| 454 | # See what patterns do match the current $node | ||||||||||||||||||||||||||||
| 455 | 27 | for my $pattern (@patterns) { | |||||||||||||||||||||||||||
| 456 | 81 | ▶ | push @{$mn->{patterns}}, $index{$pattern} if $pattern->{PATTERN}($n{node}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||
| 458 | 27 | my $dewey = $n{dewey}; | |||||||||||||||||||||||||||
| 459 | 27 | ▶ | if (@{$mn->{patterns}}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 460 | 7 | $mn->{family} = \@patterns; | |||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||
| 462 | # Is at this time that I have to compute the father | ||||||||||||||||||||||||||||
| 463 | 7 | ▶ | my $f = lastval { $dewey =~ m{^$_->{dewey}}} @results; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 464 | 7 | $mn->{father} = $f; | |||||||||||||||||||||||||||
| 465 | # ... and children | ||||||||||||||||||||||||||||
| 466 | 7 | ▶ | push @{$f->{children}}, $mn if defined($f); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 467 | 7 | CORE::push @results, $mn; | |||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||
| 469 | 27 | my $childdepth = $n{depth}+1; | |||||||||||||||||||||||||||
| 470 | 27 | my $k = -1; | |||||||||||||||||||||||||||
| 471 | CORE::unshift @stack, | ||||||||||||||||||||||||||||
| 472 | map | ||||||||||||||||||||||||||||
| 473 | { | ||||||||||||||||||||||||||||
| 474 | 24 | $k++; | |||||||||||||||||||||||||||
| 475 | 24 | Parse::Eyapp::Node::Match->new( | |||||||||||||||||||||||||||
| 476 | node => $_, | ||||||||||||||||||||||||||||
| 477 | depth => $childdepth, | ||||||||||||||||||||||||||||
| 478 | dewey => "$dewey.$k", | ||||||||||||||||||||||||||||
| 479 | patterns => [] | ||||||||||||||||||||||||||||
| 480 | ) | ||||||||||||||||||||||||||||
| 481 | 27 | } $n{node}->children(); | |||||||||||||||||||||||||||
| 482 | } while (@stack); | ||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||
| 484 | 3 | ▶ | wantarray? @results : $results[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||
| 487 | #sub _subtree_scalar { | ||||||||||||||||||||||||||||
| 488 | # # scalar context: return iterator | ||||||||||||||||||||||||||||
| 489 | # my $self = CORE::shift; | ||||||||||||||||||||||||||||
| 490 | # my @patterns = @_ or croak "Expected a pattern!"; | ||||||||||||||||||||||||||||
| 491 | # | ||||||||||||||||||||||||||||
| 492 | # # %index gives the index of $p in @patterns | ||||||||||||||||||||||||||||
| 493 | # local $a = 0; | ||||||||||||||||||||||||||||
| 494 | # my %index = map { ("$_", $a++) } @patterns; | ||||||||||||||||||||||||||||
| 495 | # | ||||||||||||||||||||||||||||
| 496 | # my @stack = (); | ||||||||||||||||||||||||||||
| 497 | # my $mn = { node => $self, depth => 0, patterns =>[] }; | ||||||||||||||||||||||||||||
| 498 | # my @results = (); | ||||||||||||||||||||||||||||
| 499 | # | ||||||||||||||||||||||||||||
| 500 | # return sub { | ||||||||||||||||||||||||||||
| 501 | # do { | ||||||||||||||||||||||||||||
| 502 | # # See if current $node matches some patterns | ||||||||||||||||||||||||||||
| 503 | # my $d = $mn->{depth}; | ||||||||||||||||||||||||||||
| 504 | # my $childdepth = $d+1; | ||||||||||||||||||||||||||||
| 505 | # # See what patterns do match the current $node | ||||||||||||||||||||||||||||
| 506 | # for my $pattern (@patterns) { | ||||||||||||||||||||||||||||
| 507 | # push @{$mn->{patterns}}, $index{$pattern} if $pattern->{PATTERN}($mn->{node}); | ||||||||||||||||||||||||||||
| 508 | # } | ||||||||||||||||||||||||||||
| 509 | # | ||||||||||||||||||||||||||||
| 510 | # if (@{$mn->{patterns}}) { # matched | ||||||||||||||||||||||||||||
| 511 | # CORE::push @results, $mn; | ||||||||||||||||||||||||||||
| 512 | # | ||||||||||||||||||||||||||||
| 513 | # # Compute the hierarchy | ||||||||||||||||||||||||||||
| 514 | # my $f = lastval { $_->{depth} < $d} @results; | ||||||||||||||||||||||||||||
| 515 | # $mn->{father} = $f; | ||||||||||||||||||||||||||||
| 516 | # $mn->{children} = []; | ||||||||||||||||||||||||||||
| 517 | # $mn->{family} = \@patterns; | ||||||||||||||||||||||||||||
| 518 | # unshift @{$f->{children}}, $mn if defined($f); | ||||||||||||||||||||||||||||
| 519 | # bless $mn, "Parse::Eyapp::Node::Match"; | ||||||||||||||||||||||||||||
| 520 | # | ||||||||||||||||||||||||||||
| 521 | # # push children in the stack | ||||||||||||||||||||||||||||
| 522 | # CORE::unshift @stack, | ||||||||||||||||||||||||||||
| 523 | # map { { node => $_, depth => $childdepth, patterns => [] } } | ||||||||||||||||||||||||||||
| 524 | # $mn->{node}->children(); | ||||||||||||||||||||||||||||
| 525 | # $mn = CORE::shift(@stack); | ||||||||||||||||||||||||||||
| 526 | # return $results[-1]; | ||||||||||||||||||||||||||||
| 527 | # } | ||||||||||||||||||||||||||||
| 528 | # # didn't match: push children in the stack | ||||||||||||||||||||||||||||
| 529 | # CORE::unshift @stack, | ||||||||||||||||||||||||||||
| 530 | # map { { node => $_, depth => $childdepth, patterns => [] } } | ||||||||||||||||||||||||||||
| 531 | # $mn->{node}->children(); | ||||||||||||||||||||||||||||
| 532 | # $mn = CORE::shift(@stack); | ||||||||||||||||||||||||||||
| 533 | # } while ($mn); # May be the stack is empty now, but if $mn then there is a node to process | ||||||||||||||||||||||||||||
| 534 | # # reset iterator | ||||||||||||||||||||||||||||
| 535 | # my @stack = (); | ||||||||||||||||||||||||||||
| 536 | # my $mn = { node => $self, depth => 0, patterns =>[] }; | ||||||||||||||||||||||||||||
| 537 | # return undef; | ||||||||||||||||||||||||||||
| 538 | # }; | ||||||||||||||||||||||||||||
| 539 | #} | ||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||
| 541 | # Factorize this!!!!!!!!!!!!!! | ||||||||||||||||||||||||||||
| 542 | #sub m { | ||||||||||||||||||||||||||||
| 543 | # goto &_subtree_list if (wantarray()); | ||||||||||||||||||||||||||||
| 544 | # goto &_subtree_scalar; | ||||||||||||||||||||||||||||
| 545 | #} | ||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||
| 547 | #################################################################### | ||||||||||||||||||||||||||||
| 548 | # Usage : $BLOCK->delete($ASSIGN) | ||||||||||||||||||||||||||||
| 549 | # $BLOCK->delete(2) | ||||||||||||||||||||||||||||
| 550 | # Purpose : deletes the specified child of the node | ||||||||||||||||||||||||||||
| 551 | # Returns : The deleted child | ||||||||||||||||||||||||||||
| 552 | # Parameters : The object plus the index or pointer to the child to be deleted | ||||||||||||||||||||||||||||
| 553 | # Throws : If the object can't do children or has no children | ||||||||||||||||||||||||||||
| 554 | # See Also : n/a | ||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||
| 556 | 3 | ▶ | sub delete { | ||||||||||||||||||||||||||
|
Subroutine
delete: called CC=9 SCAR=29.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 557 | 3 | my $self = CORE::shift; # The tree object | |||||||||||||||||||||||||||
| 558 | 3 | my $child = CORE::shift; # index or pointer | |||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||
| 560 | 3 | ▶ | croak "Parse::Eyapp::Node::delete error, node:\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
UNIVERSAL::can($self, "children") and $self->children > 0
MC/DC0%0/2
UNIVERSAL::can($self, "children") and $self->children > 0
UNIVERSAL::can($self, "children")
$self->children > 0
Truth table33%1/3
A and B
A= UNIVERSAL::can($self, "children")B= $self->children > 0
| |||||||||||||||||||||||||||||
| 561 | .Parse::Eyapp::Node::str($self)."\ndoes not have children" | ||||||||||||||||||||||||||||
| 562 | unless UNIVERSAL::can($self, 'children') and ($self->children()>0); | ||||||||||||||||||||||||||||
| 563 | 3 | ▶ | if (ref($child)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 564 | 3 | my $i = 0; | |||||||||||||||||||||||||||
| 565 | 3 | for ($self->children()) { | |||||||||||||||||||||||||||
| 566 | 6 | ▶ | last if $_ == $child; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 567 | 3 | $i++; | |||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||
| 569 | 3 | ▶ | if ($i == $self->children()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 570 | 0 | warn "Parse::Eyapp::Node::delete warning: node:\n".Parse::Eyapp::Node::str($self) | |||||||||||||||||||||||||||
| 571 | ."\ndoes not have a child like:\n" | ||||||||||||||||||||||||||||
| 572 | .Parse::Eyapp::Node::str($child) | ||||||||||||||||||||||||||||
| 573 | ."\nThe node was not deleted!\n"; | ||||||||||||||||||||||||||||
| 574 | 0 | return $child; | |||||||||||||||||||||||||||
| 575 | } | ||||||||||||||||||||||||||||
| 576 | 3 | splice(@{$self->{children}}, $i, 1); | |||||||||||||||||||||||||||
| 577 | 3 | return $child; | |||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||
| 579 | 0 | my $numchildren = $self->children(); | |||||||||||||||||||||||||||
| 580 | 0 | ▶ | croak "Parse::Eyapp::Node::delete error: expected an index between 0 and ". | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$child =~ /\d+/ and $child < $numchildren
MC/DC0%0/2
$child =~ /\d+/ and $child < $numchildren
$child =~ /\d+/
$child < $numchildren
Truth table0%0/3
A and B
A= $child =~ /\d+/B= $child < $numchildren
| |||||||||||||||||||||||||||||
| 581 | ($numchildren-1).". Got $child" unless ($child =~ /\d+/ and $child < $numchildren); | ||||||||||||||||||||||||||||
| 582 | 0 | splice(@{$self->{children}}, $child, 1); | |||||||||||||||||||||||||||
| 583 | 0 | return $child; | |||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||
| 586 | #################################################################### | ||||||||||||||||||||||||||||
| 587 | # Usage : $BLOCK->shift | ||||||||||||||||||||||||||||
| 588 | # Purpose : deletes the first child of the node | ||||||||||||||||||||||||||||
| 589 | # Returns : The deleted child | ||||||||||||||||||||||||||||
| 590 | # Parameters : The object | ||||||||||||||||||||||||||||
| 591 | # Throws : If the object can't do children | ||||||||||||||||||||||||||||
| 592 | # See Also : n/a | ||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||
| 594 | 0 | ▶ | sub shift { | ||||||||||||||||||||||||||
|
Subroutine
shift: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 595 | 0 | my $self = CORE::shift; # The tree object | |||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||
| 597 | 0 | ▶ | croak "Parse::Eyapp::Node::shift error, node:\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 598 | .Parse::Eyapp::Node->str($self)."\ndoes not have children" | ||||||||||||||||||||||||||||
| 599 | unless UNIVERSAL::can($self, 'children'); | ||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||
| 601 | 0 | return CORE::shift(@{$self->{children}}); | |||||||||||||||||||||||||||
| 602 | } | ||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||
| 604 | 0 | ▶ | sub unshift { | ||||||||||||||||||||||||||
|
Subroutine
unshift: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 605 | 0 | my $self = CORE::shift; # The tree object | |||||||||||||||||||||||||||
| 606 | 0 | my $node = CORE::shift; # node to insert | |||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||
| 608 | 0 | CORE::unshift @{$self->{children}}, $node; | |||||||||||||||||||||||||||
| 609 | } | ||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||
| 611 | 0 | ▶ | sub push { | ||||||||||||||||||||||||||
|
Subroutine
push: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 612 | 0 | my $self = CORE::shift; # The tree object | |||||||||||||||||||||||||||
| 613 | #my $node = CORE::shift; # node to insert | ||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||
| 615 | #CORE::push @{$self->{children}}, $node; | ||||||||||||||||||||||||||||
| 616 | 0 | CORE::push @{$self->{children}}, @_; | |||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||
| 619 | 2 | ▶ | sub insert_before { | ||||||||||||||||||||||||||
|
Subroutine
insert_before: called CC=9 SCAR=28.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 620 | 2 | my $self = CORE::shift; # The tree object | |||||||||||||||||||||||||||
| 621 | 2 | my $child = CORE::shift; # index or pointer | |||||||||||||||||||||||||||
| 622 | 2 | my $node = CORE::shift; # node to insert | |||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||
| 624 | 2 | ▶ | croak "Parse::Eyapp::Node::insert_before error, node:\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
UNIVERSAL::can($self, "children") and $self->children > 0
MC/DC0%0/2
UNIVERSAL::can($self, "children") and $self->children > 0
UNIVERSAL::can($self, "children")
$self->children > 0
Truth table33%1/3
A and B
A= UNIVERSAL::can($self, "children")B= $self->children > 0
| |||||||||||||||||||||||||||||
| 625 | .Parse::Eyapp::Node::str($self)."\ndoes not have children" | ||||||||||||||||||||||||||||
| 626 | unless UNIVERSAL::can($self, 'children') and ($self->children()>0); | ||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||
| 628 | 2 | ▶ | if (ref($child)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 629 | 2 | my $i = 0; | |||||||||||||||||||||||||||
| 630 | 2 | for ($self->children()) { | |||||||||||||||||||||||||||
| 631 | 6 | ▶ | last if $_ == $child; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 632 | 4 | $i++; | |||||||||||||||||||||||||||
| 633 | } | ||||||||||||||||||||||||||||
| 634 | 2 | ▶ | if ($i == $self->children()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 635 | 0 | warn "Parse::Eyapp::Node::insert_before warning: node:\n" | |||||||||||||||||||||||||||
| 636 | .Parse::Eyapp::Node::str($self) | ||||||||||||||||||||||||||||
| 637 | ."\ndoes not have a child like:\n" | ||||||||||||||||||||||||||||
| 638 | .Parse::Eyapp::Node::str($child)."\nThe node was not inserted!\n"; | ||||||||||||||||||||||||||||
| 639 | 0 | return $child; | |||||||||||||||||||||||||||
| 640 | } | ||||||||||||||||||||||||||||
| 641 | 2 | splice(@{$self->{children}}, $i, 0, $node); | |||||||||||||||||||||||||||
| 642 | 2 | return $node; | |||||||||||||||||||||||||||
| 643 | } | ||||||||||||||||||||||||||||
| 644 | 0 | my $numchildren = $self->children(); | |||||||||||||||||||||||||||
| 645 | 0 | ▶ | croak "Parse::Eyapp::Node::insert_before error: expected an index between 0 and ". | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$child =~ /\d+/ and $child < $numchildren
MC/DC0%0/2
$child =~ /\d+/ and $child < $numchildren
$child =~ /\d+/
$child < $numchildren
Truth table0%0/3
A and B
A= $child =~ /\d+/B= $child < $numchildren
| |||||||||||||||||||||||||||||
| 646 | ($numchildren-1).". Got $child" unless ($child =~ /\d+/ and $child < $numchildren); | ||||||||||||||||||||||||||||
| 647 | 0 | splice(@{$self->{children}}, $child, 0, $node); | |||||||||||||||||||||||||||
| 648 | 0 | return $child; | |||||||||||||||||||||||||||
| 649 | } | ||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||
| 651 | 0 | ▶ | sub insert_after { | ||||||||||||||||||||||||||
|
Subroutine
insert_after: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 652 | 0 | my $self = CORE::shift; # The tree object | |||||||||||||||||||||||||||
| 653 | 0 | my $child = CORE::shift; # index or pointer | |||||||||||||||||||||||||||
| 654 | 0 | my $node = CORE::shift; # node to insert | |||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||
| 656 | 0 | ▶ | croak "Parse::Eyapp::Node::insert_after error, node:\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
UNIVERSAL::can($self, "children") and $self->children > 0
MC/DC0%0/2
UNIVERSAL::can($self, "children") and $self->children > 0
UNIVERSAL::can($self, "children")
$self->children > 0
Truth table0%0/3
A and B
A= UNIVERSAL::can($self, "children")B= $self->children > 0
| |||||||||||||||||||||||||||||
| 657 | .Parse::Eyapp::Node::str($self)."\ndoes not have children" | ||||||||||||||||||||||||||||
| 658 | unless UNIVERSAL::can($self, 'children') and ($self->children()>0); | ||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||
| 660 | 0 | ▶ | if (ref($child)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 661 | 0 | my $i = 0; | |||||||||||||||||||||||||||
| 662 | 0 | for ($self->children()) { | |||||||||||||||||||||||||||
| 663 | 0 | ▶ | last if $_ == $child; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 664 | 0 | $i++; | |||||||||||||||||||||||||||
| 665 | } | ||||||||||||||||||||||||||||
| 666 | 0 | ▶ | if ($i == $self->children()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 667 | 0 | warn "Parse::Eyapp::Node::insert_after warning: node:\n" | |||||||||||||||||||||||||||
| 668 | .Parse::Eyapp::Node::str($self). | ||||||||||||||||||||||||||||
| 669 | "\ndoes not have a child like:\n" | ||||||||||||||||||||||||||||
| 670 | .Parse::Eyapp::Node::str($child)."\nThe node was not inserted!\n"; | ||||||||||||||||||||||||||||
| 671 | 0 | return $child; | |||||||||||||||||||||||||||
| 672 | } | ||||||||||||||||||||||||||||
| 673 | 0 | splice(@{$self->{children}}, $i+1, 0, $node); | |||||||||||||||||||||||||||
| 674 | 0 | return $node; | |||||||||||||||||||||||||||
| 675 | } | ||||||||||||||||||||||||||||
| 676 | 0 | my $numchildren = $self->children(); | |||||||||||||||||||||||||||
| 677 | 0 | ▶ | croak "Parse::Eyapp::Node::insert_after error: expected an index between 0 and ". | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$child =~ /\d+/ and $child < $numchildren
MC/DC0%0/2
$child =~ /\d+/ and $child < $numchildren
$child =~ /\d+/
$child < $numchildren
Truth table0%0/3
A and B
A= $child =~ /\d+/B= $child < $numchildren
| |||||||||||||||||||||||||||||
| 678 | ($numchildren-1).". Got $child" unless ($child =~ /\d+/ and $child < $numchildren); | ||||||||||||||||||||||||||||
| 679 | 0 | splice(@{$self->{children}}, $child+1, 0, $node); | |||||||||||||||||||||||||||
| 680 | 0 | return $child; | |||||||||||||||||||||||||||
| 681 | } | ||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||
| 683 | { # $match closure | ||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||
| 685 | 64 | my $match; | |||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||
| 687 | 1 | ▶ | sub clean_tree { | ||||||||||||||||||||||||||
|
Subroutine
clean_tree: called CC=3 SCAR=12.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 688 | 1 | $match = pop; | |||||||||||||||||||||||||||
| 689 | 1 | ▶ | croak "clean tree: a node and code reference expected" unless (ref($match) eq 'CODE') and (@_ > 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $match eq "CODE" and @_ > 0
MC/DC0%0/2
ref $match eq "CODE" and @_ > 0
ref $match eq "CODE"
@_ > 0
Truth table33%1/3
A and B
A= ref $match eq "CODE"B= @_ > 0
| |||||||||||||||||||||||||||||
| 690 | 1 | $_[0]->_clean_tree(); | |||||||||||||||||||||||||||
| 691 | } | ||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||
| 693 | 6 | ▶ | sub _clean_tree { | ||||||||||||||||||||||||||
|
Subroutine
_clean_tree: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 694 | 6 | my @children; | |||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||
| 696 | 6 | for ($_[0]->children()) { | |||||||||||||||||||||||||||
| 697 | 16 | ▶ | next if (!defined($_) or $match->($_)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $_ or &$match($_)
MC/DC50%1/2
not defined $_ or &$match($_)
not defined $_
&$match($_)
Truth table66%2/3
not(A) or B
A= not defined $_B= &$match($_)
| |||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||
| 699 | 5 | $_->_clean_tree(); | |||||||||||||||||||||||||||
| 700 | 5 | CORE::push @children, $_; | |||||||||||||||||||||||||||
| 701 | } | ||||||||||||||||||||||||||||
| 702 | 6 | $_[0]->{children} = \@children; # Bad code | |||||||||||||||||||||||||||
| 703 | } | ||||||||||||||||||||||||||||
| 704 | } # $match closure | ||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||
| 706 | #################################################################### | ||||||||||||||||||||||||||||
| 707 | # Usage : $t->str | ||||||||||||||||||||||||||||
| 708 | # Returns : Returns a string describing the Parse::Eyapp::Node as a term | ||||||||||||||||||||||||||||
| 709 | # i.e., s.t. like: 'PROGRAM(FUNCTION(RETURN(TERMINAL,VAR(TERMINAL))))' | ||||||||||||||||||||||||||||
| 710 | 64 | our @PREFIXES = qw(Parse::Eyapp::Node::); | |||||||||||||||||||||||||||
| 711 | 64 | our $INDENT = 0; # -1 new 0 = compact, 1 = indent, 2 = indent and include Types in closing parenthesis | |||||||||||||||||||||||||||
| 712 | 64 | our $STRSEP = ','; | |||||||||||||||||||||||||||
| 713 | 64 | our $DELIMITER = '['; | |||||||||||||||||||||||||||
| 714 | 64 | our $FOOTNOTE_HEADER = "\n---------------------------\n"; | |||||||||||||||||||||||||||
| 715 | 64 | our $FOOTNOTE_SEP = ")\n"; | |||||||||||||||||||||||||||
| 716 | 64 | our $FOOTNOTE_LEFT = '^{'; | |||||||||||||||||||||||||||
| 717 | 64 | our $FOOTNOTE_RIGHT = '}'; | |||||||||||||||||||||||||||
| 718 | 64 | our $LINESEP = 4; | |||||||||||||||||||||||||||
| 719 | 98 | ▶ | our $CLASS_HANDLER = sub { type($_[0]) }; # What to print to identify the node | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||
| 721 | 64 | my %match_del = ( | |||||||||||||||||||||||||||
| 722 | '[' => ']', | ||||||||||||||||||||||||||||
| 723 | '{' => '}', | ||||||||||||||||||||||||||||
| 724 | '(' => ')', | ||||||||||||||||||||||||||||
| 725 | '<' => '>' | ||||||||||||||||||||||||||||
| 726 | ); | ||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||
| 728 | 64 | my $pair; | |||||||||||||||||||||||||||
| 729 | 64 | my $footnotes = ''; | |||||||||||||||||||||||||||
| 730 | 64 | my $footnote_label; | |||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||
| 732 | 9 | ▶ | sub str { | ||||||||||||||||||||||||||
|
Subroutine
str: called CC=6 SCAR=19.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||
| 734 | 9 | my @terms; | |||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||
| 736 | # Consume arg only if called as a class method Parse::Eyap::Node->str($node1, $node2, ...) | ||||||||||||||||||||||||||||
| 737 | 9 | ▶ | CORE::shift unless ref($_[0]); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||
| 739 | 9 | for (@_) { | |||||||||||||||||||||||||||
| 740 | 9 | $footnote_label = 0; | |||||||||||||||||||||||||||
| 741 | 9 | $footnotes = ''; | |||||||||||||||||||||||||||
| 742 | # Set delimiters for semantic values | ||||||||||||||||||||||||||||
| 743 | 9 | ▶ | if (defined($DELIMITER) and exists($match_del{$DELIMITER})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $Parse::Eyapp::Node::DELIMITER and exists $match_del{$Parse::Eyapp::Node::DELIMITER}
MC/DC0%0/2
defined $Parse::Eyapp::Node::DELIMITER and exists $match_del{$Parse::Eyapp::Node::DELIMITER}
defined $Parse::Eyapp::Node::DELIMITER
exists $match_del{$Parse::Eyapp::Node::DELIMITER}
Truth table33%1/3
A and B
A= defined $Parse::Eyapp::Node::DELIMITERB= exists $match_del{$Parse::Eyapp::Node::DELIMITER}
| |||||||||||||||||||||||||||||
| 744 | 9 | $pair = $match_del{$DELIMITER}; | |||||||||||||||||||||||||||
| 745 | } | ||||||||||||||||||||||||||||
| 746 | else { | ||||||||||||||||||||||||||||
| 747 | 0 | $DELIMITER = $pair = ''; | |||||||||||||||||||||||||||
| 748 | } | ||||||||||||||||||||||||||||
| 749 | 9 | CORE::push @terms, _str($_).$footnotes; | |||||||||||||||||||||||||||
| 750 | } | ||||||||||||||||||||||||||||
| 751 | 9 | ▶ | return wantarray? @terms : $terms[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 752 | } | ||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||
| 754 | 98 | ▶ | sub _str { | ||||||||||||||||||||||||||
|
Subroutine
_str: called CC=18 SCAR=37.5
| |||||||||||||||||||||||||||||
| 755 | 98 | my $self = CORE::shift; # root of the subtree | |||||||||||||||||||||||||||
| 756 | 98 | ▶ | my $indent = (CORE::shift or 0); # current depth in spaces " " | ||||||||||||||||||||||||||
|
Condition100%2/2
CORE::shift() || 0
MC/DC100%1/1
CORE::shift() || 0
CORE::shift()
Truth table100%2/2
A
A= CORE::shift()
| |||||||||||||||||||||||||||||
| 757 | |||||||||||||||||||||||||||||
| 758 | 98 | my @children = Parse::Eyapp::Node::children($self); | |||||||||||||||||||||||||||
| 759 | 98 | my @t; | |||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||
| 761 | my $res; | ||||||||||||||||||||||||||||
| 762 | 98 | my $fn = $footnote_label; | |||||||||||||||||||||||||||
| 763 | 98 | ▶ | if ($INDENT >= 0 && UNIVERSAL::can($self, 'footnote')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$Parse::Eyapp::Node::INDENT >= 0 and UNIVERSAL::can($self, "footnote")
MC/DC0%0/2
$Parse::Eyapp::Node::INDENT >= 0 and UNIVERSAL::can($self, "footnote")
$Parse::Eyapp::Node::INDENT >= 0
UNIVERSAL::can($self, "footnote")
Truth table33%1/3
A and B
A= $Parse::Eyapp::Node::INDENT >= 0B= UNIVERSAL::can($self, "footnote")
| |||||||||||||||||||||||||||||
| 764 | 0 | $res = $self->footnote; | |||||||||||||||||||||||||||
| 765 | 0 | ▶ | $footnotes .= $FOOTNOTE_HEADER.$footnote_label++.$FOOTNOTE_SEP.$res if $res; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 766 | } | ||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||
| 768 | # recursively visit nodes | ||||||||||||||||||||||||||||
| 769 | 98 | for (@children) { | |||||||||||||||||||||||||||
| 770 | 89 | ▶ | CORE::push @t, Parse::Eyapp::Node::_str($_, $indent+2) if defined($_); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 771 | } | ||||||||||||||||||||||||||||
| 772 | 98 | local $" = $STRSEP; | |||||||||||||||||||||||||||
| 773 | 98 | my $class = $CLASS_HANDLER->($self); | |||||||||||||||||||||||||||
| 774 | 98 | $class =~ s/^$_// for @PREFIXES; | |||||||||||||||||||||||||||
| 775 | 98 | my $information; | |||||||||||||||||||||||||||
| 776 | 98 | ▶ | $information = $self->info if ($INDENT >= 0 && UNIVERSAL::can($self, 'info')); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$Parse::Eyapp::Node::INDENT >= 0 and UNIVERSAL::can($self, "info")
MC/DC50%1/2
$Parse::Eyapp::Node::INDENT >= 0 and UNIVERSAL::can($self, "info")
$Parse::Eyapp::Node::INDENT >= 0
UNIVERSAL::can($self, "info")
Truth table66%2/3
A and B
A= $Parse::Eyapp::Node::INDENT >= 0B= UNIVERSAL::can($self, "info")
| |||||||||||||||||||||||||||||
| 777 | 98 | ▶ | $class .= $DELIMITER.$information.$pair if defined($information); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 778 | 98 | ▶ | if ($INDENT >= 0 && $res) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$Parse::Eyapp::Node::INDENT >= 0 and $res
MC/DC0%0/2
$Parse::Eyapp::Node::INDENT >= 0 and $res
$Parse::Eyapp::Node::INDENT >= 0
$res
Truth table33%1/3
A and B
A= $Parse::Eyapp::Node::INDENT >= 0B= $res
| |||||||||||||||||||||||||||||
| 779 | 0 | $class .= $FOOTNOTE_LEFT.$fn.$FOOTNOTE_RIGHT; | |||||||||||||||||||||||||||
| 780 | } | ||||||||||||||||||||||||||||
| 781 | |||||||||||||||||||||||||||||
| 782 | 98 | ▶ | if ($INDENT > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 783 | 0 | my $w = " "x$indent; | |||||||||||||||||||||||||||
| 784 | 0 | $class = "\n$w$class"; | |||||||||||||||||||||||||||
| 785 | 0 | ▶ | $class .= "(@t\n$w)" if @children; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 786 | 0 | ▶ | $class .= " # ".$CLASS_HANDLER->($self) if ($INDENT > 1) and ($class =~ tr/\n/\n/>$LINESEP); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$Parse::Eyapp::Node::INDENT > 1 and $class =~ tr/\n// > $Parse::Eyapp::Node::LINESEP
MC/DC0%0/2
$Parse::Eyapp::Node::INDENT > 1 and $class =~ tr/\n// > $Parse::Eyapp::Node::LINESEP
$Parse::Eyapp::Node::INDENT > 1
$class =~ tr/\n// > $Parse::Eyapp::Node::LINESEP
Truth table0%0/3
A and B
A= $Parse::Eyapp::Node::INDENT > 1B= $class =~ tr/\n// > $Parse::Eyapp::Node::LINESEP
| |||||||||||||||||||||||||||||
| 787 | } | ||||||||||||||||||||||||||||
| 788 | else { | ||||||||||||||||||||||||||||
| 789 | 98 | ▶ | $class .= "(@t)" if @children; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 790 | } | ||||||||||||||||||||||||||||
| 791 | 98 | return $class; | |||||||||||||||||||||||||||
| 792 | } | ||||||||||||||||||||||||||||
| 793 | |||||||||||||||||||||||||||||
| 794 | 0 | ▶ | sub _dot { | ||||||||||||||||||||||||||
|
Subroutine
_dot: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 795 | 0 | my ($root, $number) = @_; | |||||||||||||||||||||||||||
| 796 | |||||||||||||||||||||||||||||
| 797 | 0 | my $type = $root->type(); | |||||||||||||||||||||||||||
| 798 | |||||||||||||||||||||||||||||
| 799 | 0 | my $information; | |||||||||||||||||||||||||||
| 800 | 0 | ▶ | $information = $root->info if ($INDENT >= 0 && $root->can('info')); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$Parse::Eyapp::Node::INDENT >= 0 and $root->can("info")
MC/DC0%0/2
$Parse::Eyapp::Node::INDENT >= 0 and $root->can("info")
$Parse::Eyapp::Node::INDENT >= 0
$root->can("info")
Truth table0%0/3
A and B
A= $Parse::Eyapp::Node::INDENT >= 0B= $root->can("info")
| |||||||||||||||||||||||||||||
| 801 | 0 | my $class = $CLASS_HANDLER->($root); | |||||||||||||||||||||||||||
| 802 | 0 | ▶ | $class = qq{$class<font color="red">$DELIMITER$information$pair</font>} if defined($information); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 803 | |||||||||||||||||||||||||||||
| 804 | 0 | my $dot = qq{ $number [label = <$class>];\n}; | |||||||||||||||||||||||||||
| 805 | |||||||||||||||||||||||||||||
| 806 | 0 | my $k = 0; | |||||||||||||||||||||||||||
| 807 | 0 | my @dots = map { $k++; $_->_dot("$number$k") } $root->children; | |||||||||||||||||||||||||||
| 808 | |||||||||||||||||||||||||||||
| 809 | 0 | ▶ | for($k = 1; $k <= $root->children; $k++) {; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 810 | 0 | $dot .= qq{ $number -> $number$k;\n}; | |||||||||||||||||||||||||||
| 811 | } | ||||||||||||||||||||||||||||
| 812 | |||||||||||||||||||||||||||||
| 813 | 0 | return $dot.join('',@dots); | |||||||||||||||||||||||||||
| 814 | } | ||||||||||||||||||||||||||||
| 815 | |||||||||||||||||||||||||||||
| 816 | 0 | ▶ | sub dot { | ||||||||||||||||||||||||||
|
Subroutine
dot: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 817 | 0 | my $dot = $_[0]->_dot('0'); | |||||||||||||||||||||||||||
| 818 | 0 | return << "EOGRAPH"; | |||||||||||||||||||||||||||
| 819 | digraph G { | ||||||||||||||||||||||||||||
| 820 | ordering=out | ||||||||||||||||||||||||||||
| 821 | |||||||||||||||||||||||||||||
| 822 | $dot | ||||||||||||||||||||||||||||
| 823 | } | ||||||||||||||||||||||||||||
| 824 | EOGRAPH | ||||||||||||||||||||||||||||
| 825 | } | ||||||||||||||||||||||||||||
| 826 | |||||||||||||||||||||||||||||
| 827 | 0 | ▶ | sub fdot { | ||||||||||||||||||||||||||
|
Subroutine
fdot: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 828 | 0 | my ($self, $file) = @_; | |||||||||||||||||||||||||||
| 829 | |||||||||||||||||||||||||||||
| 830 | 0 | ▶ | if ($file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 831 | 0 | ▶ | $file .= '.dot' unless $file =~ /\.dot$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 832 | } | ||||||||||||||||||||||||||||
| 833 | else { | ||||||||||||||||||||||||||||
| 834 | 0 | $file = $self->type().".dot"; | |||||||||||||||||||||||||||
| 835 | } | ||||||||||||||||||||||||||||
| 836 | 0 | open my $f, "> $file"; | |||||||||||||||||||||||||||
| 837 | 0 | print $f $self->dot(); | |||||||||||||||||||||||||||
| 838 | 0 | close($f); | |||||||||||||||||||||||||||
| 839 | } | ||||||||||||||||||||||||||||
| 840 | |||||||||||||||||||||||||||||
| 841 | 64 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=10.3
| |||||||||||||||||||||||||||||
| 842 | 64 | my @dotFormats = qw{bmp canon cgimage cmap cmapx cmapx_np eps exr fig gd gd2 gif gv imap imap_np ismap jp2 jpe jpeg jpg pct pdf pict plain plain-ext png ps ps2 psd sgi svg svgz tga tif tiff tk vml vmlz vrml wbmp x11 xdot xlib}; | |||||||||||||||||||||||||||
| 843 | |||||||||||||||||||||||||||||
| 844 | 64 | for my $format (@dotFormats) { | |||||||||||||||||||||||||||
| 845 | |||||||||||||||||||||||||||||
| 846 | 64 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 847 | 2752 | ▶ | *{'Parse::Eyapp::Node::'.$format} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=16.1
| |||||||||||||||||||||||||||||
| 848 | 0 | my ($self, $file) = @_; | |||||||||||||||||||||||||||
| 849 | |||||||||||||||||||||||||||||
| 850 | 0 | ▶ | $file = $self->type() unless defined($file); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 851 | |||||||||||||||||||||||||||||
| 852 | 0 | $self->fdot($file); | |||||||||||||||||||||||||||
| 853 | |||||||||||||||||||||||||||||
| 854 | 0 | $file =~ s/\.(dot|$format)$//; | |||||||||||||||||||||||||||
| 855 | 0 | my $dotfile = "$file.dot"; | |||||||||||||||||||||||||||
| 856 | 0 | my $pngfile = "$file.$format"; | |||||||||||||||||||||||||||
| 857 | 0 | my $err = qx{dot -T$format $dotfile -o $pngfile 2>&1}; | |||||||||||||||||||||||||||
| 858 | 0 | return ($err, $?); | |||||||||||||||||||||||||||
| 859 | } | ||||||||||||||||||||||||||||
| 860 | 2752 | } | |||||||||||||||||||||||||||
| 861 | } | ||||||||||||||||||||||||||||
| 862 | |||||||||||||||||||||||||||||
| 863 | 258 | ▶ | sub translation_scheme { | ||||||||||||||||||||||||||
|
Subroutine
translation_scheme: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 864 | 258 | my $self = CORE::shift; # root of the subtree | |||||||||||||||||||||||||||
| 865 | 258 | my @children = $self->children(); | |||||||||||||||||||||||||||
| 866 | 258 | for (@children) { | |||||||||||||||||||||||||||
| 867 | 371 | ▶ | if (ref($_) eq 'CODE') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 868 | 126 | $_->($self, $self->Children); | |||||||||||||||||||||||||||
| 869 | } | ||||||||||||||||||||||||||||
| 870 | elsif (defined($_)) { | ||||||||||||||||||||||||||||
| 871 | 245 | translation_scheme($_); | |||||||||||||||||||||||||||
| 872 | } | ||||||||||||||||||||||||||||
| 873 | } | ||||||||||||||||||||||||||||
| 874 | } | ||||||||||||||||||||||||||||
| 875 | |||||||||||||||||||||||||||||
| 876 | 219 | ▶ | sub type { | ||||||||||||||||||||||||||
|
Subroutine
type: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 877 | 219 | my $type = ref($_[0]); | |||||||||||||||||||||||||||
| 878 | |||||||||||||||||||||||||||||
| 879 | 219 | ▶ | if ($type) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 880 | 219 | ▶ | if (defined($_[1])) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 881 | 88 | $type = $_[1]; | |||||||||||||||||||||||||||
| 882 | 88 | Parse::Eyapp::Driver::BeANode($type); | |||||||||||||||||||||||||||
| 883 | 88 | bless $_[0], $type; | |||||||||||||||||||||||||||
| 884 | } | ||||||||||||||||||||||||||||
| 885 | 219 | return $type | |||||||||||||||||||||||||||
| 886 | } | ||||||||||||||||||||||||||||
| 887 | 0 | return 'Parse::Eyapp::Node::STRING'; | |||||||||||||||||||||||||||
| 888 | } | ||||||||||||||||||||||||||||
| 889 | |||||||||||||||||||||||||||||
| 890 | { # Tree "fuzzy" equality | ||||||||||||||||||||||||||||
| 891 | |||||||||||||||||||||||||||||
| 892 | #################################################################### | ||||||||||||||||||||||||||||
| 893 | # Usage : $t1->equal($t2, n => sub { return $_[0] == $_[1] }) | ||||||||||||||||||||||||||||
| 894 | # Purpose : Checks the equality between two AST | ||||||||||||||||||||||||||||
| 895 | # Returns : 1 if equal, 0 if not 'equal' | ||||||||||||||||||||||||||||
| 896 | # Parameters : Two Parse::Eyapp:Node nodes and a hash of comparison handlers. | ||||||||||||||||||||||||||||
| 897 | # The keys of the hash are the attributes of the nodes. The value is | ||||||||||||||||||||||||||||
| 898 | # a comparator function. The comparator for key $k receives the attribute | ||||||||||||||||||||||||||||
| 899 | # for the nodes being visited and rmust return true if they are considered similar | ||||||||||||||||||||||||||||
| 900 | # Throws : exceptions if the parameters aren't Parse::Eyapp::Nodes | ||||||||||||||||||||||||||||
| 901 | |||||||||||||||||||||||||||||
| 902 | 64 | my %handler; | |||||||||||||||||||||||||||
| 903 | |||||||||||||||||||||||||||||
| 904 | # True if the two trees look similar | ||||||||||||||||||||||||||||
| 905 | 2 | ▶ | sub equal { | ||||||||||||||||||||||||||
|
Subroutine
equal: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 906 | 2 | ▶ | croak "Parse::Eyapp::Node::equal error. Expected two syntax trees \n" unless (@_ > 1); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 907 | |||||||||||||||||||||||||||||
| 908 | 2 | %handler = splice(@_, 2); | |||||||||||||||||||||||||||
| 909 | 2 | my $key = ''; | |||||||||||||||||||||||||||
| 910 | 2 | ▶ | defined($key=firstval {!UNIVERSAL::isa($handler{$_},'CODE') } keys %handler) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 911 | and | ||||||||||||||||||||||||||||
| 912 | croak "Parse::Eyapp::Node::equal error. Expected a CODE ref for attribute $key\n"; | ||||||||||||||||||||||||||||
| 913 | 2 | goto &_equal; | |||||||||||||||||||||||||||
| 914 | } | ||||||||||||||||||||||||||||
| 915 | |||||||||||||||||||||||||||||
| 916 | 4 | ▶ | sub _equal { | ||||||||||||||||||||||||||
|
Subroutine
_equal: called CC=15 SCAR=41.0
| |||||||||||||||||||||||||||||
| 917 | 4 | my $tree1 = CORE::shift; | |||||||||||||||||||||||||||
| 918 | 4 | my $tree2 = CORE::shift; | |||||||||||||||||||||||||||
| 919 | |||||||||||||||||||||||||||||
| 920 | # Same type | ||||||||||||||||||||||||||||
| 921 | 4 | ▶ | return 0 unless ref($tree1) eq ref($tree2); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 922 | |||||||||||||||||||||||||||||
| 923 | # Check attributes via handlers | ||||||||||||||||||||||||||||
| 924 | 4 | for (keys %handler) { | |||||||||||||||||||||||||||
| 925 | # Check for existence | ||||||||||||||||||||||||||||
| 926 | 1 | ▶ | return 0 if (exists($tree1->{$_}) && !exists($tree2->{$_})); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $tree1->{$_} and not exists $tree2->{$_}
MC/DC0%0/2
exists $tree1->{$_} and not exists $tree2->{$_}
exists $tree1->{$_}
not exists $tree2->{$_}
Truth table33%1/3
A and not(B)
A= exists $tree1->{$_}B= not exists $tree2->{$_}
| |||||||||||||||||||||||||||||
| 927 | 0 | ▶ | return 0 if (exists($tree2->{$_}) && !exists($tree1->{$_})); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $tree2->{$_} and not exists $tree1->{$_}
MC/DC0%0/2
exists $tree2->{$_} and not exists $tree1->{$_}
exists $tree2->{$_}
not exists $tree1->{$_}
Truth table0%0/3
A and not(B)
A= exists $tree2->{$_}B= not exists $tree1->{$_}
| |||||||||||||||||||||||||||||
| 928 | |||||||||||||||||||||||||||||
| 929 | # Check for definition | ||||||||||||||||||||||||||||
| 930 | 0 | ▶ | return 0 if (defined($tree1->{$_}) && !defined($tree2->{$_})); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $tree1->{$_} and not defined $tree2->{$_}
MC/DC0%0/2
defined $tree1->{$_} and not defined $tree2->{$_}
defined $tree1->{$_}
not defined $tree2->{$_}
Truth table0%0/3
A and not(B)
A= defined $tree1->{$_}B= not defined $tree2->{$_}
| |||||||||||||||||||||||||||||
| 931 | 0 | ▶ | return 0 if (defined($tree2->{$_}) && !defined($tree1->{$_})); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $tree2->{$_} and not defined $tree1->{$_}
MC/DC0%0/2
defined $tree2->{$_} and not defined $tree1->{$_}
defined $tree2->{$_}
not defined $tree1->{$_}
Truth table0%0/3
A and not(B)
A= defined $tree2->{$_}B= not defined $tree1->{$_}
| |||||||||||||||||||||||||||||
| 932 | |||||||||||||||||||||||||||||
| 933 | # Check for equality | ||||||||||||||||||||||||||||
| 934 | 0 | ▶ | return 0 unless $handler{$_}->($tree1->{$_}, $tree2->{$_}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 935 | } | ||||||||||||||||||||||||||||
| 936 | |||||||||||||||||||||||||||||
| 937 | # Same number of children | ||||||||||||||||||||||||||||
| 938 | 3 | my @children1 = @{$tree1->{children}}; | |||||||||||||||||||||||||||
| 939 | 3 | my @children2 = @{$tree2->{children}}; | |||||||||||||||||||||||||||
| 940 | 3 | ▶ | return 0 unless @children1 == @children2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 941 | |||||||||||||||||||||||||||||
| 942 | # Children must be similar | ||||||||||||||||||||||||||||
| 943 | 3 | for (@children1) { | |||||||||||||||||||||||||||
| 944 | 2 | my $ch2 = CORE::shift @children2; | |||||||||||||||||||||||||||
| 945 | 2 | ▶ | return 0 unless _equal($_, $ch2); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 946 | } | ||||||||||||||||||||||||||||
| 947 | 3 | return 1; | |||||||||||||||||||||||||||
| 948 | } | ||||||||||||||||||||||||||||
| 949 | } | ||||||||||||||||||||||||||||
| 950 | |||||||||||||||||||||||||||||
| 951 | 64 | 1; | |||||||||||||||||||||||||||
| 952 | |||||||||||||||||||||||||||||
| 953 | package Parse::Eyapp::Node::Match; | ||||||||||||||||||||||||||||
| 954 | 64 | our @ISA = qw(Parse::Eyapp::Node); | |||||||||||||||||||||||||||
| 955 | |||||||||||||||||||||||||||||
| 956 | # A Parse::Eyapp::Node::Match object is a reference | ||||||||||||||||||||||||||||
| 957 | # to a tree of Parse::Eyapp::Nodes that has been used | ||||||||||||||||||||||||||||
| 958 | # in a tree matching regexp. You can think of them | ||||||||||||||||||||||||||||
| 959 | # as the equivalent of $1 $2, ... in treeregexeps | ||||||||||||||||||||||||||||
| 960 | |||||||||||||||||||||||||||||
| 961 | # The depth of the Parse::Eyapp::Node being referenced | ||||||||||||||||||||||||||||
| 962 | |||||||||||||||||||||||||||||
| 963 | 125 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 964 | 125 | my $class = shift; | |||||||||||||||||||||||||||
| 965 | |||||||||||||||||||||||||||||
| 966 | 125 | my $matchnode = { @_ }; | |||||||||||||||||||||||||||
| 967 | 125 | $matchnode->{children} = []; | |||||||||||||||||||||||||||
| 968 | 125 | bless $matchnode, $class; | |||||||||||||||||||||||||||
| 969 | } | ||||||||||||||||||||||||||||
| 970 | |||||||||||||||||||||||||||||
| 971 | 0 | ▶ | sub depth { | ||||||||||||||||||||||||||
|
Subroutine
depth: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 972 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 973 | |||||||||||||||||||||||||||||
| 974 | 0 | return $self->{depth}; | |||||||||||||||||||||||||||
| 975 | } | ||||||||||||||||||||||||||||
| 976 | |||||||||||||||||||||||||||||
| 977 | # The coordinates of the Parse::Eyapp::Node being referenced | ||||||||||||||||||||||||||||
| 978 | 0 | ▶ | sub coord { | ||||||||||||||||||||||||||
|
Subroutine
coord: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 979 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 980 | |||||||||||||||||||||||||||||
| 981 | 0 | return $self->{dewey}; | |||||||||||||||||||||||||||
| 982 | } | ||||||||||||||||||||||||||||
| 983 | |||||||||||||||||||||||||||||
| 984 | |||||||||||||||||||||||||||||
| 985 | # The Parse::Eyapp::Node being referenced | ||||||||||||||||||||||||||||
| 986 | 31 | ▶ | sub node { | ||||||||||||||||||||||||||
|
Subroutine
node: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 987 | 31 | my $self = shift; | |||||||||||||||||||||||||||
| 988 | |||||||||||||||||||||||||||||
| 989 | 31 | return $self->{node}; | |||||||||||||||||||||||||||
| 990 | } | ||||||||||||||||||||||||||||
| 991 | |||||||||||||||||||||||||||||
| 992 | # The Parse::Eyapp::Node:Match that references | ||||||||||||||||||||||||||||
| 993 | # the nearest ancestor of $self->{node} that matched | ||||||||||||||||||||||||||||
| 994 | 31 | ▶ | sub father { | ||||||||||||||||||||||||||
|
Subroutine
father: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 995 | 31 | my $self = shift; | |||||||||||||||||||||||||||
| 996 | |||||||||||||||||||||||||||||
| 997 | 31 | return $self->{father}; | |||||||||||||||||||||||||||
| 998 | } | ||||||||||||||||||||||||||||
| 999 | |||||||||||||||||||||||||||||
| 1000 | # The patterns that matched with $self->{node} | ||||||||||||||||||||||||||||
| 1001 | # Indexes | ||||||||||||||||||||||||||||
| 1002 | 0 | ▶ | sub patterns { | ||||||||||||||||||||||||||
|
Subroutine
patterns: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 1003 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 1004 | |||||||||||||||||||||||||||||
| 1005 | 0 | ▶ | @{$self->{patterns}} = @_ if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1006 | 0 | return @{$self->{patterns}}; | |||||||||||||||||||||||||||
| 1007 | } | ||||||||||||||||||||||||||||
| 1008 | |||||||||||||||||||||||||||||
| 1009 | # The original list of patterns that produced this match | ||||||||||||||||||||||||||||
| 1010 | 0 | ▶ | sub family { | ||||||||||||||||||||||||||
|
Subroutine
family: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 1011 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 1012 | |||||||||||||||||||||||||||||
| 1013 | 0 | ▶ | @{$self->{family}} = @_ if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1014 | 0 | return @{$self->{family}}; | |||||||||||||||||||||||||||
| 1015 | } | ||||||||||||||||||||||||||||
| 1016 | |||||||||||||||||||||||||||||
| 1017 | # The names of the patterns that matched | ||||||||||||||||||||||||||||
| 1018 | 0 | ▶ | sub names { | ||||||||||||||||||||||||||
|
Subroutine
names: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 1019 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 1020 | |||||||||||||||||||||||||||||
| 1021 | 0 | my @indexes = $self->patterns; | |||||||||||||||||||||||||||
| 1022 | 0 | my @family = $self->family; | |||||||||||||||||||||||||||
| 1023 | |||||||||||||||||||||||||||||
| 1024 | 0 | ▶ | return map { $_->{NAME} or "Unknown" } @family[@indexes]; | ||||||||||||||||||||||||||
|
Condition0%0/2
$_->{'NAME'} || 'Unknown'
MC/DC0%0/1
$_->{'NAME'} || 'Unknown'
$_->{'NAME'}
Truth table0%0/2
A
A= $_->{'NAME'}
| |||||||||||||||||||||||||||||
| 1025 | } | ||||||||||||||||||||||||||||
| 1026 | |||||||||||||||||||||||||||||
| 1027 | 0 | ▶ | sub info { | ||||||||||||||||||||||||||
|
Subroutine
info: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 1028 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 1029 | |||||||||||||||||||||||||||||
| 1030 | 0 | my $node = $self->node; | |||||||||||||||||||||||||||
| 1031 | 0 | my @names = $self->names; | |||||||||||||||||||||||||||
| 1032 | 0 | my $nodeinfo; | |||||||||||||||||||||||||||
| 1033 | 0 | ▶ | if (UNIVERSAL::can($node, 'info')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1034 | 0 | $nodeinfo = ":".$node->info; | |||||||||||||||||||||||||||
| 1035 | } | ||||||||||||||||||||||||||||
| 1036 | else { | ||||||||||||||||||||||||||||
| 1037 | 0 | $nodeinfo = ""; | |||||||||||||||||||||||||||
| 1038 | } | ||||||||||||||||||||||||||||
| 1039 | 0 | return "[".ref($self->node).":".$self->depth.":@names$nodeinfo]" | |||||||||||||||||||||||||||
| 1040 | } | ||||||||||||||||||||||||||||
| 1041 | |||||||||||||||||||||||||||||
| 1042 | 64 | 1; | |||||||||||||||||||||||||||
| 1043 | |||||||||||||||||||||||||||||
| 1044 | |||||||||||||||||||||||||||||