line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::ToPerl6::Transformer::Operators::FormatOperators; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
754
|
use 5.006001; |
|
1
|
|
|
|
|
4
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
61
|
|
6
|
1
|
|
|
1
|
|
4
|
use Readonly; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use Perl::ToPerl6::Utils qw{ :severities }; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
9
|
1
|
|
|
|
|
68
|
use Perl::ToPerl6::Utils::PPI qw{ |
10
|
|
|
|
|
|
|
is_ppi_token_operator |
11
|
|
|
|
|
|
|
remove_trailing_whitespace |
12
|
|
|
|
|
|
|
insert_trailing_whitespace |
13
|
|
|
|
|
|
|
remove_leading_whitespace |
14
|
|
|
|
|
|
|
insert_leading_whitespace |
15
|
1
|
|
|
1
|
|
110
|
}; |
|
1
|
|
|
|
|
2
|
|
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
4
|
use base 'Perl::ToPerl6::Transformer'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
569
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Readonly::Scalar my $DESC => q{Transform operators to perl6 equivalents}; |
22
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => |
23
|
|
|
|
|
|
|
q{Operators, notably '->' and '!', change names in Perl6}; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my %after = ( |
28
|
|
|
|
|
|
|
and => 1, |
29
|
|
|
|
|
|
|
or => 1, |
30
|
|
|
|
|
|
|
xor => 1, |
31
|
|
|
|
|
|
|
not => 1, |
32
|
|
|
|
|
|
|
cmp => 1, |
33
|
|
|
|
|
|
|
lt => 1, |
34
|
|
|
|
|
|
|
gt => 1, |
35
|
|
|
|
|
|
|
le => 1, |
36
|
|
|
|
|
|
|
ge => 1, |
37
|
|
|
|
|
|
|
eq => 1, |
38
|
|
|
|
|
|
|
ne => 1, |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my %before = ( |
42
|
|
|
|
|
|
|
'<' => 1, |
43
|
|
|
|
|
|
|
'<=' => 1, |
44
|
|
|
|
|
|
|
'<=>' => 1, |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my %mutate = ( |
48
|
|
|
|
|
|
|
# From the unary operators: |
49
|
|
|
|
|
|
|
# |
50
|
|
|
|
|
|
|
# '++', '--' are unchanged. |
51
|
|
|
|
|
|
|
# '!' is unchanged. |
52
|
|
|
|
|
|
|
# 'not' is unchanged. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# '^', '!' are changed. |
55
|
|
|
|
|
|
|
'^' => '+^', |
56
|
|
|
|
|
|
|
'!' => '?^', |
57
|
|
|
|
|
|
|
'~' => '+^', |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# ',' is unchanged. |
60
|
|
|
|
|
|
|
# '+', '-', '*', '/', '%', '**' are unchanged. |
61
|
|
|
|
|
|
|
# '&&', '||', '^' are unchanged. |
62
|
|
|
|
|
|
|
# 'and', 'or', 'xor' are unchanged. |
63
|
|
|
|
|
|
|
# '==', '!=', '<', '>', '<=', '>=' are unchanged. |
64
|
|
|
|
|
|
|
# 'eq', 'ne', 'lt', 'gt', 'le', 'ge' are unchanged. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# '<=>' behaves similarly. |
67
|
|
|
|
|
|
|
# 'cmp' is now named 'leg'. |
68
|
|
|
|
|
|
|
# '~~' is unchanged, but the semantics are wildly different. |
69
|
|
|
|
|
|
|
'cmp' => 'leg', |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# '&', '|', '^' are changed, and string semantics are different. |
72
|
|
|
|
|
|
|
'&' => '+&', '&=' => '+&=', |
73
|
|
|
|
|
|
|
'|' => '+|', '|=' => '+|=', |
74
|
|
|
|
|
|
|
'^' => '+^', '^=' => '+^=', |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
'<<' => '+<', '<<=' => '+<=', |
77
|
|
|
|
|
|
|
'>>' => '+>', '>>=' => '+>=', |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
'.' => '~', '.=' => '~=', |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
'->' => '.', |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
'=~' => '~~', |
84
|
|
|
|
|
|
|
'!~' => '!~~', |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# And finally, the lone ternary operator: |
87
|
|
|
|
|
|
|
# |
88
|
|
|
|
|
|
|
'?' => '??', |
89
|
|
|
|
|
|
|
':' => '!!', |
90
|
|
|
|
|
|
|
); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
93
|
|
|
|
|
|
|
|
94
|
1
|
|
|
1
|
0
|
4
|
sub supported_parameters { return () } |
95
|
1
|
|
|
1
|
1
|
5
|
sub default_necessity { return $NECESSITY_HIGHEST } |
96
|
0
|
|
|
0
|
1
|
|
sub default_themes { return qw( core ) } |
97
|
|
|
|
|
|
|
sub applies_to { |
98
|
|
|
|
|
|
|
return sub { |
99
|
0
|
0
|
0
|
0
|
|
|
is_ppi_token_operator($_[1], %mutate, %before, %after) or |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
100
|
|
|
|
|
|
|
( $_[1]->isa('PPI::Token::Label') and |
101
|
|
|
|
|
|
|
$_[1]->content =~ /\:$/ and |
102
|
|
|
|
|
|
|
$_[1]->sprevious_sibling and |
103
|
|
|
|
|
|
|
$_[1]->sprevious_sibling->isa('PPI::Token::Operator') and |
104
|
|
|
|
|
|
|
$_[1]->sprevious_sibling->content eq '?' ) |
105
|
|
|
|
|
|
|
} |
106
|
0
|
|
|
0
|
1
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub transform { |
111
|
0
|
|
|
0
|
0
|
|
my ($self, $elem, $doc) = @_; |
112
|
0
|
0
|
|
|
|
|
if ( $elem->isa('PPI::Token::Label') ) { |
113
|
0
|
|
|
|
|
|
my $old_content = $elem->content; |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
$old_content =~ s< : $ ><!!>sx; |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
$elem->set_content( $old_content ); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# nonassoc ++ |
121
|
|
|
|
|
|
|
# nonassoc -- |
122
|
|
|
|
|
|
|
# right ! |
123
|
|
|
|
|
|
|
# right ~ |
124
|
|
|
|
|
|
|
# right \ |
125
|
|
|
|
|
|
|
# right + |
126
|
|
|
|
|
|
|
# right - |
127
|
|
|
|
|
|
|
# left * |
128
|
|
|
|
|
|
|
# left % |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# nonassoc ~~ |
131
|
|
|
|
|
|
|
# left & |
132
|
|
|
|
|
|
|
# right *= etc. goto last next redo dump |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# nonassoc list operators (rightward) |
135
|
|
|
|
|
|
|
# right not |
136
|
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
my $old_content = $elem->content; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
$elem->set_content( $mutate{$old_content} ) if |
140
|
0
|
0
|
|
|
|
|
exists $mutate{$old_content}; |
141
|
|
|
|
|
|
|
|
142
|
0
|
0
|
|
|
|
|
if ( $old_content eq '=>' ) { # XXX This is a special case. |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
elsif ( $old_content eq 'x' ) { # XXX This is a special case. |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
elsif ( $old_content eq '..' ) { # XXX This is a special case. |
147
|
|
|
|
|
|
|
# List version is unchanged. |
148
|
|
|
|
|
|
|
# Scalar version is now 'ff' |
149
|
0
|
|
|
|
|
|
$elem->set_content('ff XXX'); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
elsif ( $old_content eq '...' ) { # XXX This is a special case. |
152
|
|
|
|
|
|
|
# List version is unchanged. |
153
|
|
|
|
|
|
|
# Scalar version is now 'fff' |
154
|
0
|
|
|
|
|
|
$elem->set_content('fff XXX'); |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
0
|
0
|
|
|
|
|
if ( $elem->content eq '.' ) { |
158
|
0
|
|
|
|
|
|
remove_trailing_whitespace($elem); |
159
|
0
|
|
|
|
|
|
remove_leading_whitespace($elem); |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
0
|
0
|
|
|
|
|
if ( $before{$elem->content} ) { |
|
|
0
|
|
|
|
|
|
163
|
0
|
|
|
|
|
|
insert_leading_whitespace($elem); |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
elsif ( $after{$elem->content} ) { |
166
|
0
|
|
|
|
|
|
insert_trailing_whitespace($elem); |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
0
|
|
|
|
|
|
return $self->transformation( $DESC, $EXPL, $elem ); |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
1; |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
__END__ |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=pod |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head1 NAME |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Perl::ToPerl6::Transformer::Operators::FormatOperators - Transform '->', '!" &c to their Perl6 equivalents |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 AFFILIATION |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
This Transformer is part of the core L<Perl::ToPerl6|Perl::ToPerl6> |
188
|
|
|
|
|
|
|
distribution. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 DESCRIPTION |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Several operators in Perl5 have been renamed or repurposed in Perl6. For instance, the various negations such as '~', '^' and '!' have been unified under '^', and the previous numeric, logical and Boolean contexts are now represented in the first character, so '!' is now '?^' to repreent Boolean ('?') negation ('^'): |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
~32 --> +^32 |
196
|
|
|
|
|
|
|
!$x --> ?^$x |
197
|
|
|
|
|
|
|
1 ? 2 : 3 --> 1 ?? 2 !! 3 |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Transforms operators outside of comments, heredocs, strings and POD. |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head1 CONFIGURATION |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
This Transformer is not configurable except for the standard options. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head1 AUTHOR |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
Jeffrey Goff <drforr@pobox.com> |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=head1 COPYRIGHT |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
Copyright (c) 2015 Jeffrey Goff |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
214
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=cut |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
############################################################################## |
219
|
|
|
|
|
|
|
# Local Variables: |
220
|
|
|
|
|
|
|
# mode: cperl |
221
|
|
|
|
|
|
|
# cperl-indent-level: 4 |
222
|
|
|
|
|
|
|
# fill-column: 78 |
223
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
224
|
|
|
|
|
|
|
# c-indentation-style: bsd |
225
|
|
|
|
|
|
|
# End: |
226
|
|
|
|
|
|
|
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : |