line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::ToPerl6::Transformer::CompoundStatements::SwapForArguments; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
733
|
use 5.006001; |
|
1
|
|
|
|
|
5
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
55
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
6
|
1
|
|
|
1
|
|
4
|
use Readonly; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
47
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
4
|
use Perl::ToPerl6::Utils qw{ :severities }; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
9
|
1
|
|
|
|
|
51
|
use Perl::ToPerl6::Utils::PPI qw{ |
10
|
|
|
|
|
|
|
is_ppi_statement_compound |
11
|
|
|
|
|
|
|
insert_trailing_whitespace |
12
|
|
|
|
|
|
|
remove_trailing_whitespace |
13
|
1
|
|
|
1
|
|
113
|
}; |
|
1
|
|
|
|
|
2
|
|
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
5
|
use base 'Perl::ToPerl6::Transformer'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
414
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Readonly::Scalar my $DESC => q{Transform 'if()' to 'if ()'}; |
20
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => |
21
|
|
|
|
|
|
|
q{if(), elsif() and unless() need whitespace in order to not be interpreted as function calls}; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
1
|
0
|
5
|
sub run_after { return 'Operators::FormatOperators' } |
26
|
1
|
|
|
1
|
0
|
3
|
sub supported_parameters { return () } |
27
|
1
|
|
|
1
|
1
|
5
|
sub default_necessity { return $NECESSITY_HIGHEST } |
28
|
0
|
|
|
0
|
1
|
|
sub default_themes { return qw( core ) } |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my %map = ( |
33
|
|
|
|
|
|
|
for => 1, |
34
|
|
|
|
|
|
|
foreach => 1, |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my %scope_map = ( |
38
|
|
|
|
|
|
|
my => 1, |
39
|
|
|
|
|
|
|
local => 1, |
40
|
|
|
|
|
|
|
our => 1 |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub applies_to { |
44
|
|
|
|
|
|
|
return sub { |
45
|
0
|
0
|
0
|
0
|
|
|
is_ppi_statement_compound($_[1], %map) and |
46
|
|
|
|
|
|
|
( $_[1]->schild(1)->isa('PPI::Token::Word') or |
47
|
|
|
|
|
|
|
$_[1]->schild(1)->isa('PPI::Token::Symbol') ) |
48
|
|
|
|
|
|
|
} |
49
|
0
|
|
|
0
|
1
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub transform { |
54
|
0
|
|
|
0
|
0
|
|
my ($self, $elem, $doc) = @_; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# This ASCII art may be of use. |
57
|
|
|
|
|
|
|
# |
58
|
|
|
|
|
|
|
# $elem $loop_variable |
59
|
|
|
|
|
|
|
# | | |
60
|
|
|
|
|
|
|
# | | $whitespace |
61
|
|
|
|
|
|
|
# | | | |
62
|
|
|
|
|
|
|
# [ q{for}, q{ }, q{my}, q{ }, q{$x}, q{ }, q{(@x)} ] |
63
|
|
|
|
|
|
|
# | | | | | | | |
64
|
|
|
|
|
|
|
# | | X X | | | |
65
|
|
|
|
|
|
|
# | | | | | |
66
|
|
|
|
|
|
|
# | | ,-----------' | | |
67
|
|
|
|
|
|
|
# | | | ,------------' | |
68
|
|
|
|
|
|
|
# | | | | ,------------' |
69
|
|
|
|
|
|
|
# | | | | | |
70
|
|
|
|
|
|
|
# V | V V V |
71
|
|
|
|
|
|
|
# [ q{for}, q{ }, q{$x}, q{ }, q{(@x)} ] |
72
|
|
|
|
|
|
|
# | | | | | |
73
|
|
|
|
|
|
|
# | | '------|-----|--------------, |
74
|
|
|
|
|
|
|
# | `-------------, | | |
75
|
|
|
|
|
|
|
# | | | | | |
76
|
|
|
|
|
|
|
# | ,------------' | | | |
77
|
|
|
|
|
|
|
# | | .-------|---' | |
78
|
|
|
|
|
|
|
# | | | | | |
79
|
|
|
|
|
|
|
# | | | | + + | |
80
|
|
|
|
|
|
|
# V V V | | | V |
81
|
|
|
|
|
|
|
# [ q{for}, q{ }, q{(@x)}, q{ }, q{->}, q{ }, q{$x} ] |
82
|
|
|
|
|
|
|
# |
83
|
0
|
0
|
|
|
|
|
if ( $scope_map{$elem->schild(1)->content} ) { |
84
|
0
|
|
|
|
|
|
remove_trailing_whitespace($elem->schild(1)); |
85
|
0
|
|
|
|
|
|
$elem->schild(1)->delete; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
my $whitespace = remove_trailing_whitespace($elem->schild(1)); |
89
|
0
|
|
|
|
|
|
my $loop_variable = $elem->schild(1)->clone; |
90
|
0
|
|
|
|
|
|
$elem->schild(1)->remove; |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
$elem->schild(1)->insert_after( |
93
|
|
|
|
|
|
|
$loop_variable |
94
|
|
|
|
|
|
|
); |
95
|
0
|
|
|
|
|
|
insert_trailing_whitespace($elem->schild(1)); |
96
|
0
|
|
|
|
|
|
$elem->schild(1)->insert_after( |
97
|
|
|
|
|
|
|
PPI::Token::Operator->new('->') |
98
|
|
|
|
|
|
|
); |
99
|
0
|
|
|
|
|
|
insert_trailing_whitespace($elem->schild(1)); |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
return $self->transformation( $DESC, $EXPL, $elem ); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
__END__ |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=pod |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 NAME |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Perl::ToPerl6::Transformer::CompoundStatements::SwapForArguments - Swap C<for my $x ( @x ) { }> --> C<<for ( @x ) -> $x { }>> |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 AFFILIATION |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
This Transformer is part of the core L<Perl::ToPerl6|Perl::ToPerl6> |
120
|
|
|
|
|
|
|
distribution. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 DESCRIPTION |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Perl6 formats C<for my $x (@x) { }> as C<<for (@a) -> $x>>: |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
for $x (@x) { } --> for (@x) -> $x { } |
128
|
|
|
|
|
|
|
for my $x (@x) { } --> for (@x) -> $x { } |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 CONFIGURATION |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
This Transformer is not configurable except for the standard options. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 AUTHOR |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Jeffrey Goff <drforr@pobox.com> |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 COPYRIGHT |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Copyright (c) 2015 Jeffrey Goff |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
143
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=cut |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
############################################################################## |
148
|
|
|
|
|
|
|
# Local Variables: |
149
|
|
|
|
|
|
|
# mode: cperl |
150
|
|
|
|
|
|
|
# cperl-indent-level: 4 |
151
|
|
|
|
|
|
|
# fill-column: 78 |
152
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
153
|
|
|
|
|
|
|
# c-indentation-style: bsd |
154
|
|
|
|
|
|
|
# End: |
155
|
|
|
|
|
|
|
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : |