Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPIx/Regexp/Token/GroupType.pm |
Statements | Executed 9 statements in 500µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 16µs | 31µs | BEGIN@41 | PPIx::Regexp::Token::GroupType::
1 | 1 | 1 | 10µs | 77µs | BEGIN@44 | PPIx::Regexp::Token::GroupType::
1 | 1 | 1 | 9µs | 15µs | BEGIN@42 | PPIx::Regexp::Token::GroupType::
0 | 0 | 0 | 0s | 0s | __PPIX_TOKENIZER__regexp | PPIx::Regexp::Token::GroupType::
0 | 0 | 0 | 0s | 0s | __defining_string | PPIx::Regexp::Token::GroupType::
0 | 0 | 0 | 0s | 0s | __make_group_type_matcher | PPIx::Regexp::Token::GroupType::
0 | 0 | 0 | 0s | 0s | __match_setup | PPIx::Regexp::Token::GroupType::
0 | 0 | 0 | 0s | 0s | can_be_quantified | PPIx::Regexp::Token::GroupType::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | =head1 NAME | ||||
2 | |||||
3 | PPIx::Regexp::Token::GroupType - Represent a grouping parenthesis type. | ||||
4 | |||||
5 | =head1 SYNOPSIS | ||||
6 | |||||
7 | use PPIx::Regexp::Dumper; | ||||
8 | PPIx::Regexp::Dumper->new( 'qr{(?i:foo)}smx' ) | ||||
9 | ->print(); | ||||
10 | |||||
11 | =head1 INHERITANCE | ||||
12 | |||||
13 | C<PPIx::Regexp::Token::GroupType> is a | ||||
14 | L<PPIx::Regexp::Token|PPIx::Regexp::Token>. | ||||
15 | |||||
16 | C<PPIx::Regexp::Token::GroupType> is the parent of | ||||
17 | L<PPIx::Regexp::Token::GroupType::Assertion|PPIx::Regexp::Token::GroupType::Assertion>, | ||||
18 | L<PPIx::Regexp::Token::GroupType::BranchReset|PPIx::Regexp::Token::GroupType::BranchReset>, | ||||
19 | L<PPIx::Regexp::Token::GroupType::Code|PPIx::Regexp::Token::GroupType::Code>, | ||||
20 | L<PPIx::Regexp::Token::GroupType::Modifier|PPIx::Regexp::Token::GroupType::Modifier>, | ||||
21 | L<PPIx::Regexp::Token::GroupType::NamedCapture|PPIx::Regexp::Token::GroupType::NamedCapture>, | ||||
22 | L<PPIx::Regexp::Token::GroupType::Subexpression|PPIx::Regexp::Token::GroupType::Subexpression> | ||||
23 | and | ||||
24 | L<PPIx::Regexp::Token::GroupType::Switch|PPIx::Regexp::Token::GroupType::Switch>. | ||||
25 | |||||
26 | =head1 DESCRIPTION | ||||
27 | |||||
28 | This class represents any of the magic sequences of characters that can | ||||
29 | follow an open parenthesis. This particular class is intended to be | ||||
30 | abstract. | ||||
31 | |||||
32 | =head1 METHODS | ||||
33 | |||||
34 | This class provides no public methods beyond those provided by its | ||||
35 | superclass. | ||||
36 | |||||
37 | =cut | ||||
38 | |||||
39 | package PPIx::Regexp::Token::GroupType; | ||||
40 | |||||
41 | 2 | 27µs | 2 | 47µs | # spent 31µs (16+16) within PPIx::Regexp::Token::GroupType::BEGIN@41 which was called:
# once (16µs+16µs) by base::import at line 41 # spent 31µs making 1 call to PPIx::Regexp::Token::GroupType::BEGIN@41
# spent 16µs making 1 call to strict::import |
42 | 2 | 33µs | 2 | 21µs | # spent 15µs (9+6) within PPIx::Regexp::Token::GroupType::BEGIN@42 which was called:
# once (9µs+6µs) by base::import at line 42 # spent 15µs making 1 call to PPIx::Regexp::Token::GroupType::BEGIN@42
# spent 6µs making 1 call to warnings::import |
43 | |||||
44 | 2 | 436µs | 2 | 77µs | # spent 77µs (10+67) within PPIx::Regexp::Token::GroupType::BEGIN@44 which was called:
# once (10µs+67µs) by base::import at line 44 # spent 77µs making 1 call to PPIx::Regexp::Token::GroupType::BEGIN@44
# spent 67µs making 1 call to base::import, recursion: max depth 1, sum of overlapping time 67µs |
45 | |||||
46 | 1 | 800ns | our $VERSION = '0.036'; | ||
47 | |||||
48 | # Return true if the token can be quantified, and false otherwise | ||||
49 | sub can_be_quantified { return }; | ||||
50 | |||||
51 | =head2 __defining_string | ||||
52 | |||||
53 | my $string = $class->__defining_string(); | ||||
54 | |||||
55 | This method is private to the C<PPIx-Regexp> package, and is documented | ||||
56 | for the author's benefit only. It may be changed or revoked without | ||||
57 | notice. | ||||
58 | |||||
59 | This method returns an array of strings that define the specific group | ||||
60 | type. These strings will normally start with C<'?'>. | ||||
61 | |||||
62 | Optionally, the first returned item may be a hash reference. The only | ||||
63 | supported key is C<{suffix}>, which is a string to be suffixed to each | ||||
64 | of the regular expressions made by C<__make_group_type_matcher()> out of | ||||
65 | the defining strings, inside a C<(?= ... )>, so that it is not included | ||||
66 | in the match. | ||||
67 | |||||
68 | This method B<must> be overridden, unless C<__make_group_type_matcher()> | ||||
69 | is. | ||||
70 | |||||
71 | =cut | ||||
72 | |||||
73 | sub __defining_string { | ||||
74 | require Carp; | ||||
75 | Carp::confess( | ||||
76 | 'Programming error - __defining_string() must be overridden' ); | ||||
77 | } | ||||
78 | |||||
79 | =head2 __make_group_type_matcher | ||||
80 | |||||
81 | my $hash_ref = $class->__make_group_type_matcher(); | ||||
82 | |||||
83 | This method is private to the C<PPIx-Regexp> package, and is documented | ||||
84 | for the author's benefit only. It may be changed or revoked without | ||||
85 | notice. | ||||
86 | |||||
87 | This method returns a reference to a hash. The keys are regexp delimiter | ||||
88 | characters which appear in the defining strings for the group type. For | ||||
89 | each key, the value is a reference to an array of C<Regexp> objects, | ||||
90 | properly escaped for the key character. Key C<''> provides the regular | ||||
91 | expressions to be used if the regexp delimiter does not appear in any of | ||||
92 | the defining strings. | ||||
93 | |||||
94 | If this method is overridden by the subclass, method | ||||
95 | C<__defining_string()> need not be, unless the overridden | ||||
96 | C<__make_group_type_matcher()> calls C<__defining_string()>. | ||||
97 | |||||
98 | =cut | ||||
99 | |||||
100 | sub __make_group_type_matcher { | ||||
101 | my ( $class ) = @_; | ||||
102 | |||||
103 | my @defs = $class->__defining_string(); | ||||
104 | |||||
105 | my $opt = ref $defs[0] ? shift @defs : {}; | ||||
106 | |||||
107 | my $suffix = defined $opt->{suffix} ? | ||||
108 | qr/ (?= \Q$opt->{suffix}\E ) /smx : | ||||
109 | ''; | ||||
110 | |||||
111 | my %rslt; | ||||
112 | foreach my $str ( $class->__defining_string() ) { | ||||
113 | my %seen; | ||||
114 | my @chars = grep { ! $seen{$_}++ } split qr{}smx, $str; | ||||
115 | push @{ $rslt{''} ||= [] }, qr{ \A \Q$str\E $suffix }smx; | ||||
116 | foreach my $chr ( @chars ) { | ||||
117 | ( my $expr = $str ) =~ s/ (?= \Q$chr\E ) /\\/smxg; | ||||
118 | push @{ $rslt{$chr} ||= [] }, qr{ \A \Q$expr\E $suffix }smx; | ||||
119 | } | ||||
120 | } | ||||
121 | return \%rslt; | ||||
122 | } | ||||
123 | |||||
124 | |||||
125 | =head2 __match_setup | ||||
126 | |||||
127 | $class->__match_setup( $tokenizer ); | ||||
128 | |||||
129 | This method is private to the C<PPIx-Regexp> package, and is documented | ||||
130 | for the author's benefit only. It may be changed or revoked without | ||||
131 | notice. | ||||
132 | |||||
133 | This method performs whatever setup is needed once it is determined that | ||||
134 | the given group type has been detected. This method is called only if | ||||
135 | the class matched at the current position in the string being parsed. It | ||||
136 | must perform whatever extra setup is needed for the match. It returns | ||||
137 | nothing. | ||||
138 | |||||
139 | This method need not be overridden. The default does nothing. | ||||
140 | |||||
141 | =cut | ||||
142 | |||||
143 | sub __match_setup { | ||||
144 | return; | ||||
145 | } | ||||
146 | |||||
147 | 1 | 200ns | my %matcher; | ||
148 | |||||
149 | sub __PPIX_TOKENIZER__regexp { | ||||
150 | my ( $class, $tokenizer, $character ) = @_; | ||||
151 | |||||
152 | my $mtch = $matcher{$class} ||= $class->__make_group_type_matcher(); | ||||
153 | |||||
154 | my $re_list = $mtch->{ $tokenizer->get_start_delimiter() } || | ||||
155 | $mtch->{''}; | ||||
156 | |||||
157 | foreach my $re ( @{ $re_list } ) { | ||||
158 | my $accept = $tokenizer->find_regexp( $re ) | ||||
159 | or next; | ||||
160 | $class->__match_setup( $tokenizer ); | ||||
161 | return $accept; | ||||
162 | } | ||||
163 | |||||
164 | return; | ||||
165 | } | ||||
166 | |||||
167 | 1 | 4µs | 1; | ||
168 | |||||
169 | __END__ |