line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
PPIx::Regexp::Token::Condition - Represent the condition of a switch |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use PPIx::Regexp::Dumper; |
8
|
|
|
|
|
|
|
PPIx::Regexp::Dumper->new( 'qr{(?(1)foo|bar)}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 the condition portion of a switch or conditional |
21
|
|
|
|
|
|
|
expression, provided that condition is reasonably represented as a |
22
|
|
|
|
|
|
|
token. |
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::Token::Condition; |
32
|
|
|
|
|
|
|
|
33
|
9
|
|
|
9
|
|
58
|
use strict; |
|
9
|
|
|
|
|
34
|
|
|
9
|
|
|
|
|
245
|
|
34
|
9
|
|
|
9
|
|
49
|
use warnings; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
251
|
|
35
|
|
|
|
|
|
|
|
36
|
9
|
|
|
9
|
|
55
|
use base qw{ PPIx::Regexp::Token::Reference }; |
|
9
|
|
|
|
|
55
|
|
|
9
|
|
|
|
|
800
|
|
37
|
|
|
|
|
|
|
|
38
|
9
|
|
|
9
|
|
62
|
use PPIx::Regexp::Constant qw{ RE_CAPTURE_NAME @CARP_NOT }; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
5301
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
our $VERSION = '0.088'; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
{ |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
my %explanation = ( |
45
|
|
|
|
|
|
|
'(DEFINE)' => 'Define a group to be recursed into', |
46
|
|
|
|
|
|
|
'(R)' => 'True if recursing', |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub explain { |
50
|
6
|
|
|
6
|
1
|
12
|
my ( $self ) = @_; |
51
|
6
|
|
|
|
|
19
|
my $content = $self->content(); |
52
|
6
|
100
|
|
|
|
33
|
if ( defined( my $expl = $explanation{$content} ) ) { |
53
|
2
|
|
|
|
|
5
|
return $expl; |
54
|
|
|
|
|
|
|
} |
55
|
4
|
100
|
|
|
|
47
|
if ( $content =~ m/ \A [(] R /smx ) { # ) |
56
|
2
|
100
|
|
|
|
11
|
$self->is_named() |
57
|
|
|
|
|
|
|
and return sprintf |
58
|
|
|
|
|
|
|
q, |
59
|
|
|
|
|
|
|
$self->name(); |
60
|
1
|
|
|
|
|
5
|
return sprintf |
61
|
|
|
|
|
|
|
q, |
62
|
|
|
|
|
|
|
$self->absolute(); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
$self->is_named() |
65
|
2
|
100
|
|
|
|
12
|
and return sprintf |
66
|
|
|
|
|
|
|
q, |
67
|
|
|
|
|
|
|
$self->name(); |
68
|
1
|
|
|
|
|
5
|
return sprintf |
69
|
|
|
|
|
|
|
q, |
70
|
|
|
|
|
|
|
$self->absolute(); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub perl_version_introduced { |
76
|
19
|
|
|
19
|
1
|
2317
|
my ( $self ) = @_; |
77
|
19
|
100
|
|
|
|
69
|
$self->content() =~ m/ \A [(] [0-9]+ [)] \z /smx |
78
|
|
|
|
|
|
|
and return '5.005'; |
79
|
13
|
|
|
|
|
55
|
return '5.009005'; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
my @recognize = ( |
83
|
|
|
|
|
|
|
[ qr{ \A \( (?: ( [0-9]+ ) | R ( [0-9]+ ) ) \) }smx, |
84
|
|
|
|
|
|
|
{ is_named => 0 } ], |
85
|
|
|
|
|
|
|
[ qr{ \A \( R \) }smx, |
86
|
|
|
|
|
|
|
{ is_named => 0, capture => '0' } ], |
87
|
|
|
|
|
|
|
[ qr{ \A \( (?: < ( @{[ RE_CAPTURE_NAME ]} ) > | |
88
|
|
|
|
|
|
|
' ( @{[ RE_CAPTURE_NAME ]} ) ' | |
89
|
|
|
|
|
|
|
R & ( @{[ RE_CAPTURE_NAME ]} ) ) \) }smxo, |
90
|
|
|
|
|
|
|
{ is_named => 1} ], |
91
|
|
|
|
|
|
|
[ qr{ \A \( DEFINE \) }smx, |
92
|
|
|
|
|
|
|
{ is_named => 0, capture => '0' } ], |
93
|
|
|
|
|
|
|
); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# This must be implemented by tokens which do not recognize themselves. |
96
|
|
|
|
|
|
|
# The return is a list of list references. Each list reference must |
97
|
|
|
|
|
|
|
# contain a regular expression that recognizes the token, and optionally |
98
|
|
|
|
|
|
|
# a reference to a hash to pass to make_token as the class-specific |
99
|
|
|
|
|
|
|
# arguments. The regular expression MUST be anchored to the beginning of |
100
|
|
|
|
|
|
|
# the string. |
101
|
|
|
|
|
|
|
sub __PPIX_TOKEN__recognize { |
102
|
8
|
|
|
8
|
|
21
|
return @recognize; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# Return true if the token can be quantified, and false otherwise |
106
|
|
|
|
|
|
|
# sub can_be_quantified { return }; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub __PPIX_TOKENIZER__regexp { |
109
|
32
|
|
|
32
|
|
119
|
my ( undef, $tokenizer ) = @_; # Invocant, $character unused |
110
|
|
|
|
|
|
|
|
111
|
32
|
|
|
|
|
91
|
foreach ( @recognize ) { |
112
|
78
|
|
|
|
|
118
|
my ( $re, $arg ) = @{ $_ }; |
|
78
|
|
|
|
|
194
|
|
113
|
78
|
100
|
|
|
|
197
|
my $accept = $tokenizer->find_regexp( $re ) or next; |
114
|
26
|
|
|
|
|
119
|
return $tokenizer->make_token( $accept, __PACKAGE__, $arg ); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
6
|
|
|
|
|
22
|
return; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
__END__ |