Parser.pm

filter: Statementstmt 72.4% 218 / 301 Branchbran 66.6% 104 / 156 Conditioncond 45.8% 11 / 24 MC/DCmcdc 40.0% 6 / 15 Subroutinesub 70.0% 21 / 30 Podpod 0.0% 0 / 9 totaltotal 67.2% 360 / 535 CC 88 SCAR 25.9
CC
88
Cov
69%
_comment
56.0
LoadGraph
30.0
_nextSpace
20.0
CRAP 13.4
« Path.pm ↑ Summary
1 # Ogdl.pm
2 # author: R.Veen
3 # license: same as the rest of OGDL (zlib)
4 # see: www.ogdl.org
5 # date: 12 june 2003
6  
7 # 2010-11-11 Hui Zhou:
8 # Comma (,) only resets one level up
9 # Semicolon (;) resets to beginning of the line (or group)
10 # Semicolon is the new metachar that we have discussed in OGDL mailinglist but never got agreed.
11  
12 package OGDL::Parser;
13  
14 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 our $VERSION = '0.02';
17  
18 2 ▶use OGDL::Graph;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 0 ▶sub LoadGraph{
Subroutine LoadGraph: not called CC=5 SCAR=34.0
Pod undocumented
21 0 my ($name)=@_;
22 0 ▶ if(-T "$name.gm"){
Branch: 1 branch
BranchTrueFalseTotal
if (-T "$name.gm") 0 0 0
23 0 return m4ToGraph("$name.gm");
24 }
25 0 ▶ if(-T "$name.g"){
Branch: 1 branch
BranchTrueFalseTotal
if (-T "$name.g") 0 0 0
26 0 return fileToGraph("$name.g");
27 }
28 0 ▶ if(-T $name){
Branch: 1 branch
BranchTrueFalseTotal
if (-T $name) 0 0 0
29 0 return fileToGraph($name);
30 }
31 0 ▶ if(-d $name){
Branch: 1 branch
BranchTrueFalseTotal
if (-d $name) 0 0 0
32 0 return dirToGraph($name);
33 }
34 0 return undef;
35 }
36  
37 0 ▶sub dirToGraph{
Subroutine dirToGraph: not called CC=4 SCAR=26.4
Pod undocumented
38 0 my ($dir)=@_;
39 0 my $topdir=`pwd`;
40 0 ▶ if(-d $dir){
Branch: 1 branch
BranchTrueFalseTotal
if (-d $dir) 0 0 0
41 0 chdir $dir;
42 0 my $g=OGDL::Graph->new($dir);
43 0 ▶ my @dirlist=sort glob("*");
Subroutine BEGIN: called CC=1 SCAR=0.2
44 0 foreach(@dirlist){
45 0 ▶ if(-d $_){
Branch: 1 branch
BranchTrueFalseTotal
if (-d $_) { } 0 0 0
46 0 my $subg=dirToGraph($_);
47 0 $g->addNode($subg);
48 }
49 else{
50 0 $g->addGraph($_);
51 }
52 }
53 # print "chdir $cwd";
54 0 chdir "..";
55 0 return $g;
56 }
57 0 return undef;
58 }
59  
60 sub fileToGraph
61 3 ▶{
Subroutine fileToGraph: called CC=2 SCAR=7.0
Pod undocumented
62 3 ▶ open my $input, $_[0] or return undef;
Branch: 1 branch
BranchTrueFalseTotal
open my $input, $_[0] or return undef 3 0 3
63 3 my $parser=OGDL::Parser->new($_[0]);
64 3 $parser->read($input);
65 3 my $g=$parser->parse;
66 3 return $g;
67 }
68  
69 0 ▶sub m4ToGraph{
Subroutine m4ToGraph: not called CC=2 SCAR=17.9
Pod undocumented
70 0 ▶ open my $input, "m4 $_[0] |" or return undef;
Branch: 1 branch
BranchTrueFalseTotal
open my $input, "m4 $_[0] |" or return undef 0 0 0
71 0 my $parser=OGDL::Parser->new($_[0]);
72 0 $parser->read($input);
73 0 my $g=$parser->parse;
74 0 return $g;
75 }
76  
77 # this routine accepts string
78 sub stringToGraph
79 0 ▶{
Subroutine stringToGraph: not called CC=1 SCAR=6.9
Pod undocumented
80 0 my $parser=OGDL::Parser->new("string");
81 0 $parser->append($_[0]);
82 0 my $g=$parser->parse;
83 0 return $g;
84 }
85  
86 # $ogdl->read(*FILEHANDL)
87 3 ▶sub read{
Subroutine read: called CC=3 SCAR=11.0
Pod undocumented
88 3 my $r_ogdl= $_[0];
89 3 my $input =$_[1];
90 3 my $lines="";
91 # my $tabexpand=' 'x8;
92 3 my $tabwidth=8;
93 3 my $i;
94 3 ▶ while(<$input>){
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $input)) 150 3 153
95 # print;
96 # s/#.*$/\n/; # Remove any trailing comments
97 150 s/\r\n/\n/; #convert the newline
98 150 s/\s*$/\n/; # Remove any trailing spaces
99 # next if ( /^$/ ); # Skip empty lines
100 # s/\t/$tabexpand/g; # Expand tabs
101 150 $i=index $_, "\t";
102 150 ▶ while($i>=0){
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 6 150 156
103 6 my $n=$tabwidth-$i%$tabwidth;
104 6 substr($_,$i,1)=' 'x$n;
105 6 $i+=$n;
106 6 $i=index $_, ' ',$i;
107 }
108 150 $lines = $lines . $_;
109 }
110 3 $$r_ogdl{"text"}=$lines;
111 }
112  
113 0 ▶sub append{
Subroutine append: not called CC=1 SCAR=6.9
Pod undocumented
114 0 my $r_ogdl=$_[0];
115 0 $$r_ogdl{"text"}=$$r_ogdl{"text"}.$_[1];
116 }
117  
118 sub new
119 3 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
120 3 my ($class,$rootname)=@_;
121 3 my $tempg;
122 3 $tempg=OGDL::Graph->new($rootname);
123 3 my $p = {
124 text => "",
125 ix => 0,
126 level => 0,
127 indentation => [ () ],
128 line_level => -1,
129 groups => [ () ],
130 ixgroup => 0,
131 # allowgoback =>0, #temperary hack to decide whether comar will go back one indent level, not necessary with opposite precedence
132 g => undef
133 };
134 3 $p->{g}[0]=$tempg;
135 3 return bless $p, $class;
136 }
137  
138 sub parse
139 3 ▶{
Subroutine parse: called CC=2 SCAR=6.9
Pod undocumented
140 3 my $p = shift;
141 3 ▶ while (_line($p)) { }
Branch: 1 branch
BranchTrueFalseTotal
if (_line($p)) 100 3 103
142 3 return $p->{g}[0];
143 }
144  
145 sub _line
146 103 ▶{
Subroutine _line: called CC=10 SCAR=23.0
147 103 my $p = shift;
148  
149 # print "[" . substr ($p->{text},$p->{ix},20) . "]\n" ;
150 103 my $i = _space($p);
151 103 ▶ if (_newline($p)) { return 1 };
Branch: 1 branch
BranchTrueFalseTotal
if (_newline($p)) 5 98 103
152 98 ▶ if (_eos($p)) { return 0 };
Branch: 1 branch
BranchTrueFalseTotal
if (_eos($p)) 3 95 98
153 #print "line: lev(at entry) " . $p->{line_level} . "\n";
154 #print "line ind[]= ";
155 #$ind = $p->{indentation};
156 #for (@$ind) {
157 #print $_ . " ";
158 #}
159 #print ", i=$i, current ind=$p->{indentation}[$p->{line_level}];, line_level=$p->{line_level}\n";
160  
161  
162 95 ▶ if ( $p->{line_level} == -1 ) { #start
Branch: 2 branches
BranchTrueFalseTotal
if ($p->{'line_level'} == -1) { } 3 92 95
elsif ($i > $p->{'indentation'}[$p->{'line_level'}]) { } 35 57 92
163 3 $p->{indentation}[0] = $i;
164 3 $p->{line_level} = 0;
165 }
166 elsif ( $i > $p->{indentation}[$p->{line_level}] ) { #indentation increased
167 35 $p->{line_level}++;
168 35 $p->{indentation}[$p->{line_level}] = $i;
169 }
170 else {
171 57 ▶ if ( $i < $p->{indentation}[$p->{line_level}] ) {#indentation decreased
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $p->{"indentation"}[$p->{"line_level"}]) 24 33 57
172 24 ▶ while ( $p->{line_level} > 0) { #find the parent or brother line_level
Branch: 1 branch
BranchTrueFalseTotal
if ($p->{"line_level"} > 0) 46 8 54
173 46 ▶ if ( $i >= $p->{indentation}[$p->{line_level}] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= $p->{"indentation"}[$p->{"line_level"}]) 16 30 46
174 16 last;
175 }
176 30 $p->{line_level}--;
177 }
178 }
179 }
180 95 $p->{level} = $p->{line_level}; #current level
181 95 $p->{groups}[$p->{ixgroup}]=$p->{level};
182 95 $p->{allowgoback}=0;
183  
184 # print "\ncurrent level is $p->{level}\n";
185  
186  
187 # print "line: lev(after) " . $p->{line_level} . "\n";
188  
189 95 ▶ while ( _node($p) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_node($p)) 166 95 261
190 166 _space($p); #Remove the trailing spaces
191 }
192
193 95 ▶ return _eos($p) ? 0:1;
Branch: 1 branch
BranchTrueFalseTotal
_eos($p) ? : 0 95 95
194 }
195  
196 sub _node
197 261 ▶{
Subroutine _node: called CC=15 SCAR=29.0
198 # print "get node\n";
199 261 my $p = shift;
200 0 ▶ if ( _eos($p) ) { return undef; }
Branch: 1 branch
BranchTrueFalseTotal
if (_eos($p)) 0 261 261
201 261 my $s=undef;
202 261 my $c=_peek($p);
203 261 ▶ if($c eq '('){
Branch: 9 branches
BranchTrueFalseTotal
if ($c eq '(') { } 6 255 261
elsif ($c eq ')') { } 6 249 255
elsif ($c eq ';') { } 5 244 249
elsif ($c eq ',') { } 18 226 244
elsif ($c eq q['] or $c eq '"') { } 3 223 226
elsif ($c eq '\\') { } 1 222 223
elsif ($c eq "\n") { } 95 127 222
elsif ($c eq '#') { } 0 127 127
elsif ($c eq 'w') { } 127 0 127
204 6 _getc($p);
205 6 $p->{ixgroup}++;
206 6 $p->{groups}[$p->{ixgroup}] = $p->{level};
207 # $p->{allowgoback}=0;
208 6 return 1;
209 }
210 elsif($c eq ')'){
211 6 _getc($p);
212 6 $p->{level}=$p->{groups}[$p->{ixgroup}]+1;
213 # $p->{allowgoback}=1;
214 6 $p->{ixgroup}--;
215 6 ▶ if ($p->{ixgroup} < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($p->{"ixgroup"} < 0) 0 6 6
216 0 { _fatal("Unmatched ')'"); }
217 6 return 1;
218 }
219 elsif($c eq ';'){
220 5 _getc($p);
221 5 $p->{level} = $p->{groups}[$p->{ixgroup}];
222 # if($p->{allowgoback}){
223 # $p->{level}--; #exception: , at beginning
224 # $p->{allowgoback}=0;
225 # }
226 5 return 1;
227 }
228 elsif($c eq ','){
229 18 _getc($p);
230 18 $p->{level}--; #exception: , at beginning
231 18 return 1;
232 }
233 ▶ elsif($c eq "'" || $c eq '"'){
Condition66%2/3
$c eq "'" or $c eq "\""
l!l&&r!l&&!r
03223
MC/DC50%1/2
$c eq "'" or $c eq "\""
$c eq "'" $c eq "\""
Truth table66%2/3
A or B
A= $c eq "'"B= $c eq "\""
ABresult
1X1
011
000
234 3 $s=_quoted($p, '\'');
235 }
236 elsif($c eq '\\'){
237 1 $s=_block($p);
238 }
239 elsif($c eq "\n"){
240 95 $s=_newline($p);
241 95 return 0;
242 }
243 elsif($c eq '#'){
244 0 $s=_comment($p);
245 0 return 0;
246 }
247 elsif($c eq 'w'){
248 127 $s = _word($p);
249 }
250 else{
251 # print "($c)" if defined $c;
252 0 return undef;
253 }
254  
255 131 ▶ if (defined $s) { # what if $s=""?
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 131 0 131
256 # print $s;
257 131 _addNode($p,$s);
258 131 $p->{level}++;
259 # $p->{allowgoback}=1;
260 131 return 1;
261 }
262
263 #should never reach here.
264 0 ▶ if(! _newline($p)){
Branch: 1 branch
BranchTrueFalseTotal
unless (_newline($p)) 0 0 0
265 0 print "Strange? not newline, what else could it be?\n";
266 }
267 0 return 0;
268 }
269  
270 sub _newline
271 204 ▶{
Subroutine _newline: called CC=3 SCAR=11.0
272 204 my $p = shift;
273 204 my $c = _getc($p);
274 # print "newline $p->{ix} [$c]\n";
275 204 ▶ if (!defined $c ) { return 0; };
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $c) 3 201 204
276 201 ▶ if ( $c eq "\n" ) { return 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "\n") 104 97 201
277 97 _ungetc($p);
278 97 return 0;
279 }
280  
281 sub _eos
282 472 ▶{
Subroutine _eos: called CC=2 SCAR=6.9
283 472 my $p = shift;
284 472 ▶ if ($p->{ix} == -1) { return 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($p->{"ix"} == -1) 3 469 472
285 469 return 0;
286 }
287  
288 sub _space
289 284 ▶{
Subroutine _space: called CC=2 SCAR=6.9
290 284 my $p = shift;
291 284 my $lines = $p->{text};
292 284 my $ix = $p->{ix};
293 284 my $c;
294 284 my $n=0;
295
296 284 ▶ while (_isSpaceChar($c = _getc($p))) {
Branch: 1 branch
BranchTrueFalseTotal
if (_isSpaceChar($c = _getc($p))) 638 284 922
297 638 $n++;
298 }
299
300 284 _ungetc($p);
301  
302 # print "space [$n]\n";
303 284 return $n;
304 }
305  
306  
307 0 ▶sub _comment{#it will take out the new line as well
Subroutine _comment: not called CC=7 SCAR=40.3
308 # print "trying comment\n";
309 0 my $p=$_[0];
310 0 ▶ if(_eos($p)){return undef;}
Branch: 1 branch
BranchTrueFalseTotal
if (_eos($p)) 0 0 0
311 0 my $s="";
312 0 my $c=_getc($p);
313 0 ▶ if($c eq '#'){
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq '#') { } 0 0 0
314 0 $c=_getc($p);
315 0 ▶ if($c ne ' ' && $c ne "\t"){_ungetc($p);_ungetc($p);return undef;}
Branch: 1 branch
BranchTrueFalseTotal
if ($c ne " " and $c ne "\t") 0 0 0
Condition0%0/3
$c ne " " and $c ne "\t"
!ll&&!rl&&r
000
MC/DC0%0/2
$c ne " " and $c ne "\t"
$c ne " " $c ne "\t"
Truth table0%0/3
A and B
A= $c ne " "B= $c ne "\t"
ABresult
0X0
100
111
316 0 ▶ while(defined $c){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c) 0 0 0
317 0 ▶ if($c eq "\n"){
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "\n") { } 0 0 0
318 # _ungetc($p);
319 0 last;
320 }
321 else{
322 0 $s=$s.$c;
323 }
324 0 $c=_getc($p);
325 }
326 }
327 0 else{ _ungetc($p);return undef;}
328 # print $s;
329 0 return $s;
330 }
331 #start with a quote with the beginning quote stripped
332 sub _quoted
333 3 ▶{
Subroutine _quoted: called CC=13 SCAR=26.2
334 3 my ($p, $term) = @_;
335 3 my $lines = $p->{text};
336 3 my $ix = $p->{ix};
337 3 my $s="";
338 3 my $cprev;
339 my $c;
340
341 3 $term=_getc($p);
342 #Omited checking. Make sure its a quote before entering.
343 # what is the last current line indentation
344 3 my $i = $p->{indentation}[$p->{line_level}];
345 3 $i++;#the '"' itself increases the increases by 1
346 3 my $strip=$i;
347 3 ▶ while ( ($c = _getc($p)) || ($c eq '0')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c = _getc($p) or $c eq 0) 2503 0 2503
Condition33%1/3
$c = _getc($p) or $c eq 0
l!l&&r!l&&!r
250300
MC/DC0%0/2
$c = _getc($p) or $c eq 0
$c = _getc($p) $c eq 0
Truth table33%1/3
A or B
A= $c = _getc($p)B= $c eq 0
ABresult
1X1
011
000
348 2503 ▶ if ( ($c eq $term) && !($cprev eq '\\')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq $term and not $cprev eq '\\') { } 3 2500 2503
Condition100%3/3
$c eq $term and not $cprev eq "\\"
!ll&&!rl&&r
249463
MC/DC100%2/2
$c eq $term and not $cprev eq "\\"
$c eq $term not $cprev eq "\\"
Truth table100%3/3
A and not(B)
A= $c eq $termB= not $cprev eq "\\"
ABresult
0X0
100
111
349 3 last;
350 }
351 else {
352 2500 ▶ if($c eq $term){chop $s;} # chop off the '\'
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq $term) 6 2494 2500
353 2500 $cprev=$c;
354 2500 ▶ if($strip<$i && _isSpaceChar($c)){ #continue strip indentation of $s
Branch: 3 branches
BranchTrueFalseTotal
if ($strip < $i and _isSpaceChar($c)) { } 154 2346 2500
elsif ($strip == $i) { } 2343 3 2346
elsif ($strip < $i) { } 3 0 3
Condition100%3/3
$strip < $i and _isSpaceChar($c)
!ll&&!rl&&r
23433154
MC/DC100%2/2
$strip < $i and _isSpaceChar($c)
$strip < $i _isSpaceChar($c)
Truth table100%3/3
A and B
A= $strip < $iB= _isSpaceChar($c)
ABresult
0X0
100
111
355 154 $strip++;
356 }
357 elsif($strip==$i){ #finished strip, use both $s and $s2
358 2343 $s=$s.$c;
359 2343 ▶ if($c eq "\n"){#new line, start strip for the next line
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "\n") 33 2310 2343
360 33 $strip=0;
361 0 ▶ if($cprev eq '\\'){chop;chop;} #the line continuation
Branch: 1 branch
BranchTrueFalseTotal
if ($cprev eq "\\") 0 33 33
362 }
363 }
364 elsif($strip<$i){ #indentation decreased
365 # print "indentation reduced from $i to $strip, current s=[$s]\n";
366 0 ▶ if($c ne "\n"){$i=$strip;}
Branch: 1 branch
BranchTrueFalseTotal
if ($c ne "\n") { } 0 3 3
367 3 else{$strip=0;}
368 3 $s=$s.$c;
369 }
370 }
371 }
372 3 return $s;
373 }
374  
375 sub _block
376 1 ▶{
Subroutine _block: called CC=13 SCAR=26.1
377 1 my $p = $_[0];
378 1 my $c;
379
380 # what is the last current line indentation
381 1 my $i = $p->{indentation}[$p->{line_level}];
382 1 my $s;
383 1 my $is=-1;
384 1 my $j;
385 1 _getc($p);_newline($p); #omited checking. Make sure it is a block before entering.
386 1 while (1) {
387 15 $j = _space($p);
388 # print "j=$j [" . substr ($p->{text},$p->{ix},5) . "]" ;
389 # if less indented and not empty, exit
390 15 ▶ if ($j <= $i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $i) 3 12 15
391 0 ▶ if ( _eos($p) ) { last; }
Branch: 1 branch
BranchTrueFalseTotal
if (_eos($p)) 0 3 3
392 3 ▶ if ( ! _newline($p) ) { last; }
Branch: 1 branch
BranchTrueFalseTotal
if (not _newline($p)) { } 1 2 3
393 2 else { _ungetc($p); } # in CRLF combinations the CR is lost: that's ok !
394 }
395
396 14 ▶ if ($is == -1) { $is = $j; }
Branch: 1 branch
BranchTrueFalseTotal
if ($is == -1) 1 13 14
397 0 ▶ if ( $j > $is ) { $p->{ix} -= ($j-$is); } # XXX ungetting extra spaces
Branch: 1 branch
BranchTrueFalseTotal
if ($j > $is) 0 14 14
398
399 14 ▶ while ( $c = _getc($p) ) { #get a line, that is ended in \n
Branch: 1 branch
BranchTrueFalseTotal
if ($c = _getc($p)) 782 0 782
400 782 ▶ if ($c ne "\r") { $s = $s . $c; }
Branch: 1 branch
BranchTrueFalseTotal
if ($c ne "\r") 782 0 782
401 782 ▶ if ($c eq "\n") { last; }
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "\n") 14 768 782
402 }
403  
404 0 ▶ if ( _eos($p) ) { last; }
Branch: 1 branch
BranchTrueFalseTotal
if (_eos($p)) 0 14 14
405 }
406  
407 1 ▶ if ( ! _eos($p) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (_eos($p)) 1 0 1
408 # $p->{ix} -= $j; # XXX unget spaces
409 1 ▶ while (! _newline($p)){_ungetc($p);}_ungetc($p);#return to the end of last line so _node can return properly
Branch: 1 branch
BranchTrueFalseTotal
unless (_newline($p)) 1 1 2
410 }
411 1 $c=chop $s;
412 1 ▶ while($c=~/[\n \t]/){$c=chop $s;}
Branch: 1 branch
BranchTrueFalseTotal
if ($c =~ /[\n \t]/) 2 1 3
413 1 $s=$s.$c;
414 1 return $s;
415 }
416  
417 0 ▶sub _nextSpace{
Subroutine _nextSpace: not called CC=4 SCAR=30.0
418 0 my $p=shift;
419 0 my $next=substr($p->{"text"},$p->{"ix"},1);
420 0 ▶ if(defined $next && $next eq ' ' || $next eq '\t'){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $next and $next eq ' ' or $next eq '\\t') { } 0 0 0
Condition0%0/6
defined $next and $next eq " " or $next eq "\\t"
l!l&&r!l&&!r
000
defined $next and $next eq " "
!ll&&!rl&&r
000
MC/DC0%0/3
defined $next and $next eq " " or $next eq "\\t"
defined $next $next eq " " $next eq "\\t"
Truth table0%0/5
A and B or C
A= defined $nextB= $next eq " "C= $next eq "\\t"
ABCresult
11X1
0X11
1011
0X00
1000
421 0 return 1;
422 }
423 else {
424 0 return 0;
425 }
426 }
427 369 ▶sub _nextWord{
Subroutine _nextWord: called CC=3 SCAR=11.0
428 369 my $p=shift;
429 369 my $next=substr($p->{"text"},$p->{"ix"},2);
430 369 ▶ if(defined $next && $next!~/^([ \t\r\n\(\);,]|# )/ ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $next and not $next =~ /^([ \t\r\n\(\);,]|# )/) { } 242 127 369
Condition66%2/3
defined $next and not $next =~ /^([ \t\r\n\(\);,]|# )/
!ll&&!rl&&r
0127242
MC/DC50%1/2
defined $next and not $next =~ /^([ \t\r\n\(\);,]|# )/
defined $next not $next =~ /^([ \t\r\n\(\);,]|# )/
Truth table66%2/3
A and not(B)
A= defined $nextB= not $next =~ /^([ \t\r\n\(\);,]|# )/
ABresult
0X0
100
111
431 242 return 1;
432 }
433 else {
434 127 return 0;
435 }
436 }
437 261 ▶sub _peek{
Subroutine _peek: called CC=5 SCAR=16.6
438 261 my $p=shift;
439 261 my $next=substr($p->{"text"},$p->{"ix"},2);
440 261 ▶ if(defined $next){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $next) 261 0 261
441 261 ▶ if($next=~/^(['"\(\);,]|# |\\[\r\n])/ ){
Branch: 1 branch
BranchTrueFalseTotal
if ($next =~ /^(['"\(\);,]|# |\\[\r\n])/) 39 222 261
442 39 return substr($next,0,1);
443 }
444 222 ▶ if($next=~/^[ \t]/ ){
Branch: 1 branch
BranchTrueFalseTotal
if ($next =~ /^[ \t]/) 0 222 222
445 0 return " ";
446 }
447 222 ▶ if($next=~/^[\r\n]/ ){
Branch: 1 branch
BranchTrueFalseTotal
if ($next =~ /^[\r\n]/) { } 95 127 222
448 95 return "\n";
449 }
450 else{
451 127 return 'w';
452 }
453 }
454 0 return undef;
455 }
456  
457 sub _word
458 127 ▶{
Subroutine _word: called CC=2 SCAR=6.9
459 127 my $p = shift;
460 127 my $lines = $p->{text};
461 127 my $ix = $p->{ix};
462 127 my $c;
463 127 my $s="";
464
465 # print "word at ix=$ix?\n";
466 127 ▶ while(_nextWord($p)){
Branch: 1 branch
BranchTrueFalseTotal
if (_nextWord($p)) 242 127 369
467 242 $s=$s. _getc($p);
468 }
469 # while (_isWordChar($c = _getc($p))) {
470 # $s = $s . $c;
471 # }
472 # _ungetc($p);
473 127 return $s;
474 }
475  
476 sub _isSpaceChar
477 1079 ▶{
Subroutine _isSpaceChar: called CC=3 SCAR=11.0
478 1079 ▶ if(defined $_[0]){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0]) 1076 3 1079
479 1076 ▶ if ($_[0] =~ /[ \t]/) { return 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /[ \t]/) 792 284 1076
480 }
481 287 return 0;
482 }
483  
484 sub _isWordChar
485 0 ▶{
Subroutine _isWordChar: not called CC=3 SCAR=24.8
486 0 ▶ if(defined $_[0]){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0]) { } 0 0 0
487 0 ▶ if ($_[0] =~ /[ \t\n\r\(\),;]/) { return 0; }
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /[ \t\n\r\(\),;]/) 0 0 0
488 }
489 else{
490 0 return 0;
491 }
492 0 return 1;
493 }
494  
495 sub _getc
496 4692 ▶{
Subroutine _getc: called CC=3 SCAR=11.0
497 4692 my $p = shift;
498 4692 my $lines = $p->{text};
499 4692 my $ix = $p->{ix};
500
501 4692 ▶ if ($ix == -1) { return undef; }
Branch: 1 branch
BranchTrueFalseTotal
if ($ix == -1) 3 4689 4692
502
503 4689 ▶ if ($ix >= length($lines) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ix >= length $lines) 3 4686 4689
504 3 $p->{ix} = -1;
505 3 return undef;
506 }
507  
508 4686 my $c = substr($lines,$ix,1);
509 4686 $p->{ix}++;
510 # print $c;
511 4686 return $c;
512 }
513  
514 sub _ungetc
515 385 ▶{
Subroutine _ungetc: called CC=2 SCAR=6.9
516 385 my $p = shift;
517 385 ▶ if ( $p->{ix} == -1 ) { return; }
Branch: 1 branch
BranchTrueFalseTotal
if ($p->{"ix"} == -1) 3 382 385
518 382 $p->{ix}--;
519 # print "ungetc " . $p->{ix} . "\n";
520 }
521  
522 sub _fatal
523 0 ▶{
Subroutine _fatal: not called CC=1 SCAR=6.9
524 0 print $_[0];
525 0 exit(1);
526 }
527  
528 sub _addNode
529 131 ▶{
Subroutine _addNode: called CC=2 SCAR=7.1
530 131 my $p = shift;
531 131 my $s = shift;
532  
533 131 ▶ unless ( $p->{g} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($p->{"g"}) 0 131 131
534 0 $p->{g}[0] = OGDL::Graph->new("stream");
535 }
536
537 131 my $g2 = OGDL::Graph->new($s);
538 131 $p->{g}[$p->{level}]->addNode($g2);
539 131 $p->{g}[$p->{level}+1] = $g2;
540 }
541  
542 2 1;
543 __END__
« Path.pm ↑ Summary