| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
=head1 NAME |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
PPIx::Regexp::Node::Range - Represent a character range in a character class |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use PPIx::Regexp::Dumper; |
|
8
|
|
|
|
|
|
|
PPIx::Regexp::Dumper->new( 'qr{[a-z]}smx' ) |
|
9
|
|
|
|
|
|
|
->print(); |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 INHERITANCE |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
C is a |
|
14
|
|
|
|
|
|
|
L. |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
C has no descendants. |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
This class represents a character range in a character class. It is a |
|
21
|
|
|
|
|
|
|
node rather than a structure because there are no delimiters. The |
|
22
|
|
|
|
|
|
|
content is simply the two literals with the '-' operator between them. |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 METHODS |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
This class provides no public methods beyond those provided by its |
|
27
|
|
|
|
|
|
|
superclass. |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
package PPIx::Regexp::Node::Range; |
|
32
|
|
|
|
|
|
|
|
|
33
|
9
|
|
|
9
|
|
58
|
use strict; |
|
|
9
|
|
|
|
|
16
|
|
|
|
9
|
|
|
|
|
251
|
|
|
34
|
9
|
|
|
9
|
|
104
|
use warnings; |
|
|
9
|
|
|
|
|
28
|
|
|
|
9
|
|
|
|
|
256
|
|
|
35
|
|
|
|
|
|
|
|
|
36
|
9
|
|
|
9
|
|
43
|
use base qw{ PPIx::Regexp::Node }; |
|
|
9
|
|
|
|
|
16
|
|
|
|
9
|
|
|
|
|
787
|
|
|
37
|
|
|
|
|
|
|
|
|
38
|
9
|
|
|
|
|
5551
|
use PPIx::Regexp::Constant qw{ |
|
39
|
|
|
|
|
|
|
MSG_PROHIBITED_BY_STRICT |
|
40
|
|
|
|
|
|
|
@CARP_NOT |
|
41
|
9
|
|
|
9
|
|
61
|
}; |
|
|
9
|
|
|
|
|
16
|
|
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
our $VERSION = '0.088'; |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub explain { |
|
46
|
1
|
|
|
1
|
1
|
11
|
my ( $self ) = @_; |
|
47
|
1
|
50
|
|
|
|
8
|
my $first = $self->schild( 0 ) |
|
48
|
|
|
|
|
|
|
or return $self->__no_explanation(); |
|
49
|
1
|
50
|
|
|
|
4
|
my $last = $self->schild( -1 ) |
|
50
|
|
|
|
|
|
|
or return $self->__no_explanation(); |
|
51
|
1
|
|
|
|
|
6
|
return sprintf q, |
|
52
|
|
|
|
|
|
|
$first->content(), $last->content(); |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub __PPIX_LEXER__finalize { |
|
56
|
13
|
|
|
13
|
|
39
|
my ( $self, $lexer ) = @_; |
|
57
|
|
|
|
|
|
|
|
|
58
|
13
|
|
|
|
|
78
|
my $rslt = $self->SUPER::__PPIX_LEXER__finalize( $lexer ); |
|
59
|
|
|
|
|
|
|
|
|
60
|
13
|
100
|
|
|
|
64
|
if ( $lexer->strict() ) { |
|
61
|
|
|
|
|
|
|
# If strict is in effect, we're an error unless both ends of the |
|
62
|
|
|
|
|
|
|
# range are portable. |
|
63
|
3
|
|
|
|
|
25
|
my @kids = $self->schildren(); |
|
64
|
3
|
|
|
|
|
19
|
delete $self->{_range_start}; # Context for compatibility. |
|
65
|
3
|
|
|
|
|
9
|
foreach my $inx ( 0, -1 ) { |
|
66
|
6
|
|
|
|
|
17
|
my $kid = $kids[$inx]; |
|
67
|
|
|
|
|
|
|
# If we're not a literal, we can not make the test, so we |
|
68
|
|
|
|
|
|
|
# blindly accept it. |
|
69
|
6
|
50
|
|
|
|
24
|
$kid->isa( 'PPIx::Regexp::Token::Literal' ) |
|
70
|
|
|
|
|
|
|
or next; |
|
71
|
6
|
|
|
|
|
20
|
my $content = $kid->content(); |
|
72
|
6
|
100
|
66
|
|
|
49
|
$content =~ m/ \A (?: [[:alnum:]] | \\N\{ .* \} ) \z /smx |
|
73
|
|
|
|
|
|
|
and $self->_range_ends_compatible( $content ) |
|
74
|
|
|
|
|
|
|
or return $self->_prohibited_by_strict( $rslt ); |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
11
|
|
|
|
|
38
|
return $rslt; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub _prohibited_by_strict { |
|
82
|
2
|
|
|
2
|
|
10
|
my ( $self, $rslt ) = @_; |
|
83
|
2
|
|
|
|
|
5
|
delete $self->{_range_start}; |
|
84
|
2
|
|
|
|
|
32
|
$rslt += $self->__error( |
|
85
|
|
|
|
|
|
|
join( ' ', 'Non-portable range ends', MSG_PROHIBITED_BY_STRICT ), |
|
86
|
|
|
|
|
|
|
perl_version_introduced => '5.023008', |
|
87
|
|
|
|
|
|
|
); |
|
88
|
2
|
|
|
|
|
12
|
return $rslt; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub _range_ends_compatible { |
|
92
|
6
|
|
|
6
|
|
16
|
my ( $self, $content ) = @_; |
|
93
|
6
|
100
|
|
|
|
24
|
if ( defined( my $start = $self->{_range_start} ) ) { |
|
94
|
3
|
|
|
|
|
48
|
foreach my $re ( |
|
95
|
|
|
|
|
|
|
qr{ \A [[:upper:]] \z }smx, |
|
96
|
|
|
|
|
|
|
qr{ \A [[:lower:]] \z }smx, |
|
97
|
|
|
|
|
|
|
qr{ \A [0-9] \z }smx, |
|
98
|
|
|
|
|
|
|
qr{ \A \\N \{ .* \} }smx, |
|
99
|
|
|
|
|
|
|
) { |
|
100
|
3
|
50
|
|
|
|
22
|
$start =~ $re |
|
101
|
|
|
|
|
|
|
or next; |
|
102
|
3
|
|
|
|
|
43
|
return $content =~ $re; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
0
|
|
|
|
|
0
|
return; |
|
105
|
|
|
|
|
|
|
} else { |
|
106
|
3
|
|
|
|
|
8
|
$self->{_range_start} = $content; |
|
107
|
3
|
|
|
|
|
30
|
return 1; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
__END__ |