line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::ToPerl6::Transformer::BasicTypes::Integers::RewriteHexNumbers; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
800
|
use 5.006001; |
|
1
|
|
|
|
|
4
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
6
|
1
|
|
|
1
|
|
4
|
use Readonly; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
46
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
4
|
use Perl::ToPerl6::Utils qw{ :severities }; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
47
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
127
|
use base 'Perl::ToPerl6::Transformer'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
282
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Readonly::Scalar my $DESC => q{Transforms 0x0123 into :16<0123>}; |
15
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => q{Perl6 hexadecimal integers look like :16<0123>}; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
18
|
|
|
|
|
|
|
|
19
|
2
|
|
|
2
|
0
|
7
|
sub supported_parameters { return () } |
20
|
1
|
|
|
1
|
1
|
6
|
sub default_necessity { return $NECESSITY_HIGHEST } |
21
|
0
|
|
|
0
|
1
|
|
sub default_themes { return qw( core ) } |
22
|
0
|
|
|
0
|
1
|
|
sub applies_to { return 'PPI::Token::Number::Hex' } |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub transform { |
27
|
0
|
|
|
0
|
0
|
|
my ($self, $elem, $doc) = @_; |
28
|
0
|
0
|
0
|
|
|
|
return unless $elem and $elem->content; # XXX Shouldn't be required, but it is. |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my $old_content = $elem->content; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# |
33
|
|
|
|
|
|
|
# Remove leading '0x' and optional leading underscore |
34
|
|
|
|
|
|
|
# |
35
|
0
|
|
|
|
|
|
$old_content =~ s{^0x[_]?}{}i; |
36
|
0
|
|
|
|
|
|
$old_content =~ s{[_]$}{}; |
37
|
0
|
|
|
|
|
|
$old_content =~ s{[_]+}{_}g; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my $new_content = ':16<' . $old_content . '>'; |
40
|
0
|
|
|
|
|
|
$elem->set_content( $new_content ); |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
return $self->transformation( $DESC, $EXPL, $elem ); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
__END__ |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=pod |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 NAME |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Perl::ToPerl6::Transformer::BasicTypes::Integers::RewriteHexNumbers - Format 0x1234 properly |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 AFFILIATION |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
This Transformer is part of the core L<Perl::ToPerl6|Perl::ToPerl6> |
61
|
|
|
|
|
|
|
distribution. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 DESCRIPTION |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Perl6 hexadecimal literals have the format ':16<01_78_ab_ef>'. Perl6 enforces the rule that separators must occur between digits, and only one separator character at a time: |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
0x01 -> :16<01> |
69
|
|
|
|
|
|
|
0x01af -> :16<01af> |
70
|
|
|
|
|
|
|
0x010_af -> :16<010_af> |
71
|
|
|
|
|
|
|
0x_010__af_ -> :16<010_af> |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Transforms hexadecimal numbers outside of comments, heredocs, strings and POD. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 CONFIGURATION |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
This Transformer is not configurable except for the standard options. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 AUTHOR |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Jeffrey Goff <drforr@pobox.com> |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 COPYRIGHT |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Copyright (c) 2015 Jeffrey Goff |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
88
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
############################################################################## |
93
|
|
|
|
|
|
|
# Local Variables: |
94
|
|
|
|
|
|
|
# mode: cperl |
95
|
|
|
|
|
|
|
# cperl-indent-level: 4 |
96
|
|
|
|
|
|
|
# fill-column: 78 |
97
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
98
|
|
|
|
|
|
|
# c-indentation-style: bsd |
99
|
|
|
|
|
|
|
# End: |
100
|
|
|
|
|
|
|
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : |