File Coverage

blib/lib/Parse/Eyapp/_TreeregexpSupport.pm
Criterion Covered Total %
statement 22 29 75.8
branch 4 12 33.3
condition 3 6 50.0
subroutine 6 6 100.0
pod 0 2 0.0
total 35 55 63.6


line stmt bran cond sub pod time code
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::_TreeregexpSupport;
9 27     27   263 use strict;
  27         62  
  27         678  
10 27     27   122 use Carp;
  27         51  
  27         1419  
11 27     27   144 use Parse::Eyapp::Node;
  27         53  
  27         522  
12 27     27   112 use base qw (Exporter);
  27         54  
  27         8360  
13             our @EXPORT_OK = qw(until_first_match checknumchildren);
14              
15             ################### Support routines #########################
16              
17             # used whith array patterns
18             # index of the children to start
19             # $b recognizer treereg
20             # $r reference to an array where children that don't match are pushed
21             sub until_first_match {
22 83     83 0 179 my ($father, $order, $b, $r) = @_;
23              
24 83 50       268 return undef unless UNIVERSAL::can($father, 'children');
25 83         228 for ($order..0+$father->children()) {
26 148         395 my $t = $father->child($_);
27 148 100       2577 return $t if ($b->($t));
28 127         411 push @$r, $t;
29             }
30 62         1172 return undef;
31             }
32              
33             sub checknumchildren {
34 4     4 0 25 my ($self, $numexpected, $line, $filename, $there_are_lists, $severity) = @_;
35            
36 4         11 my $numchildren = $self->children;
37 4 50 33     63 return 1 if ($numchildren == $numexpected) or ($there_are_lists and $numchildren >= $numexpected);
      66        
38              
39 0 0         return 0 unless ($severity > 1);
40 0           my $class = ref($self);
41 0 0         my $clause = $there_are_lists? ' at least' : '';
42 0           my $warnmessage =<<"END_OF_WARN_MESSAGE";
43             found node $class with $numchildren children.
44             Expected$clause $numexpected children (see line $line of $filename)"
45             END_OF_WARN_MESSAGE
46 0 0         croak "Error! $warnmessage" if $severity > 2;
47 0           warn "Warning! $warnmessage";
48              
49 0           return 0;
50             }
51              
52             1;
53              
54              
55             __END__