line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::ToPerl6::Transformer::Regexes::StandardizeDelimiters; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
733
|
use 5.006001; |
|
1
|
|
|
|
|
5
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
17
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
6
|
1
|
|
|
1
|
|
4
|
use Readonly; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
14
|
use Perl::ToPerl6::Utils qw{ :severities }; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
51
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
105
|
use base 'Perl::ToPerl6::Transformer'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
493
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Readonly::Scalar my $DESC => q{Regex delimiters can no longer be alphanumeric}; |
15
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => q{Regex delimiters can no longer be alphanumeric}; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
0
|
3
|
sub supported_parameters { return () } |
20
|
1
|
|
|
1
|
1
|
5
|
sub default_necessity { return $NECESSITY_HIGHEST } |
21
|
0
|
|
|
0
|
1
|
|
sub default_themes { return qw( core ) } |
22
|
|
|
|
|
|
|
sub applies_to { |
23
|
|
|
|
|
|
|
return sub { |
24
|
|
|
|
|
|
|
$_[1]->isa('PPI::Token::Regexp') and |
25
|
0
|
0
|
|
0
|
|
|
$_[1]->{sections}[0]{type} =~ /[a-zA-Z0-9#]/ |
26
|
|
|
|
|
|
|
} |
27
|
0
|
|
|
0
|
1
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub transform { |
32
|
0
|
|
|
0
|
0
|
|
my ($self, $elem, $doc) = @_; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my @content; |
35
|
0
|
|
|
|
|
|
for ( @{ $elem->{sections} } ) { |
|
0
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $content = substr( $elem->content, $_->{position}, $_->{size} ); |
37
|
0
|
|
|
|
|
|
$content =~ s{/}{\\/}g; # XXX this could be a problem. |
38
|
0
|
|
|
|
|
|
$_->{position}--; # Account for the eventual lack of whitespace. |
39
|
0
|
|
|
|
|
|
$_->{type} = '//'; |
40
|
0
|
|
|
|
|
|
push @content, $content; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
my ( $operator ) = $elem->content =~ m{^(m|s|y|tr)}; |
44
|
0
|
|
|
|
|
|
my $num_modifiers = keys %{ $elem->get_modifiers }; |
|
0
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my $modifiers = substr( $elem->content, -$num_modifiers, $num_modifiers ); |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
my $new_content = $operator . '/' . |
48
|
|
|
|
|
|
|
join('/', @content) . '/' . |
49
|
|
|
|
|
|
|
$modifiers; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
$elem->{separator} = '/'; |
52
|
0
|
|
|
|
|
|
$elem->set_content( $new_content ); |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
return $self->transformation( $DESC, $EXPL, $elem ); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
__END__ |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=pod |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 NAME |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Perl::ToPerl6::Transformer::Regexp::StandardizeDelimiters - Regexen can no longer have alphanumeric delimiters |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 AFFILIATION |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
This Transformer is part of the core L<Perl::ToPerl6|Perl::ToPerl6> |
73
|
|
|
|
|
|
|
distribution. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 DESCRIPTION |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Perl6 regular expression delimiters can no longer be alphanumeric: |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
m mfoom --> m/foo/ |
81
|
|
|
|
|
|
|
m mf/oom --> m/f\/oo/ # Escape the new delimiter |
82
|
|
|
|
|
|
|
m f\foof --> m/\foo/ # Otherwise do not alter the contents. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Transforms regular expressions outside of comments, heredocs, strings and POD. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 CONFIGURATION |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
This Transformer is not configurable except for the standard options. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 AUTHOR |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Jeffrey Goff <drforr@pobox.com> |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 COPYRIGHT |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Copyright (c) 2015 Jeffrey Goff |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
99
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=cut |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
############################################################################## |
104
|
|
|
|
|
|
|
# Local Variables: |
105
|
|
|
|
|
|
|
# mode: cperl |
106
|
|
|
|
|
|
|
# cperl-indent-level: 4 |
107
|
|
|
|
|
|
|
# fill-column: 78 |
108
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
109
|
|
|
|
|
|
|
# c-indentation-style: bsd |
110
|
|
|
|
|
|
|
# End: |
111
|
|
|
|
|
|
|
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : |