| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Perl::ToPerl6::Transformer::CompoundStatements::AddWhitespace; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
718
|
use 5.006001; |
|
|
1
|
|
|
|
|
4
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
18
|
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
21
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use Readonly; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
53
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
4
|
use Perl::ToPerl6::Utils qw{ :severities }; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
45
|
|
|
9
|
1
|
|
|
|
|
51
|
use Perl::ToPerl6::Utils::PPI qw{ |
|
10
|
|
|
|
|
|
|
is_ppi_statement_compound |
|
11
|
|
|
|
|
|
|
is_ppi_token_word |
|
12
|
|
|
|
|
|
|
insert_trailing_whitespace |
|
13
|
1
|
|
|
1
|
|
121
|
}; |
|
|
1
|
|
|
|
|
2
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
4
|
use base 'Perl::ToPerl6::Transformer'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
311
|
|
|
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
|
|
|
|
|
|
|
my %map = ( |
|
26
|
|
|
|
|
|
|
if => 1, |
|
27
|
|
|
|
|
|
|
elsif => 1, |
|
28
|
|
|
|
|
|
|
unless => 1, |
|
29
|
|
|
|
|
|
|
given => 1, |
|
30
|
|
|
|
|
|
|
when => 1, |
|
31
|
|
|
|
|
|
|
while => 1, |
|
32
|
|
|
|
|
|
|
until => 1, |
|
33
|
|
|
|
|
|
|
for => 1, |
|
34
|
|
|
|
|
|
|
foreach => 1, |
|
35
|
|
|
|
|
|
|
); |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
|
38
|
|
|
|
|
|
|
|
|
39
|
1
|
|
|
1
|
0
|
4
|
sub supported_parameters { return () } |
|
40
|
1
|
|
|
1
|
1
|
5
|
sub default_necessity { return $NECESSITY_HIGHEST } |
|
41
|
0
|
|
|
0
|
1
|
|
sub default_themes { return qw( core ) } |
|
42
|
|
|
|
|
|
|
sub applies_to { |
|
43
|
|
|
|
|
|
|
return sub { |
|
44
|
0
|
0
|
0
|
0
|
|
|
is_ppi_statement_compound($_[1], %map) or |
|
45
|
|
|
|
|
|
|
$_[1]->isa('PPI::Statement::Given') or |
|
46
|
|
|
|
|
|
|
$_[1]->isa('PPI::Statement::When') |
|
47
|
|
|
|
|
|
|
} |
|
48
|
0
|
|
|
0
|
1
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# |
|
53
|
|
|
|
|
|
|
# Note to the reader: |
|
54
|
|
|
|
|
|
|
# |
|
55
|
|
|
|
|
|
|
# $elem (PPI::Statement::Compound) |
|
56
|
|
|
|
|
|
|
# \ |
|
57
|
|
|
|
|
|
|
# \ 0 1 2 3 4 # count by child() |
|
58
|
|
|
|
|
|
|
# \0 1 2 3 4 # count by schild() |
|
59
|
|
|
|
|
|
|
# +-----+-----+-----+-----+ |
|
60
|
|
|
|
|
|
|
# | | | | | |
|
61
|
|
|
|
|
|
|
# V V V V V |
|
62
|
|
|
|
|
|
|
# if (...) {...} elsif (...) |
|
63
|
|
|
|
|
|
|
# |
|
64
|
|
|
|
|
|
|
# After insertion, the tree looks like this: |
|
65
|
|
|
|
|
|
|
# |
|
66
|
|
|
|
|
|
|
# $elem (PPI::Statement::Compound) |
|
67
|
|
|
|
|
|
|
# \ |
|
68
|
|
|
|
|
|
|
# \ 0 1 2 3 4 5 6 # count by child() |
|
69
|
|
|
|
|
|
|
# \0 1 2 3 4 # count by schild() |
|
70
|
|
|
|
|
|
|
# +-----+-----+-----+-----+-----+----+ |
|
71
|
|
|
|
|
|
|
# | | | | | | | |
|
72
|
|
|
|
|
|
|
# V V V V V V V |
|
73
|
|
|
|
|
|
|
# if ' ' (...) {...} elsif ' ' (...) |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub transform { |
|
76
|
0
|
|
|
0
|
0
|
|
my ($self, $elem, $doc) = @_; |
|
77
|
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
for my $child ( $elem->schildren ) { |
|
79
|
0
|
0
|
|
|
|
|
next unless is_ppi_token_word($child, %map); |
|
80
|
0
|
|
|
|
|
|
insert_trailing_whitespace($child); |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
return $self->transformation( $DESC, $EXPL, $elem ); |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
__END__ |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=pod |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 NAME |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Perl::ToPerl6::Transformer::CompoundStatements::AddWhitespace - Add whitespace between conditionals 'if', 'unless' &c and '(...)' |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 AFFILIATION |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
This Transformer is part of the core L<Perl::ToPerl6|Perl::ToPerl6> |
|
102
|
|
|
|
|
|
|
distribution. |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
While Perl6 conditionals allow parentheses, they need whitespace between the bareword C<if> and the opening parenthesis to avoid being interpreted as a function call: |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
if(1) { } elsif(){} --> if (1) { } elsif(){} |
|
110
|
|
|
|
|
|
|
if (1) { } elsif(){} --> if (1) { } elsif(){} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 CONFIGURATION |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
This Transformer is not configurable except for the standard options. |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 AUTHOR |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Jeffrey Goff <drforr@pobox.com> |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Copyright (c) 2015 Jeffrey Goff |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
|
125
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=cut |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
############################################################################## |
|
130
|
|
|
|
|
|
|
# Local Variables: |
|
131
|
|
|
|
|
|
|
# mode: cperl |
|
132
|
|
|
|
|
|
|
# cperl-indent-level: 4 |
|
133
|
|
|
|
|
|
|
# fill-column: 78 |
|
134
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
|
135
|
|
|
|
|
|
|
# c-indentation-style: bsd |
|
136
|
|
|
|
|
|
|
# End: |
|
137
|
|
|
|
|
|
|
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : |