line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::APL::Translator; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
65143
|
use strict; |
|
3
|
|
|
|
|
16
|
|
|
3
|
|
|
|
|
81
|
|
4
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
78
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
13
|
use base 'Text::APL::Base'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
938
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub translate { |
9
|
24
|
|
|
24
|
1
|
57
|
my $self = shift; |
10
|
24
|
|
|
|
|
44
|
my ($tape) = @_; |
11
|
|
|
|
|
|
|
|
12
|
24
|
|
|
|
|
36
|
my $code = ''; |
13
|
|
|
|
|
|
|
|
14
|
24
|
|
|
|
|
53
|
foreach my $token (@$tape) { |
15
|
31
|
100
|
|
|
|
77
|
if ($token->{type} eq 'expr') { |
|
|
100
|
|
|
|
|
|
16
|
18
|
|
|
|
|
35
|
my $value = $token->{value}; |
17
|
18
|
100
|
66
|
|
|
57
|
if (exists $token->{as_is} && $token->{as_is}) { |
18
|
5
|
|
|
|
|
17
|
$code .= '__print(do {' . $value . '});'; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
else { |
21
|
13
|
|
|
|
|
42
|
$code .= '__print_escaped(do {' . $value . '});'; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
elsif ($token->{type} eq 'exec') { |
25
|
9
|
|
|
|
|
18
|
$code .= $token->{value}; |
26
|
9
|
100
|
|
|
|
25
|
$code .= ';' unless $token->{line}; |
27
|
9
|
|
|
|
|
29
|
$code .= "\n"; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
else { |
30
|
4
|
|
|
|
|
15
|
$token->{value} =~ s/}/\\}/gms; |
31
|
4
|
|
|
|
|
10
|
$token->{value} =~ s/{/\\{/gms; |
32
|
4
|
|
|
|
|
15
|
$code .= '__print(q{' . $token->{value} . '});'; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
24
|
|
|
|
|
87
|
$code; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
1; |
40
|
|
|
|
|
|
|
__END__ |