LispPerl/Reader.pm

filter: Statementstmt 89.3% 252 / 282 Branchbran 79.7% 118 / 148 Conditioncond 74.2% 49 / 66 MC/DCmcdc 31.0% 9 / 29 Subroutinesub 87.5% 28 / 32 Podpod 0.0% 0 / 24 totaltotal 78.4% 456 / 581 CC 97 SCAR 23.4
CC
97
Cov
84%
lex
19.9
string
19.1
symbol
13.3
CRAP 10.4
« LispPerl/Printer.pm ↑ Summary LispPerl/BuiltIns.pm »
1 package Language::LispPerl::Reader;
2 6 $Language::LispPerl::Reader::VERSION = '0.007';
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use Language::LispPerl::Seq;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use Language::LispPerl::Atom;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use Language::LispPerl::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use Class::Load;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 680 ▶sub from_perl{
Subroutine from_perl: called CC=5 SCAR=16.1
Pod undocumented
13 680 my ($thing) = @_;
14 680 my $refthing = ref($thing);
15 680 ▶ unless( $refthing ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($refthing) 525 155 680
16 525 return $thing;
17 }
18 155 ▶ if( $refthing eq 'HASH' ){
Branch: 1 branch
BranchTrueFalseTotal
if ($refthing eq "HASH") 128 27 155
19 128 ▶ if( my $class = $thing->{__class} ){
Branch: 1 branch
BranchTrueFalseTotal
if (my $class = $thing->{"__class"}) 65 63 128
20 65 Class::Load::load_class( $class );
21 65 return $class->from_hash( $thing );
22 }
23 return {
24 63 map{ $_ => from_perl( $thing->{$_} ) } keys %$thing
25 };
26 }
27 27 ▶ if( $refthing eq 'ARRAY' ){
Branch: 1 branch
BranchTrueFalseTotal
if ($refthing eq "ARRAY") 27 0 27
28 27 return [ map{ from_perl( $_ ) } @$thing ];
29 }
30 0 confess("No idea how to turn $thing into objects");
31 }
32  
33 114 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
34 114 my $class = shift;
35 114 my $self = {
36 class => $class,
37 ast => {},
38 nest => 0,
39 filehandler => undef,
40 filename => "unknown",
41 line => 1,
42 col => 1
43 };
44 114 bless $self;
45 114 return $self;
46 }
47  
48 0 ▶sub class {
Subroutine class: not called CC=1 SCAR=6.9
Pod undocumented
49 0 my $self = shift;
50 0 return $self->{class};
51 }
52  
53 59830 ▶sub filehandler {
Subroutine filehandler: called CC=2 SCAR=6.9
Pod undocumented
54 59830 my $self = shift;
55 59830 my $fh = shift;
56 59830 ▶ if ( defined $fh ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fh) { } 114 59716 59830
57 114 $self->{filehandler} = $fh;
58 }
59 else {
60 59716 return $self->{filehandler};
61 }
62 }
63  
64 4039 ▶sub filename {
Subroutine filename: called CC=2 SCAR=6.9
Pod undocumented
65 4039 my $self = shift;
66 4039 my $fn = shift;
67 4039 ▶ if ( defined $fn ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fn) { } 114 3925 4039
68 114 $self->{filename} = $fn;
69 }
70 else {
71 3925 return $self->{filename};
72 }
73 }
74  
75 5315 ▶sub line {
Subroutine line: called CC=2 SCAR=6.9
Pod undocumented
76 5315 my $self = shift;
77 5315 my $line = shift;
78 5315 ▶ if ( defined $line ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line) { } 752 4563 5315
79 752 $self->{line} = $line;
80 }
81 else {
82 4563 return $self->{line};
83 }
84 }
85  
86 31525 ▶sub col {
Subroutine col: called CC=2 SCAR=6.9
Pod undocumented
87 31525 my $self = shift;
88 31525 my $col = shift;
89 31525 ▶ if ( defined $col ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $col) { } 14176 17349 31525
90 14176 $self->{col} = $col;
91 }
92 else {
93 17349 return $self->{col};
94 }
95 }
96  
97 114 ▶sub ast {
Subroutine ast: called CC=1 SCAR=0.0
Pod undocumented
98 114 my $self = shift;
99 114 return $self->{ast};
100 }
101  
102 45654 ▶sub peekc {
Subroutine peekc: called CC=3 SCAR=11.0
Pod undocumented
103 45654 my $self = shift;
104 45654 my $fh = $self->filehandler();
105 45654 ▶ die "file handler is un-defined" if ( !defined $fh );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fh 0 45654 45654
106 45654 my $c = undef;
107 45654 ▶ if ( !eof($fh) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eof $fh) 45540 114 45654
108 45540 $c = getc($fh);
109 45540 seek( $fh, -1, 1 );
110 }
111 45654 return $c;
112 }
113  
114 14062 ▶sub readc {
Subroutine readc: called CC=3 SCAR=11.0
Pod undocumented
115 14062 my $self = shift;
116 14062 my $fh = $self->filehandler();
117 14062 my $c = $self->peekc();
118 14062 ▶ if ( defined $c ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c) 14062 0 14062
119 14062 ▶ if ( $c eq "\n" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "\n") { } 638 13424 14062
120 638 $self->line( 1 + $self->line() );
121 638 $self->col(1);
122 }
123 else {
124 13424 $self->col( 1 + $self->col() );
125 }
126 14062 seek( $fh, 1, 1 );
127 }
128 14062 return $c;
129 }
130  
131 13464 ▶sub consume {
Subroutine consume: called CC=2 SCAR=6.9
Pod undocumented
132 13464 my $self = shift;
133 13464 my $offset = shift;
134 13464 ▶ for ( my $i = 0 ; $i < $offset ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $offset) 13464 13464 26928
135 13464 $self->readc();
136 }
137 }
138  
139 11533 ▶sub skip_blanks {
Subroutine skip_blanks: called CC=5 SCAR=16.1
Pod undocumented
140 11533 my $self = shift;
141 11533 my $c = undef;
142 11533 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
not defined $c or do { do { $c = $self->peekc; if (defined $c) { if ($c eq ";") { $self->consume(1); $self->comment; } elsif ($c =~ /\s/) { $self->consume(1); } else { $c = undef; } ; } else { $c = undef; } } } 11533 3386 14919
143 14919 $c = $self->peekc();
144 14919 ▶ if ( defined $c ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c) { } 14805 114 14919
145 14805 ▶ if ( $c eq ";" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($c eq ';') { } 32 14773 14805
elsif ($c =~ /\s/) { } 3354 11419 14773
146 32 $self->consume(1);
147 32 $self->comment();
148 }
149 elsif ( $c =~ /\s/ ) {
150 3354 $self->consume(1);
151 }
152 else {
153 11419 $c = undef;
154 }
155 }
156 else {
157 114 $c = undef;
158 }
159 } until !defined $c;
160 }
161  
162 114 ▶sub parse {
Subroutine parse: called CC=8 SCAR=20.9
Pod undocumented
163 114 my $self = shift;
164 114 my $file_or_str = shift;
165 114 my $mode = shift;
166 114 ▶ $mode = "string" if !defined $mode;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mode 105 9 114
167 114 my $fh = undef;
168 114 ▶ if ( $mode eq "string" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq 'string') { } 105 9 114
169 105 ▶ open $fh, "<", \$file_or_str or die "cannot read string $file_or_str";
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<", \$file_or_str or die "cannot read string $file_or_str" 105 0 105
170 }
171 else {
172 9 ▶ open $fh, "<", $file_or_str or die "cannot open file $file_or_str";
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<", $file_or_str or die "cannot open file $file_or_str" 9 0 9
173 }
174 114 $self->filehandler($fh);
175 114 $self->filename($file_or_str);
176 114 $self->line(1);
177 114 $self->col(1);
178 114 my $ast = Language::LispPerl::Seq->new();
179 114 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
eof $fh or do { do { $self->skip_blanks; my $r = $self->lex; $ast->append($r) if defined $r } } 114 179 293
180 293 $self->skip_blanks();
181 293 my $r = $self->lex();
182 293 ▶ $ast->append($r) if defined $r;
Branch: 1 branch
BranchTrueFalseTotal
if defined $r 293 0 293
183 } until eof($fh);
184 114 $self->{ast} = $ast;
185 114 ▶ close $fh if $mode ne "string";
Branch: 1 branch
BranchTrueFalseTotal
if $mode ne "string" 9 105 114
186 }
187  
188 9 ▶sub read_file {
Subroutine read_file: called CC=1 SCAR=0.0
Pod undocumented
189 9 my $self = shift;
190 9 my $file = shift;
191 9 $self->parse( $file, "file" );
192 }
193  
194 105 ▶sub read_string {
Subroutine read_string: called CC=1 SCAR=0.0
Pod undocumented
195 105 my $self = shift;
196 105 my $str = shift;
197 105 $self->parse($str);
198 }
199  
200 0 ▶sub show {
Subroutine show: not called CC=2 SCAR=17.9
Pod undocumented
201 0 my $self = shift;
202 0 my $indent = shift;
203 0 ▶ $indent = "" if !defined $indent;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $indent 0 0 0
204 0 $self->{ast}->show($indent);
205 }
206  
207 4070 ▶sub lex {
Subroutine lex: called CC=19 SCAR=29.9
Pod undocumented
208 4070 my $self = shift;
209 4070 my $c = $self->peekc();
210 4070 ▶ if ( defined $c ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c) 4070 0 4070
211 4070 ▶ if ( $c eq '(' ) {
Branch: 13 branches
BranchTrueFalseTotal
if ($c eq '(') { } 808 3262 4070
elsif ($c eq '"') { } 141 3121 3262
elsif ($c =~ /\d/) { } 133 2988 3121
elsif ($c eq '[') { } 151 2837 2988
elsif ($c eq '{') { } 28 2809 2837
elsif ($c eq '#') { } 54 2755 2809
elsif ($c eq '^') { } 17 2738 2755
elsif ($c eq ':') { } 50 2688 2738
elsif ($c eq q[']) { } 42 2646 2688
elsif ($c eq '`') { } 52 2594 2646
elsif ($c eq '~') { } 74 2520 2594
elsif ($c eq ';') { } 0 2520 2520
elsif ($c eq ')' || $c eq ']' || $c eq '}' and $self->{'nest'} == 0) { } 0 2520 2520
212 808 return $self->seq( "list", "(", ")" );
213 }
214 elsif ( $c eq '"' ) {
215 141 return $self->string();
216 }
217 elsif ( $c =~ /\d/ ) {
218 133 return $self->number();
219 }
220 elsif ( $c eq '[' ) {
221 151 return $self->seq( "vector", "[", "]" );
222 }
223 elsif ( $c eq '{' ) {
224 28 return $self->seq( "map", "{", "}" );
225 }
226 elsif ( $c eq '#' ) {
227 54 $self->consume(1);
228 54 return $self->dispatch();
229 }
230 elsif ( $c eq '^' ) {
231 17 $self->consume(1);
232 17 ▶ $self->error("meta should be a map") if $self->peekc() ne "{";
Branch: 1 branch
BranchTrueFalseTotal
if $self->peekc ne "{" 0 17 17
233 17 my $md = $self->lex();
234 17 $md->type("meta");
235 17 return $md;
236 }
237 elsif ( $c eq ':' ) {
238 50 $self->consume(1);
239 50 my $k = $self->symbol();
240 50 $k->type("keyword");
241 50 return $k;
242 }
243 elsif ( $c eq "'" ) {
244 42 $self->consume(1);
245 42 my $q = $self->lex();
246 42 return Language::LispPerl::Atom->new({type => "quotation", value => $q });
247 }
248 elsif ( $c eq "`" ) {
249 52 $self->consume(1);
250 52 my $sq = $self->lex();
251 52 return Language::LispPerl::Atom->new({ type => "syntaxquotation", value => $sq });
252 }
253 elsif ( $c eq "~" ) {
254 74 $self->consume(1);
255 74 my $dq = $self->symbol();
256 74 $dq->type("dequotation");
257 74 return $dq;
258  
259 #} elsif($c eq "@") {
260 # $self->consume(1);
261 # my $dr = $self->symbol();
262 #$dr->type("deref");
263 #return $dr;
264 }
265 elsif ( $c eq ";" ) {
266 0 $self->consume(1);
267 0 $self->comment();
268 0 return undef;
269 }
270 ▶ elsif ( ( $c eq ')' or $c eq ']' or $c eq '}' )
Condition88%8/9
$c eq ")" || $c eq "]" || $c eq "}" and $self->{"nest"} == 0
!ll&&!rl&&r
151310070
$c eq ")" or $c eq "]" or $c eq "}"
l!l&&r!l&&!r
979281513
$c eq ")" or $c eq "]"
l!l&&r!l&&!r
8081711541
MC/DC0%0/4
$c eq ")" || $c eq "]" || $c eq "}" and $self->{"nest"} == 0
$c eq ")" $c eq "]" $c eq "}" $self->{"nest"} == 0
Truth table57%4/7
A or B or C and D
A= $c eq ")"B= $c eq "]"C= $c eq "}"D= $self->{"nest"} == 0
ABCDresult
000X0
1XX00
01X00
00100
1XX11
01X11
00111
271 and $self->{nest} == 0 )
272 {
273 0 $self->error( "unexpected " . $c );
274 }
275 else {
276 2520 return $self->symbol();
277 }
278 }
279 0 return undef;
280 }
281  
282 54 ▶sub dispatch {
Subroutine dispatch: called CC=5 SCAR=16.6
Pod undocumented
283 54 my $self = shift;
284 54 my $c = $self->peekc();
285 54 ▶ if ( defined $c ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c) 54 0 54
286 54 ▶ if ( $c eq ":" ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($c eq ':') { } 33 21 54
elsif ($c eq '!') { } 1 20 21
elsif ($c eq '[') { } 20 0 20
287 33 $self->consume(1);
288 33 return Language::LispPerl::Atom->new({ type => "accessor", value => $self->lex() });
289 }
290 elsif ( $c eq "!" ) {
291 1 $self->consume(1);
292 1 return Language::LispPerl::Atom->new({ type => "sender", value => $self->lex() });
293 }
294 elsif ( $c eq '[' ) {
295 20 return $self->seq( "xml", "[", "]" );
296 }
297 else {
298 0 $self->error("unsupport syntax for disptacher");
299 }
300 }
301 0 return undef;
302 }
303  
304 32 ▶sub comment {
Subroutine comment: called CC=4 SCAR=13.9
Pod undocumented
305 32 my $self = shift;
306 32 my $c = undef;
307 32 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
not defined $c or do { do { $c = $self->readc; if (defined $c and $c eq "\n") { $c = undef; } } } 32 566 598
308 598 $c = $self->readc();
309 598 ▶ if ( defined $c and $c eq "\n" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c and $c eq "\n") 32 566 598
Condition66%2/3
defined $c and $c eq "\n"
!ll&&!rl&&r
056632
MC/DC50%1/2
defined $c and $c eq "\n"
defined $c $c eq "\n"
Truth table66%2/3
A and B
A= defined $cB= $c eq "\n"
ABresult
0X0
100
111
310 32 $c = undef;
311 }
312 } until !defined $c;
313 32 $self->skip_blanks();
314  
315 32 return undef;
316 }
317  
318 141 ▶sub string {
Subroutine string: called CC=15 SCAR=29.5
Pod undocumented
319 141 my $self = shift;
320 141 my $c = undef;
321 141 my $s = Language::LispPerl::Atom->new({ type => "string" });
322 $s->{pos} = {
323 141 filename => $self->filename(),
324 line => $self->line(),
325 col => $self->col()
326 };
327 141 $self->consume(1);
328 141 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
not defined $c or do { do { $c = $self->peekc; if (defined $c) { if ($c eq "\\") { $self->consume(1); my $nc = $self->peekc; $self->error("unexpected eof") unless defined $nc; $self->consume(1); my $rc = $nc; if ($nc eq "a") { $rc = "\a"; } elsif ($nc eq "b") { $rc = "\b"; } elsif ($nc eq "e") { $rc = "\e"; } elsif ($nc eq "f") { $rc = "\f"; } elsif ($nc eq "n") { $rc = "\n"; } elsif ($nc eq "r") { $rc = "\r"; } elsif ($nc eq "t") { $rc = "\t"; } ; $s->{"value"} .= $rc; } elsif ($c ne "\"") { $s->{"value"} .= $c; $self->consume(1); } else { $c = undef; } ; } } } 141 604 745
329 745 $c = $self->peekc();
330 745 ▶ if ( defined $c ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c) 745 0 745
331 745 ▶ if ( $c eq "\\" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($c eq '\\') { } 11 734 745
elsif ($c ne '"') { } 593 141 734
332 11 $self->consume(1);
333 11 my $nc = $self->peekc();
334 11 ▶ $self->error("unexpected eof") if !defined $nc;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $nc 0 11 11
335 11 $self->consume(1);
336 11 my $rc = $nc;
337 11 ▶ if ( $nc eq "a" ) {
Branch: 7 branches
BranchTrueFalseTotal
if ($nc eq 'a') { } 0 11 11
elsif ($nc eq 'b') { } 0 11 11
elsif ($nc eq 'e') { } 0 11 11
elsif ($nc eq 'f') { } 0 11 11
elsif ($nc eq 'n') { } 4 7 11
elsif ($nc eq 'r') { } 0 7 7
elsif ($nc eq 't') { } 1 6 7
338 0 $rc = "\a";
339 }
340 elsif ( $nc eq "b" ) {
341 0 $rc = "\b";
342 }
343 elsif ( $nc eq "e" ) {
344 0 $rc = "\e";
345 }
346 elsif ( $nc eq "f" ) {
347 0 $rc = "\f";
348 }
349 elsif ( $nc eq "n" ) {
350 4 $rc = "\n";
351 }
352 elsif ( $nc eq "r" ) {
353 0 $rc = "\r";
354 }
355 elsif ( $nc eq "t" ) {
356 1 $rc = "\t";
357 }
358 11 $s->{value} .= $rc;
359 }
360 elsif ( $c ne '"' ) {
361 593 $s->{value} .= $c;
362 593 $self->consume(1);
363 }
364 else {
365 141 $c = undef;
366 }
367 }
368 } until !defined $c;
369 141 $c = $self->peekc();
370 141 ▶ if ( defined $c and $c eq '"' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c and $c eq '"') { } 141 0 141
Condition33%1/3
defined $c and $c eq "\""
!ll&&!rl&&r
00141
MC/DC0%0/2
defined $c and $c eq "\""
defined $c $c eq "\""
Truth table33%1/3
A and B
A= defined $cB= $c eq "\""
ABresult
0X0
100
111
371 141 $self->consume(1);
372 }
373 else {
374 0 $self->error("expect \"");
375 }
376 141 $self->skip_blanks();
377 141 return $s;
378 }
379  
380 133 ▶sub number {
Subroutine number: called CC=12 SCAR=25.4
Pod undocumented
381 133 my $self = shift;
382 133 my $c = undef;
383 133 my $n = Language::LispPerl::Atom->new({ type => "number" });
384 $n->{pos} = {
385 133 filename => $self->filename(),
386 line => $self->line(),
387 col => $self->col()
388 };
389 133 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
not defined $c or do { do { $c = $self->peekc; if (defined $c and $c =~ /\S/ and $c ne ";" and $c ne "(" and $c ne ")" and $c ne "[" and $c ne "]" and $c ne "{" and $c ne "}") { if ($c =~ m[[\+\-\d\.xXabcdefABCDEF/\_]]) { $self->consume(1); $n->{"value"} .= $c; } else { $self->error('unexpect letter ' . $c . ' for number'); } ; } else { $c = undef; } } } 133 152 285
390 285 $c = $self->peekc();
391 285 ▶ if ( defined $c
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c and $c =~ /\S/ and $c ne ';' and $c ne '(' and $c ne ')' and $c ne '[' and $c ne ']' and $c ne '{' and $c ne '}') { } 152 133 285
Condition79%19/24
defined $c and $c =~ /\S/ and $c ne ";" and $c ne "(" and $c ne ")" and $c ne "[" and $c ne "]" and $c ne "{" and $c ne "}"
!ll&&!rl&&r
1294152
defined $c and $c =~ /\S/ and $c ne ";" and $c ne "(" and $c ne ")" and $c ne "[" and $c ne "]" and $c ne "{"
!ll&&!rl&&r
1290156
defined $c and $c =~ /\S/ and $c ne ";" and $c ne "(" and $c ne ")" and $c ne "[" and $c ne "]"
!ll&&!rl&&r
1254156
defined $c and $c =~ /\S/ and $c ne ";" and $c ne "(" and $c ne ")" and $c ne "["
!ll&&!rl&&r
1250160
defined $c and $c =~ /\S/ and $c ne ";" and $c ne "(" and $c ne ")"
!ll&&!rl&&r
8639160
defined $c and $c =~ /\S/ and $c ne ";" and $c ne "("
!ll&&!rl&&r
860199
defined $c and $c =~ /\S/ and $c ne ";"
!ll&&!rl&&r
860199
defined $c and $c =~ /\S/
!ll&&!rl&&r
086199
MC/DC44%4/9
defined $c and $c =~ /\S/ and $c ne ";" and $c ne "(" and $c ne ")" and $c ne "[" and $c ne "]" and $c ne "{" and $c ne "}"
defined $c $c =~ /\S/ $c ne ";" $c ne "(" $c ne ")" $c ne "[" $c ne "]" $c ne "{" $c ne "}"
Truth table50%5/10
A and B and C and D and E and F and G and H and I
A= defined $cB= $c =~ /\S/C= $c ne ";"D= $c ne "("E= $c ne ")"F= $c ne "["G= $c ne "]"H= $c ne "{"I= $c ne "}"
ABCDEFGHIresult
0XXXXXXXX0
10XXXXXXX0
110XXXXXX0
1110XXXXX0
11110XXXX0
111110XXX0
1111110XX0
11111110X0
1111111100
1111111111
392 and $c =~ /\S/
393 and $c ne ";"
394 and $c ne '('
395 and $c ne ')'
396 and $c ne '['
397 and $c ne ']'
398 and $c ne '{'
399 and $c ne '}' )
400 {
401 152 ▶ if ( $c =~ /[\+\-\d\.xXabcdefABCDEF\/\_]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c =~ m[[\+\-\d\.xXabcdefABCDEF/\_]]) { } 152 0 152
402 152 $self->consume(1);
403 152 $n->{value} .= $c;
404 }
405 else {
406 0 $self->error( "unexpect letter " . $c . " for number" );
407 }
408 }
409 else {
410 133 $c = undef;
411 }
412 } until !defined $c;
413 0 ▶ local $SIG{__WARN__} = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
414 0 $n->error( "invild number literal " . $n->{value} );
415 133 };
416 133 $n->{value} = 0 + $n->{value};
417 133 delete $SIG{__WARN__};
418 133 $self->skip_blanks();
419 133 return $n;
420 }
421  
422 2644 ▶sub symbol {
Subroutine symbol: called CC=13 SCAR=25.9
Pod undocumented
423 2644 my $self = shift;
424 2644 my $c = undef;
425 2644 my $sym = Language::LispPerl::Atom->new({ type => "symbol" });
426 2644 $self->skip_blanks();
427 $sym->{pos} = {
428 2644 filename => $self->filename(),
429 line => $self->line(),
430 col => $self->col()
431 };
432 2644 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
not defined $c or do { do { $c = $self->peekc; if (defined $c) { if ($c =~ /\S/ and $c ne ";" and $c ne "(" and $c ne ")" and $c ne "[" and $c ne "]" and $c ne "{" and $c ne "}") { $self->error('unexpected letter ' . $c . ' for symbol') if $c =~ m([^0-9a-zA-Z_!&\?\*/\.\+\|=%\$<>#@\:\-\\]); $sym->{"value"} .= $c; $self->consume(1); } else { $c = undef; } ; } } } 2644 6692 9336
433 9336 $c = $self->peekc();
434 9336 ▶ if ( defined $c ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c) 9336 0 9336
435 9336 ▶ if ( $c =~ /\S/
Branch: 1 branch
BranchTrueFalseTotal
if ($c =~ /\S/ and $c ne ';' and $c ne '(' and $c ne ')' and $c ne '[' and $c ne ']' and $c ne '{' and $c ne '}') { } 6692 2644 9336
Condition80%17/21
$c =~ /\S/ and $c ne ";" and $c ne "(" and $c ne ")" and $c ne "[" and $c ne "]" and $c ne "{" and $c ne "}"
!ll&&!rl&&r
2606386692
$c =~ /\S/ and $c ne ";" and $c ne "(" and $c ne ")" and $c ne "[" and $c ne "]" and $c ne "{"
!ll&&!rl&&r
260606730
$c =~ /\S/ and $c ne ";" and $c ne "(" and $c ne ")" and $c ne "[" and $c ne "]"
!ll&&!rl&&r
23252816730
$c =~ /\S/ and $c ne ";" and $c ne "(" and $c ne ")" and $c ne "["
!ll&&!rl&&r
232507011
$c =~ /\S/ and $c ne ";" and $c ne "(" and $c ne ")"
!ll&&!rl&&r
126210637011
$c =~ /\S/ and $c ne ";" and $c ne "("
!ll&&!rl&&r
126208074
$c =~ /\S/ and $c ne ";"
!ll&&!rl&&r
126208074
MC/DC50%4/8
$c =~ /\S/ and $c ne ";" and $c ne "(" and $c ne ")" and $c ne "[" and $c ne "]" and $c ne "{" and $c ne "}"
$c =~ /\S/ $c ne ";" $c ne "(" $c ne ")" $c ne "[" $c ne "]" $c ne "{" $c ne "}"
Truth table55%5/9
A and B and C and D and E and F and G and H
A= $c =~ /\S/B= $c ne ";"C= $c ne "("D= $c ne ")"E= $c ne "["F= $c ne "]"G= $c ne "{"H= $c ne "}"
ABCDEFGHresult
0XXXXXXX0
10XXXXXX0
110XXXXX0
1110XXXX0
11110XXX0
111110XX0
1111110X0
111111100
111111111
436 and $c ne ';'
437 and $c ne '('
438 and $c ne ')'
439 and $c ne '['
440 and $c ne ']'
441 and $c ne '{'
442 and $c ne '}' )
443 {
444 6692 ▶ $self->error( "unexpected letter " . $c . " for symbol" )
Branch: 1 branch
BranchTrueFalseTotal
if $c =~ m([^0-9a-zA-Z_!&\?\*/\.\+\|=%\$<>#@\:\-\\]) 0 6692 6692
445 if $c =~ /[^0-9a-zA-Z_!&\?\*\/\.\+\|=%\$<>#@\:\-\\]/;
446 6692 $sym->{value} .= $c;
447 6692 $self->consume(1);
448 }
449 else {
450 2644 $c = undef;
451 }
452 }
453 } until !defined $c;
454 2644 $self->skip_blanks();
455 2644 ▶ if ( $sym->{value} eq "" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sym->{'value'} eq '') { } 1007 1637 2644
456 1007 return undef;
457 }
458 else {
459 1637 return $sym;
460 }
461 }
462  
463 1007 ▶sub seq {
Subroutine seq: called CC=10 SCAR=24.2
Pod undocumented
464 1007 my $self = shift;
465 1007 my $type = shift;
466 1007 my $begin = shift;
467 1007 my $end = shift;
468 1007 ▶ $type = "list" if !defined $type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 0 1007 1007
469 1007 ▶ $begin = "(" if !defined $begin;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $begin 0 1007 1007
470 1007 ▶ $end = ")" if !defined $end;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $end 0 1007 1007
471 1007 my $e = undef;
472 1007 my $c = $self->peekc();
473  
474 1007 ▶ if ( defined $c and $c eq $begin ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c and $c eq $begin) { } 1007 0 1007
Condition33%1/3
defined $c and $c eq $begin
!ll&&!rl&&r
001007
MC/DC0%0/2
defined $c and $c eq $begin
defined $c $c eq $begin
Truth table33%1/3
A and B
A= defined $cB= $c eq $begin
ABresult
0X0
100
111
475 1007 $self->consume(1);
476 }
477 else {
478 0 $self->error( "expect " . $begin );
479 }
480 1007 $self->skip_blanks();
481 1007 my $seq = Language::LispPerl::Seq->new({ type => $type });
482 1007 $seq->pos({
483 filename => $self->filename(),
484 line => $self->line(),
485 col => $self->col()
486 });
487 1007 $self->{nest} += 1;
488 1007 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
not defined $e or do { do { $e = $self->lex; $self->skip_blanks; $seq->append($e) if defined $e } } 1007 2625 3632
489 3632 $e = $self->lex();
490 3632 $self->skip_blanks();
491 3632 ▶ $seq->append($e) if defined $e;
Branch: 1 branch
BranchTrueFalseTotal
if defined $e 2625 1007 3632
492 } until !defined $e;
493 1007 $c = $self->peekc();
494 1007 ▶ if ( defined $c and $c eq $end ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c and $c eq $end) { } 1007 0 1007
Condition33%1/3
defined $c and $c eq $end
!ll&&!rl&&r
001007
MC/DC0%0/2
defined $c and $c eq $end
defined $c $c eq $end
Truth table33%1/3
A and B
A= defined $cB= $c eq $end
ABresult
0X0
100
111
495 1007 $self->consume(1);
496 1007 $self->{nest} -= 1;
497 }
498 else {
499 0 $self->error( "expect " . $end );
500 }
501 1007 $self->skip_blanks();
502 1007 return $seq;
503 }
504  
505 0 ▶sub error {
Subroutine error: not called CC=1 SCAR=6.9
Pod undocumented
506 0 my $self = shift;
507 0 my $msg = shift;
508 0 $msg .= " @[file: " . $self->filename();
509 0 $msg .= "; line: " . $self->line();
510 0 $msg .= "; col: " . $self->col() . "]";
511 0 Language::LispPerl::Logger::error($msg);
512 }
513 6 1;
« LispPerl/Printer.pm ↑ Summary LispPerl/BuiltIns.pm »