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