| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | return m4ToGraph("$name.gm"); | |||||||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | if(-T "$name.g"){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | return fileToGraph("$name.g"); | |||||||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | if(-T $name){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | return fileToGraph($name); | |||||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | if(-d $name){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 98 | ▶ | if (_eos($p)) { return 0 }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 24 | ▶ | while ( $p->{line_level} > 0) { #find the parent or brother line_level | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 46 | ▶ | if ( $i >= $p->{indentation}[$p->{line_level}] ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 166 | _space($p); #Remove the trailing spaces | |||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 95 | ▶ | return _eos($p) ? 0:1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 261 | my $s=undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 202 | 261 | my $c=_peek($p); | |||||||||||||||||||||||||||||||||||||||||||||
| 203 | 261 | ▶ | if($c eq '('){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 9 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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 "\""
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 "\""
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 201 | ▶ | if ( $c eq "\n" ) { return 1; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | my $s=""; | |||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | my $c=_getc($p); | |||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | if($c eq '#'){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | $c=_getc($p); | |||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | if($c ne ' ' && $c ne "\t"){_ungetc($p);_ungetc($p);return undef;} | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$c ne " " and $c ne "\t"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | while(defined $c){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | if($c eq "\n"){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$c = _getc($p) or $c eq 0
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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 2503 | ▶ | if ( ($c eq $term) && !($cprev eq '\\')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$c eq $term and not $cprev eq "\\"
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 "\\"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 3 | last; | |||||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 351 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 2500 | ▶ | if($c eq $term){chop $s;} # chop off the '\' | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 2500 | $cprev=$c; | |||||||||||||||||||||||||||||||||||||||||||||
| 354 | 2500 | ▶ | if($strip<$i && _isSpaceChar($c)){ #continue strip indentation of $s | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
$strip < $i and _isSpaceChar($c)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 33 | $strip=0; | |||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | ▶ | if($cprev eq '\\'){chop;chop;} #the line continuation | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | ▶ | if ( _eos($p) ) { last; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 3 | ▶ | if ( ! _newline($p) ) { last; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | ▶ | if ( $j > $is ) { $p->{ix} -= ($j-$is); } # XXX ungetting extra spaces | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 14 | ▶ | while ( $c = _getc($p) ) { #get a line, that is ended in \n | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 782 | ▶ | if ($c ne "\r") { $s = $s . $c; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 782 | ▶ | if ($c eq "\n") { last; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | ▶ | if ( _eos($p) ) { last; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 1 | ▶ | if ( ! _eos($p) ){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 1 | $c=chop $s; | |||||||||||||||||||||||||||||||||||||||||||||
| 412 | 1 | ▶ | while($c=~/[\n \t]/){$c=chop $s;} | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/6
defined $next and $next eq " " or $next eq "\\t"
defined $next and $next eq " "
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"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $next and not $next =~ /^([ \t\r\n\(\);,]|# )/
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\(\);,]|# )/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 261 | ▶ | if($next=~/^(['"\(\);,]|# |\\[\r\n])/ ){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 39 | return substr($next,0,1); | |||||||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 222 | ▶ | if($next=~/^[ \t]/ ){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | return " "; | |||||||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 222 | ▶ | if($next=~/^[\r\n]/ ){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 1076 | ▶ | if ($_[0] =~ /[ \t]/) { return 1; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | ▶ | if ($_[0] =~ /[ \t\n\r\(\),;]/) { return 0; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 4689 | ▶ | if ($ix >= length($lines) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||||||