line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Language::LispPerl::Printer; |
2
|
|
|
|
|
|
|
$Language::LispPerl::Printer::VERSION = '0.007'; |
3
|
6
|
|
|
6
|
|
21
|
use strict; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
134
|
|
4
|
6
|
|
|
6
|
|
19
|
use warnings; |
|
6
|
|
|
|
|
6
|
|
|
6
|
|
|
|
|
3806
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head2 to_perl |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Pure function. Takes something Language::LispPerl related and |
9
|
|
|
|
|
|
|
turns it into a pure perl data structure. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=cut |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub to_perl{ |
14
|
860
|
|
|
860
|
1
|
633
|
my $thing = shift; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# Object case. Easy. |
17
|
860
|
100
|
|
|
|
1427
|
if( Scalar::Util::blessed( $thing ) ){ |
18
|
130
|
|
|
|
|
286
|
return $thing->to_hash(); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
730
|
|
|
|
|
583
|
my $ref_thing = ref($thing); |
22
|
|
|
|
|
|
|
# Pure scalar thing. Easy. |
23
|
730
|
100
|
|
|
|
883
|
unless( $ref_thing ){ |
24
|
550
|
|
|
|
|
5679
|
return $thing; |
25
|
|
|
|
|
|
|
} |
26
|
180
|
100
|
|
|
|
269
|
if( $ref_thing eq 'ARRAY' ){ |
27
|
54
|
|
|
|
|
39
|
return [ map{ to_perl( $_ ) } @{$thing} ]; |
|
96
|
|
|
|
|
134
|
|
|
54
|
|
|
|
|
441
|
|
28
|
|
|
|
|
|
|
} |
29
|
126
|
50
|
|
|
|
175
|
if( $ref_thing eq 'HASH' ){ |
30
|
126
|
|
|
|
|
134
|
my $hash = {}; |
31
|
126
|
|
|
|
|
350
|
while( my ( $k , $v ) = each %$thing ){ |
32
|
370
|
|
|
|
|
361
|
$hash->{$k} = to_perl( $v ); |
33
|
|
|
|
|
|
|
} |
34
|
126
|
|
|
|
|
2351
|
return $hash; |
35
|
|
|
|
|
|
|
} |
36
|
0
|
|
|
|
|
0
|
confess("Cannot turn $thing into pure perl structure"); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub to_string { |
41
|
32
|
|
|
32
|
0
|
32
|
my $obj = shift; |
42
|
32
|
50
|
|
|
|
43
|
return "" if !defined $obj; |
43
|
32
|
|
|
|
|
710
|
my $class = $obj->class(); |
44
|
32
|
|
|
|
|
684
|
my $type = $obj->type(); |
45
|
32
|
|
|
|
|
29
|
my $s = ""; |
46
|
32
|
100
|
|
|
|
46
|
if ( $class eq "Seq" ) { |
47
|
8
|
100
|
|
|
|
14
|
if ( $type eq "vector" ) { |
|
|
50
|
|
|
|
|
|
48
|
2
|
|
|
|
|
4
|
$s = "["; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
elsif ( ( $type eq "map" ) ) { |
51
|
0
|
|
|
|
|
0
|
$s = "{"; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else { |
54
|
6
|
|
|
|
|
7
|
$s = "("; |
55
|
|
|
|
|
|
|
} |
56
|
8
|
|
|
|
|
5
|
foreach my $i ( @{ $obj->value() } ) { |
|
8
|
|
|
|
|
221
|
|
57
|
21
|
|
|
|
|
58
|
$s .= to_string($i) . " "; |
58
|
|
|
|
|
|
|
} |
59
|
8
|
100
|
|
|
|
27
|
if ( $type eq "vector" ) { |
|
|
50
|
|
|
|
|
|
60
|
2
|
|
|
|
|
3
|
$s .= "]"; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
elsif ( ( $type eq "map" ) ) { |
63
|
0
|
|
|
|
|
0
|
$s .= "}"; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
else { |
66
|
6
|
|
|
|
|
6
|
$s .= ")"; |
67
|
|
|
|
|
|
|
} |
68
|
8
|
|
|
|
|
25
|
$s =~ s/ ([\)\]\}])$/$1/; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
else { |
71
|
24
|
100
|
33
|
|
|
172
|
if ( $type eq "vector" ) { |
|
|
50
|
66
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
72
|
1
|
|
|
|
|
2
|
$s = "["; |
73
|
1
|
|
|
|
|
2
|
foreach my $i ( @{ $obj->value() } ) { |
|
1
|
|
|
|
|
23
|
|
74
|
3
|
|
|
|
|
5
|
$s .= to_string($i) . " "; |
75
|
|
|
|
|
|
|
} |
76
|
1
|
|
|
|
|
3
|
$s .= "]"; |
77
|
1
|
|
|
|
|
3
|
$s =~ s/ \]$/\]/; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
elsif ( $type eq "map" or $type eq "meta" ) { |
80
|
0
|
|
|
|
|
0
|
$s = "{"; |
81
|
0
|
|
|
|
|
0
|
foreach my $i ( keys %{ $obj->value() } ) { |
|
0
|
|
|
|
|
0
|
|
82
|
0
|
|
|
|
|
0
|
$s .= $i . "=>" . to_string( $obj->value()->{$i} ) . " "; |
83
|
|
|
|
|
|
|
} |
84
|
0
|
|
|
|
|
0
|
$s .= "}"; |
85
|
0
|
|
|
|
|
0
|
$s =~ s/ \}$/\}/; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
elsif ( $type eq "xml" ) { |
88
|
0
|
|
|
|
|
0
|
$s = "<"; |
89
|
0
|
|
|
|
|
0
|
$s .= $obj->{name}; |
90
|
0
|
0
|
|
|
|
0
|
if ( defined $obj->{meta_data} ) { |
91
|
0
|
|
|
|
|
0
|
my %meta = %{ $obj->meta_data()->value() }; |
|
0
|
|
|
|
|
0
|
|
92
|
0
|
|
|
|
|
0
|
foreach my $i ( keys %meta ) { |
93
|
0
|
|
|
|
|
0
|
$s .= " " . $i . "=\"" . to_string( $meta{$i} ) . "\""; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
0
|
|
|
|
|
0
|
$s .= ">"; |
97
|
0
|
|
|
|
|
0
|
foreach my $i ( @{ $obj->value() } ) { |
|
0
|
|
|
|
|
0
|
|
98
|
0
|
|
|
|
|
0
|
$s .= to_string($i) . " "; |
99
|
|
|
|
|
|
|
} |
100
|
0
|
|
|
|
|
0
|
$s .= "</" . $obj->{name} . ">"; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
elsif ( $type eq "function" or $type eq "macro" ) { |
103
|
1
|
|
|
|
|
24
|
$s = to_string( $obj->value() ); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
elsif ( $type eq "exception" ) { |
106
|
0
|
|
|
|
|
0
|
$s = "exception: "; |
107
|
0
|
|
|
|
|
0
|
$s .= $obj->{label} . " - "; |
108
|
0
|
|
|
|
|
0
|
$s .= $obj->value(); |
109
|
0
|
|
|
|
|
0
|
foreach my $c ( @{ $obj->{caller} } ) { |
|
0
|
|
|
|
|
0
|
|
110
|
0
|
|
|
|
|
0
|
$s .= "\n\t" . to_string($c); |
111
|
0
|
|
|
|
|
0
|
$s .= "["; |
112
|
0
|
|
|
|
|
0
|
$s .= "file:" . $c->{pos}->{filename} . "; "; |
113
|
0
|
|
|
|
|
0
|
$s .= "line:" . $c->{pos}->{line} . "; "; |
114
|
0
|
|
|
|
|
0
|
$s .= "col:" . $c->{pos}->{col} . ";"; |
115
|
0
|
|
|
|
|
0
|
$s .= "]"; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
elsif( $type eq 'string' ){ |
119
|
4
|
|
|
|
|
90
|
$s = $obj->value(); |
120
|
4
|
|
|
|
|
10
|
$s =~ s/"/\\"/g; |
121
|
4
|
|
|
|
|
9
|
$s = '"'.$s.'"'; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
else { |
124
|
18
|
|
|
|
|
422
|
$s = $obj->value(); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
} |
127
|
32
|
|
|
|
|
206
|
return $s; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |
131
|
|
|
|
|
|
|
|