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