line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
PPIx::Regexp::Structure::Regexp - Represent the top-level regular expression |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use PPIx::Regexp::Dumper; |
8
|
|
|
|
|
|
|
PPIx::Regexp::Dumper->new( 'qr{foo}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 top-level regular expression. In the example |
21
|
|
|
|
|
|
|
given in the L, the C<{foo}> will be represented by this |
22
|
|
|
|
|
|
|
class. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 METHODS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
This class provides the following public methods. Methods not documented |
27
|
|
|
|
|
|
|
here are private, and unsupported in the sense that the author reserves |
28
|
|
|
|
|
|
|
the right to change or remove them without notice. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
package PPIx::Regexp::Structure::Regexp; |
33
|
|
|
|
|
|
|
|
34
|
9
|
|
|
9
|
|
61
|
use strict; |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
260
|
|
35
|
9
|
|
|
9
|
|
46
|
use warnings; |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
284
|
|
36
|
|
|
|
|
|
|
|
37
|
9
|
|
|
9
|
|
55
|
use base qw{ PPIx::Regexp::Structure::Main }; |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
849
|
|
38
|
|
|
|
|
|
|
|
39
|
9
|
|
|
9
|
|
61
|
use PPIx::Regexp::Constant qw{ @CARP_NOT }; |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
3123
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
our $VERSION = '0.088'; |
42
|
|
|
|
|
|
|
|
43
|
1
|
|
|
1
|
1
|
5
|
sub can_be_quantified { return; } |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 capture_names |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
foreach my $name ( $re->capture_names() ) { |
48
|
|
|
|
|
|
|
print "Capture name '$name'\n"; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
This method returns the capture names found in the regular expression. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub capture_names { |
56
|
326
|
|
|
326
|
1
|
852
|
my ( $self ) = @_; |
57
|
326
|
|
|
|
|
586
|
my %name; |
58
|
326
|
100
|
|
|
|
1121
|
my $captures = $self->find( |
59
|
|
|
|
|
|
|
'PPIx::Regexp::Structure::NamedCapture') |
60
|
|
|
|
|
|
|
or return; |
61
|
21
|
|
|
|
|
62
|
foreach my $grab ( @{ $captures } ) { |
|
21
|
|
|
|
|
58
|
|
62
|
21
|
|
|
|
|
123
|
$name{$grab->name()}++; |
63
|
|
|
|
|
|
|
} |
64
|
21
|
|
|
|
|
142
|
return ( sort keys %name ); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub explain { |
68
|
1
|
|
|
1
|
1
|
5
|
return 'Regular expression'; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 max_capture_number |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
print "Highest used capture number ", |
74
|
|
|
|
|
|
|
$re->max_capture_number(), "\n"; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
This method returns the highest capture number used by the regular |
77
|
|
|
|
|
|
|
expression. If there are no captures, the return will be 0. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub max_capture_number { |
82
|
330
|
|
|
330
|
1
|
815
|
my ( $self ) = @_; |
83
|
330
|
|
|
|
|
915
|
return $self->{max_capture_number}; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# Called by the lexer once it has done its worst to all the tokens. |
87
|
|
|
|
|
|
|
# Called as a method with the lexer as argument. The return is the |
88
|
|
|
|
|
|
|
# number of parse failures discovered when finalizing. |
89
|
|
|
|
|
|
|
sub __PPIX_LEXER__finalize { |
90
|
324
|
|
|
324
|
|
976
|
my ( $self, $lexer ) = @_; |
91
|
324
|
|
|
|
|
580
|
my $rslt = 0; |
92
|
324
|
|
|
|
|
1196
|
foreach my $elem ( $self->elements() ) { |
93
|
1532
|
|
|
|
|
4493
|
$rslt += $elem->__PPIX_LEXER__finalize( $lexer ); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# Calculate the maximum capture group, and number all the other |
97
|
|
|
|
|
|
|
# capture groups along the way. |
98
|
|
|
|
|
|
|
$self->{max_capture_number} = |
99
|
324
|
|
|
|
|
1356
|
$self->__PPIX_LEXER__record_capture_number( 1 ) - 1; |
100
|
|
|
|
|
|
|
|
101
|
324
|
|
|
|
|
852
|
return $rslt; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
__END__ |