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