line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lisp::Printer; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
1262
|
use strict; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
239
|
|
4
|
6
|
|
|
6
|
|
37
|
use vars qw(@EXPORT_OK $VERSION); |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
2253
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
$VERSION = sprintf("%d.%02d", q$Revision: 1.7 $ =~ /(\d+)\.(\d+)/); |
7
|
|
|
|
|
|
|
|
8
|
6
|
|
|
6
|
|
531
|
use Lisp::Symbol qw(symbolp); |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
308
|
|
9
|
6
|
|
|
6
|
|
8054
|
use Lisp::Vector qw(vectorp); |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
672
|
|
10
|
6
|
|
|
6
|
|
6559
|
use Lisp::Cons qw(consp); |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
3112
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
require Exporter; |
13
|
|
|
|
|
|
|
*import = \&Exporter::import; |
14
|
|
|
|
|
|
|
@EXPORT_OK = qw(lisp_print); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub dump |
17
|
|
|
|
|
|
|
{ |
18
|
0
|
|
|
0
|
0
|
0
|
require Data::Dumper; |
19
|
0
|
|
|
|
|
0
|
Data::Dumper::Dumper($_[0]); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub lisp_print |
23
|
|
|
|
|
|
|
{ |
24
|
228
|
|
|
228
|
0
|
536
|
my $obj = shift; |
25
|
228
|
|
|
|
|
263
|
my $str = ""; |
26
|
228
|
100
|
|
|
|
373
|
if (ref($obj)) { |
27
|
77
|
100
|
|
|
|
187
|
if (symbolp($obj)) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
28
|
49
|
|
|
|
|
143
|
$str = $obj->name; |
29
|
|
|
|
|
|
|
} elsif (vectorp($obj)) { |
30
|
2
|
|
|
|
|
6
|
$str = "[" . join(" ", map lisp_print($_), @$obj) . "]"; |
31
|
|
|
|
|
|
|
} elsif (ref($obj) eq "Lisp::Cons") { |
32
|
1
|
|
|
|
|
6
|
$str = "(" .join(" . ", map lisp_print($_), @$obj). ")"; |
33
|
|
|
|
|
|
|
} elsif (ref($obj) eq "ARRAY") { |
34
|
25
|
|
|
|
|
217
|
$str = "(" . join(" ", map lisp_print($_), @$obj) . ")"; |
35
|
|
|
|
|
|
|
} elsif (ref($obj) eq "HASH") { |
36
|
|
|
|
|
|
|
# make it into an alist |
37
|
0
|
|
|
|
|
0
|
$str = "(" . join("", |
38
|
0
|
|
|
|
|
0
|
map {"(" . lisp_print($_) . |
39
|
|
|
|
|
|
|
" . " . |
40
|
|
|
|
|
|
|
lisp_print($obj->{$_}) . |
41
|
|
|
|
|
|
|
")" |
42
|
|
|
|
|
|
|
} sort keys %$obj) . |
43
|
|
|
|
|
|
|
")"; |
44
|
|
|
|
|
|
|
} else { |
45
|
0
|
|
|
|
|
0
|
$str = "#<$obj>"; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} else { |
48
|
|
|
|
|
|
|
# XXX: need real number/string type info |
49
|
151
|
100
|
|
|
|
744
|
if (!defined($obj)) { |
|
|
100
|
|
|
|
|
|
50
|
2
|
|
|
|
|
3
|
$str = "nil"; |
51
|
|
|
|
|
|
|
} elsif ($obj =~ /^[+-]?\d+(?:\.\d*)?$/) { |
52
|
|
|
|
|
|
|
# number |
53
|
145
|
|
|
|
|
203
|
$str = $obj + 0; |
54
|
|
|
|
|
|
|
} else { |
55
|
|
|
|
|
|
|
# string |
56
|
4
|
|
|
|
|
17
|
$obj =~ s/([\"\\])/\\$1/g; # quote special chars |
57
|
4
|
|
|
|
|
11
|
$str = qq("$obj"); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
228
|
|
|
|
|
854
|
$str; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |