RandGen/Regexp.pm

filter: Statementstmt 62.7% 108 / 172 Branchbran 37.5% 33 / 88 Conditioncond 30.7% 12 / 39 MC/DCmcdc 16.6% 4 / 24 Subroutinesub 50.0% 11 / 22 Podpod 80.0% 4 / 5 totaltotal 49.1% 172 / 350 CC 64 SCAR 41.1
CC
64
Cov
51%
capture
110.0
_parseRegexp
90.9
nameCapture
72.0
CRAP 60.8
« RandGen/Production.pm ↑ Summary RandGen/Grammar.pm »
1 # $Revision: #3 $$Date: 2005/08/31 $$Author: jd150722 $
2 ######################################################################
3 #
4 # This program is Copyright 2003-2005 by Jeff Dutton.
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of either the GNU General Public License or the
8 # Perl Artistic License.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # If you do not have a copy of the GNU General Public License write to
16 # the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
17 # MA 02139, USA.
18 ######################################################################
19  
20 package Parse::RandGen::Regexp;
21  
22 4 require 5.006_001;
23 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 4 ▶use Parse::RandGen qw($Debug);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 4 ▶use Data::Dumper; # FIX - debug only
Subroutine BEGIN: called CC=1 SCAR=0.0
26 4 ▶use YAPE::Regex;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 4 ▶use vars qw(@ISA %_Yterm $Debug);
Subroutine BEGIN: called CC=1 SCAR=0.0
29 4 @ISA = ('Parse::RandGen::Condition');
30  
31 5 ▶sub _newDerived {
Subroutine _newDerived: called CC=6 SCAR=18.1
32 5 ▶ my $self = shift or confess ("%Error: Cannot call without a valid object!");
Branch: 1 branch
BranchTrueFalseTotal
my $self = shift() or confess("%Error: Cannot call without a valid object!") 5 0 5
33 5 my $type = ref($self);
34 5 my $elemRef = ref($self->element());
35 5 ▶ ($elemRef eq "Regexp") or confess("%Error: $type has an element that is not a Regexp reference (ref=\"$elemRef\")!");
Branch: 1 branch
BranchTrueFalseTotal
$elemRef eq "Regexp" or confess(qq[%Error: $type has an element that is not a Regexp reference (ref="$elemRef")!]) 5 0 5
36  
37 # Implement a RandGen::Rule to represent the complexities of the Regexp
38 # This is only used for pick()ing a matching value for the Regexp...
39 5 my $yape = YAPE::Regex->new($self->element());
40 5 $yape->parse();
41 5 my $treeArray = $yape->{TREE};
42 5 ▶ ($#{$treeArray} > 0) and die("Found a YAPE::Regex TREE with more than one entry!\n");
Branch: 1 branch
BranchTrueFalseTotal
$#{$treeArray;} > 0 and die "Found a YAPE::Regex TREE with more than one entry!\n" 0 5 5
43 5 ▶ (ref($$treeArray[0]) eq "YAPE::Regex::group") or die("Found a YAPE::Regex TREE, but its entry is not a group!\n");
Branch: 1 branch
BranchTrueFalseTotal
ref $treeArray->[0] eq "YAPE::Regex::group" or die "Found a YAPE::Regex TREE, but its entry is not a group!\n" 5 0 5
44  
45 5 $self->{_rule} = Parse::RandGen::Rule->new();
46 5 my $prod = Parse::RandGen::Production->new();
47 5 $self->{_rule}->addProd($prod);
48 my $cur = {
49 rule => $self->{_rule},
50 5 prod => $prod,
51 on => { },
52 off => { i=>1, m=>1, s=>1, x=>1 },
53 };
54 5 ▶ $Data::Dumper::Indent = 1 if $Debug;
Branch: 1 branch
BranchTrueFalseTotal
if $Parse::RandGen::Regexp::Debug 3 2 5
55 #print ("Parse::RandGen::Regexp::new(): Getting ready to parse the following Regexp ".$self->element().":\n", Data::Dumper->Dump([$yape])) if $Debug;
56 5 $self->_parseRegexp($$treeArray[0], { rule=>$self->{_rule}, prod=>$prod } );
57 #print ("Parse::RandGen::Regexp::new(): Finished parsing the following Regexp ".$self->element()." and now \$self->{_rule} is:\n", $self->{_rule}->dumpHeir(), "\n\n") if $Debug;
58 #print ("Parse::RandGen::Regexp::new(): Finished parsing the following Regexp ".$self->element()." and now \$self->{_rule} is:\n", Data::Dumper->Dump([$self->{_rule}])) if $Debug;
59 }
60  
61 0 ▶sub dump {
Subroutine dump: not called CC=2 SCAR=17.9
Pod undocumented
62 0 ▶ my $self = shift or confess ("%Error: Cannot call without a valid object!");
Branch: 1 branch
BranchTrueFalseTotal
my $self = shift() or confess("%Error: Cannot call without a valid object!") 0 0 0
63 0 my $delimiter = "'";
64 0 my $output = $self->element();
65 0 $output =~ s/($delimiter)/\\$1/gs; # First, escape the delimiter (compiled regex is devoid of a specific delimiter)
66 0 $output = "m${delimiter}${output}${delimiter}";
67 0 return $output;
68 }
69  
70 202 ▶sub pick {
Subroutine pick: called CC=4 SCAR=15.2
Pod documented
71 202 ▶ my $self = shift or confess ("%Error: Cannot call without a valid object!");
Branch: 1 branch
BranchTrueFalseTotal
my $self = shift() or confess("%Error: Cannot call without a valid object!") 202 0 202
72 202 my %args = ( match=>1, # Default is to pick matching data
73 captures=>{ }, # Captures that are being explicitly specified
74 @_ );
75 202 my $vals = { };
76 202 foreach my $cap (keys %{$args{captures}}) {
77 0 ▶ my $ruleRef = $self->capture($cap)
Branch: 1 branch
BranchTrueFalseTotal
my $ruleRef = $self->capture($cap) or confess("%Error: Regexp::pick(): Unknown capture field ($cap)!\n") 0 0 0
78 or confess("%Error: Regexp::pick(): Unknown capture field ($cap)!\n");
79 0 $vals->{$ruleRef} = $args{captures}{$cap};
80 }
81 202 delete $args{captures};
82 202 my $val = $self->{_rule}->pick(%args, vals=>$vals);
83 202 if (0) {
84 my $elem = $self->element();
85 print ("Parse::RandGen::Regexp($elem)::pick(match=>$args{match}) with value of ", $self->dumpVal($val), "\n");
86 }
87 202 return($val);
88 }
89  
90 0 ▶sub numCaptures {
Subroutine numCaptures: not called CC=3 SCAR=24.8
Pod documented
91 0 ▶ my $self = shift or confess ("%Error: Cannot call without a valid object!");
Branch: 1 branch
BranchTrueFalseTotal
my $self = shift() or confess("%Error: Cannot call without a valid object!") 0 0 0
92 0 ▶ return 0 unless defined($self->{_captureList});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_captureList"} 0 0 0
93 0 my @caps = @{$self->{_captureList}};
94 0 return ($#caps + 1);
95 }
96  
97 0 ▶sub capture {
Subroutine capture: not called CC=10 SCAR=47.0
Pod documented
98 0 ▶ my $self = shift or confess ("%Error: Cannot call without a valid object!");
Branch: 1 branch
BranchTrueFalseTotal
my $self = shift() or confess("%Error: Cannot call without a valid object!") 0 0 0
99 0 my $capture = shift;
100 0 ▶ defined($capture) and ($capture =~ m/^(\d+)|([a-z]\w*)$/i)
Branch: 2 branches
BranchTrueFalseTotal
defined $capture and $capture =~ /^(\d+)|([a-z]\w*)$/i or confess('%Error: Capture identifier of "' . (defined $capture ? $capture : "[undef]") . qq[" is not valid!\n]) 0 0 0
defined $capture ? : 0 0 0
Condition0%0/3
defined $capture and $capture =~ /^(\d+)|([a-z]\w*)$/i
!ll&&!rl&&r
000
MC/DC0%0/2
defined $capture and $capture =~ /^(\d+)|([a-z]\w*)$/i
defined $capture $capture =~ /^(\d+)|([a-z]\w*)$/i
Truth table0%0/3
A and B
A= defined $captureB= $capture =~ /^(\d+)|([a-z]\w*)$/i
ABresult
0X0
100
111
101 or confess("%Error: Capture identifier of \"".(defined($capture)?$capture:"[undef]")."\" is not valid!\n");
102 0 my $num = $1;
103 0 my $name = $2;
104  
105 0 ▶ if (defined($num)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $num) { } 0 0 0
106 0 my $numCaptures = $self->numCaptures();
107 0 ▶ ($num >= 1) and ($num <= $numCaptures)
Branch: 1 branch
BranchTrueFalseTotal
$num >= 1 and $num <= $numCaptures or confess("%Error: Regexp::capture(): Capture number $num is invalid (only captures 1..$numCaptures exist for this Regexp)!\n") 0 0 0
Condition0%0/3
$num >= 1 and $num <= $numCaptures
!ll&&!rl&&r
000
MC/DC0%0/2
$num >= 1 and $num <= $numCaptures
$num >= 1 $num <= $numCaptures
Truth table0%0/3
A and B
A= $num >= 1B= $num <= $numCaptures
ABresult
0X0
100
111
108 or confess("%Error: Regexp::capture(): Capture number $num is invalid (only captures 1..$numCaptures exist for this Regexp)!\n");
109 0 return $self->{_captureList}[$num-1];
110 } else {
111 0 ▶ defined($self->{_captureNames}) and defined($self->{_captureNames}{$name})
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"_captureNames"} and defined $self->{"_captureNames"}{$name} or confess(qq[%Error: Regexp::capture(): Cannot find named capture "$name"!\n]) 0 0 0
Condition0%0/3
defined $self->{"_captureNames"} and defined $self->{"_captureNames"}{$name}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"_captureNames"} and defined $self->{"_captureNames"}{$name}
defined $self->{"_captureNames"} defined $self->{"_captureNames"}{$name}
Truth table0%0/3
A and B
A= defined $self->{"_captureNames"}B= defined $self->{"_captureNames"}{$name}
ABresult
0X0
100
111
112 or confess("%Error: Regexp::capture(): Cannot find named capture \"$name\"!\n");
113 0 return $self->{_captureNames}{$name};
114 }
115 }
116  
117 0 ▶sub nameCapture {
Subroutine nameCapture: not called CC=8 SCAR=42.8
Pod documented
118 0 ▶ my $self = shift or confess ("%Error: Cannot call without a valid object!");
Branch: 1 branch
BranchTrueFalseTotal
my $self = shift() or confess("%Error: Cannot call without a valid object!") 0 0 0
119 0 my %args = @_; # "capture# => name" pairs
120 0 ▶ $self->{_captureNames} = { } unless defined($self->{_captureNames});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_captureNames"} 0 0 0
121 0 foreach my $capNum (keys %args) {
122 0 ▶ defined($capNum) and ($capNum =~ m/\d+/)
Branch: 1 branch
BranchTrueFalseTotal
defined $capNum and $capNum =~ /\d+/ or confess("%Error: Regexp::nameCapture(): Capture number specified is invalid ($capNum)!\n") 0 0 0
Condition0%0/3
defined $capNum and $capNum =~ /\d+/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $capNum and $capNum =~ /\d+/
defined $capNum $capNum =~ /\d+/
Truth table0%0/3
A and B
A= defined $capNumB= $capNum =~ /\d+/
ABresult
0X0
100
111
123 or confess("%Error: Regexp::nameCapture(): Capture number specified is invalid ($capNum)!\n");
124 0 my $numCaptures = $self->numCaptures();
125 0 ▶ ($capNum >= 1) and ($capNum <= $numCaptures)
Branch: 1 branch
BranchTrueFalseTotal
$capNum >= 1 and $capNum <= $numCaptures or confess("%Error: Regexp::nameCapture(): Cannot name capture number $capNum (only captures 1..$numCaptures exist for this Regexp)!\n") 0 0 0
Condition0%0/3
$capNum >= 1 and $capNum <= $numCaptures
!ll&&!rl&&r
000
MC/DC0%0/2
$capNum >= 1 and $capNum <= $numCaptures
$capNum >= 1 $capNum <= $numCaptures
Truth table0%0/3
A and B
A= $capNum >= 1B= $capNum <= $numCaptures
ABresult
0X0
100
111
126 or confess("%Error: Regexp::nameCapture(): Cannot name capture number $capNum (only captures 1..$numCaptures exist for this Regexp)!\n");
127  
128 0 my $ruleName = $args{$capNum};
129 0 my $rule = $self->{_captureList}[$capNum];
130 0 $rule->{_name} = $ruleName; # Name the rule (does not get registered with the grammar - is that OK?)
131 0 $self->{_captureNames}{$ruleName} = $rule; # For lookup within the Regexp object via "capture()" function
132 }
133 }
134  
135 # YAPE::Regex elements that are supported as CharClass objects
136 %_Yterm = (
137 2 ▶ "YAPE::Regex::class" => sub{ my $y=shift; return ( $y->{NEG} . $y->{TEXT} ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
138 0 ▶ "YAPE::Regex::slash" => sub{ my $y=shift; return ($y->text()); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
139 1 ▶ "YAPE::Regex::macro" => sub{ my $y=shift; return ($y->text()); },
Subroutine __ANON__: called CC=1 SCAR=0.0
140 0 ▶ "YAPE::Regex::oct" => sub{ my $y=shift; return ($y->text()); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
141 0 ▶ "YAPE::Regex::hex" => sub{ my $y=shift; return ($y->text()); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
142 0 ▶ "YAPE::Regex::utf8hex" => sub{ my $y=shift; return ($y->text()); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
143 0 ▶ "YAPE::Regex::ctrl" => sub{ my $y=shift; return ($y->text()); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
144 0 ▶ "YAPE::Regex::named" => sub{ my $y=shift; return ($y->text()); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
145 0 ▶ "YAPE::Regex::any" => sub{ my $y=shift; return ($y->text()); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
146 4 );
147  
148 18 ▶sub _parseRegexp {
Subroutine _parseRegexp: called CC=37 SCAR=45.1
149 18 ▶ my $self = shift or confess ("%Error: Cannot call without a valid object!");
Branch: 1 branch
BranchTrueFalseTotal
my $self = shift() or confess("%Error: Cannot call without a valid object!") 18 0 18
150 18 my $yIter = shift; # YAPE::Regex object iterator
151 18 ▶ my $curRef = shift or confess(); # Current position in Condition ($self) object
Branch: 1 branch
BranchTrueFalseTotal
my $curRef = shift() or confess() 18 0 18
152 18 my %cur = %$curRef; # Make a local copy of current state
153  
154 18 my $yType = ref($yIter);
155 18 ▶ if ($yType eq "YAPE::Regex::group") {
Branch: 1 branch
BranchTrueFalseTotal
if ($yType eq "YAPE::Regex::group") 5 13 18
156 0 foreach my $switch (split //, $yIter->{ON}) { delete $cur{off}{$switch}; $cur{on}{$switch} = 1; }
157 5 foreach my $switch (split //, $yIter->{OFF}) { delete $cur{on}{$switch}; $cur{off}{$switch} = 1; }
158 }
159  
160 18 ▶ if ( ($yType eq "YAPE::Regex::group")
Branch: 2 branches
BranchTrueFalseTotal
if ($yType eq 'YAPE::Regex::group' or $yType eq 'YAPE::Regex::capture') { } 8 10 18
elsif ($yType eq 'YAPE::Regex::whitespace' or $yType eq 'YAPE::Regex::anchor' or $yType eq 'YAPE::Regex::comment') { } 0 10 10
Condition100%3/3
$yType eq "YAPE::Regex::group" or $yType eq "YAPE::Regex::capture"
l!l&&r!l&&!r
5310
MC/DC100%2/2
$yType eq "YAPE::Regex::group" or $yType eq "YAPE::Regex::capture"
$yType eq "YAPE::Regex::group" $yType eq "YAPE::Regex::capture"
Truth table100%3/3
A or B
A= $yType eq "YAPE::Regex::group"B= $yType eq "YAPE::Regex::capture"
ABresult
1X1
011
000
161 || ($yType eq "YAPE::Regex::capture") ){
162 8 ▶ defined($yIter->{NGREED}) or confess("$yType type does not have NGREED implemented!\n");
Branch: 1 branch
BranchTrueFalseTotal
defined $yIter->{"NGREED"} or confess("$yType type does not have NGREED implemented!\n") 8 0 8
163 8 ▶ defined($yIter->{QUANT}) or confess("$yType type does not have QUANT implemented!\n");
Branch: 1 branch
BranchTrueFalseTotal
defined $yIter->{"QUANT"} or confess("$yType type does not have QUANT implemented!\n") 8 0 8
164  
165 8 my @yList = @{$yIter->{CONTENT}};
166 8 foreach my $elemIter (@yList) {
167 15 my $elemType = ref($elemIter);
168 15 ▶ if ($elemType eq "YAPE::Regex::alt") {
Branch: 2 branches
BranchTrueFalseTotal
if ($elemType eq 'YAPE::Regex::alt') { } 2 13 15
elsif ($elemType eq 'YAPE::Regex::group' or $elemType eq 'YAPE::Regex::capture') { } 3 10 13
169 2 $cur{rule}->addProd($cur{prod} = Parse::RandGen::Production->new());
170 ▶ } elsif ( ($elemType eq "YAPE::Regex::group")
Condition66%2/3
$elemType eq "YAPE::Regex::group" or $elemType eq "YAPE::Regex::capture"
l!l&&r!l&&!r
0310
MC/DC50%1/2
$elemType eq "YAPE::Regex::group" or $elemType eq "YAPE::Regex::capture"
$elemType eq "YAPE::Regex::group" $elemType eq "YAPE::Regex::capture"
Truth table66%2/3
A or B
A= $elemType eq "YAPE::Regex::group"B= $elemType eq "YAPE::Regex::capture"
ABresult
1X1
011
000
171 || ($elemType eq "YAPE::Regex::capture") ) {
172  
173 3 ▶ defined($elemIter->{NGREED}) or confess("$elemType type does not have NGREED implemented!\n");
Branch: 1 branch
BranchTrueFalseTotal
defined $elemIter->{"NGREED"} or confess("$elemType type does not have NGREED implemented!\n") 3 0 3
174 3 ▶ defined($elemIter->{QUANT}) or confess("$elemType type does not have QUANT implemented!\n");
Branch: 1 branch
BranchTrueFalseTotal
defined $elemIter->{"QUANT"} or confess("$elemType type does not have QUANT implemented!\n") 3 0 3
175 3 my $greedy = !$elemIter->{NGREED};
176 3 my $quant = $elemIter->{QUANT};
177  
178 3 my $prod = Parse::RandGen::Production->new();
179 3 my $rule = Parse::RandGen::Rule->new();
180 3 $rule->addProd($prod);
181 3 ▶ if ($elemType eq "YAPE::Regex::capture") {
Branch: 1 branch
BranchTrueFalseTotal
if ($elemType eq "YAPE::Regex::capture") 3 0 3
182 3 ▶ $self->{_captureList} = [ ] unless ($self->{_captureList});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_captureList"} 3 0 3
183 3 push(@{$self->{_captureList}}, $rule);
184 }
185  
186 #print "Creating a subrule (elem=>$rule, quant=>$quant, greedy=>$greedy)\n" if $Debug;
187 3 $cur{prod}->addCond(Parse::RandGen::Subrule->new($rule, quant=>$quant, greedy=>$greedy));
188  
189 3 my %next = %cur;
190 3 $next{rule} = $rule;
191 3 $next{prod} = $prod;
192 3 $self->_parseRegexp($elemIter, \%next);
193 } else {
194 10 $self->_parseRegexp($elemIter, \%cur);
195 }
196 }
197 ▶ } elsif ( ($yType eq "YAPE::Regex::whitespace")
Condition33%2/6
$yType eq "YAPE::Regex::whitespace" or $yType eq "YAPE::Regex::anchor" or $yType eq "YAPE::Regex::comment"
l!l&&r!l&&!r
0010
$yType eq "YAPE::Regex::whitespace" or $yType eq "YAPE::Regex::anchor"
l!l&&r!l&&!r
0010
MC/DC0%0/3
$yType eq "YAPE::Regex::whitespace" or $yType eq "YAPE::Regex::anchor" or $yType eq "YAPE::Regex::comment"
$yType eq "YAPE::Regex::whitespace" $yType eq "YAPE::Regex::anchor" $yType eq "YAPE::Regex::comment"
Truth table25%1/4
A or B or C
A= $yType eq "YAPE::Regex::whitespace"B= $yType eq "YAPE::Regex::anchor"C= $yType eq "YAPE::Regex::comment"
ABCresult
1XX1
01X1
0011
0000
198 || ($yType eq "YAPE::Regex::anchor")
199 || ($yType eq "YAPE::Regex::comment")
200 ){
201 # Do nothing, simply ignore these objects
202 } else {
203 10 ▶ defined($yIter->{NGREED}) or confess("$yType type does not have NGREED implemented!\n");
Branch: 1 branch
BranchTrueFalseTotal
defined $yIter->{"NGREED"} or confess("$yType type does not have NGREED implemented!\n") 10 0 10
204 10 ▶ defined($yIter->{QUANT}) or confess("$yType type does not have QUANT implemented!\n");
Branch: 1 branch
BranchTrueFalseTotal
defined $yIter->{"QUANT"} or confess("$yType type does not have QUANT implemented!\n") 10 0 10
205 10 my $greedy = !$yIter->{NGREED};
206 10 my $quant = $yIter->{QUANT};
207 10 my @charClasses = ();
208  
209 10 ▶ if (($yType eq "YAPE::Regex::text") && $cur{off}{i} && !$quant) {
Branch: 2 branches
BranchTrueFalseTotal
if ($yType eq 'YAPE::Regex::text' and $cur{'off'}{'i'} and not $quant) { } 7 3 10
elsif ($yType eq 'YAPE::Regex::alt') { } 0 3 3
Condition66%4/6
$yType eq "YAPE::Regex::text" and $cur{"off"}{"i"} and not $quant
!ll&&!rl&&r
307
$yType eq "YAPE::Regex::text" and $cur{"off"}{"i"}
!ll&&!rl&&r
307
MC/DC33%1/3
$yType eq "YAPE::Regex::text" and $cur{"off"}{"i"} and not $quant
$yType eq "YAPE::Regex::text" $cur{"off"}{"i"} not $quant
Truth table50%2/4
A and B and not(C)
A= $yType eq "YAPE::Regex::text"B= $cur{"off"}{"i"}C= not $quant
ABCresult
0XX0
10X0
1100
1111
210 7 my $cond = Parse::RandGen::Literal->new($yIter->{TEXT}, greedy => $greedy);
211 7 $cur{prod}->addCond($cond);
212 } elsif ($yType eq "YAPE::Regex::alt") {
213 0 confess("Not expecting a $yType here!\n");
214 } else {
215 3 ▶ if ($yType eq "YAPE::Regex::text") {
Branch: 2 branches
BranchTrueFalseTotal
if ($yType eq 'YAPE::Regex::text') { } 0 3 3
elsif (exists $Parse::RandGen::Regexp::_Yterm{$yType}) { } 3 0 3
216 # Case-insensitive text
217 0 my $text = $yIter->{TEXT};
218 0 ▶ for (my $offset=0; $offset < length($text); $offset++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset < length $text) 0 0 0
219 0 my $char = substr($text, $offset, 1);
220 0 my $nchar = lc($char);
221 0 ▶ $nchar = uc($char) unless ($nchar ne $char);
Branch: 1 branch
BranchTrueFalseTotal
unless $nchar ne $char 0 0 0
222 0 ▶ if (($nchar eq $char) || $cur{off}{i}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nchar eq $char or $cur{'off'}{'i'}) { } 0 0 0
Condition0%0/3
$nchar eq $char or $cur{"off"}{"i"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$nchar eq $char or $cur{"off"}{"i"}
$nchar eq $char $cur{"off"}{"i"}
Truth table0%0/3
A or B
A= $nchar eq $charB= $cur{"off"}{"i"}
ABresult
1X1
011
000
223 #print ("Parse::RandGen::Regexp: creating a case-sensitive CharClass for letter $offset of the literal \"$text\" ([$char])\n");
224 0 push @charClasses, "$char";
225 } else {
226 #print ("Parse::RandGen::Regexp: creating a case-insenstive CharClass for letter $offset of the literal \"$text\" ([$char$nchar])\n");
227 0 push @charClasses, "$char$nchar";
228 }
229 }
230 } elsif (exists($_Yterm{$yType})) {
231 3 @charClasses = ( &{$_Yterm{$yType}}($yIter) );
232 } else {
233 0 confess("%Error: YAPE type unknown or unsupported (\"$yType\")!");
234 }
235  
236 3 foreach my $cclass (@charClasses) {
237 3 my $on = join('', sort(keys(%{$cur{on}})));
238 3 my $off = join('', sort(keys(%{$cur{off}})));
239 3 my $charClassRE;
240 3 ▶ if ($yType eq "YAPE::Regex::any") {
Branch: 1 branch
BranchTrueFalseTotal
if ($yType eq 'YAPE::Regex::any') { } 0 3 3
241 0 $charClassRE = qr/(?$on-$off:$cclass)/; # Cannot match the . character in [ ]
242 } else {
243 #print "Parse::RandGen::Regexp: cclass is $cclass\n";
244 3 ▶ if (!$on && ($off eq "imsx")) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $on and $off eq 'imsx') { } 3 0 3
Condition33%1/3
not $on and $off eq "imsx"
!ll&&!rl&&r
003
MC/DC0%0/2
not $on and $off eq "imsx"
not $on $off eq "imsx"
Truth table33%1/3
not(A) and B
A= not $onB= $off eq "imsx"
ABresult
0X0
100
111
245 3 $charClassRE = qr/[$cclass]/; # default
246 } else {
247 0 $charClassRE = qr/(?$on-$off:[$cclass])/;
248 }
249 #print "Parse::RandGen::Regexp: cclass charClassRE is $charClassRE\n";
250 }
251
252 3 my $cond = Parse::RandGen::CharClass->new($charClassRE, quant=>$quant, greedy=>$greedy);
253 0 $cur{prod}->addCond($cond);
254 }
255 }
256 }
257 }
258  
259 ######################################################################
260 #### Package return
261 4 1;
262 __END__
« RandGen/Production.pm ↑ Summary RandGen/Grammar.pm »