Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPIx/Regexp/Token/Operator.pm |
Statements | Executed 13 statements in 275µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 14µs | 28µs | BEGIN@33 | PPIx::Regexp::Token::Operator::
1 | 1 | 1 | 8µs | 14µs | BEGIN@34 | PPIx::Regexp::Token::Operator::
1 | 1 | 1 | 8µs | 31µs | BEGIN@38 | PPIx::Regexp::Token::Operator::
1 | 1 | 1 | 8µs | 30µs | BEGIN@39 | PPIx::Regexp::Token::Operator::
1 | 1 | 1 | 8µs | 74µs | BEGIN@36 | PPIx::Regexp::Token::Operator::
0 | 0 | 0 | 0s | 0s | __PPIX_TOKENIZER__regexp | PPIx::Regexp::Token::Operator::
0 | 0 | 0 | 0s | 0s | _treat_as_literal | PPIx::Regexp::Token::Operator::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | =head1 NAME | ||||
2 | |||||
3 | PPIx::Regexp::Token::Operator - Represent an operator. | ||||
4 | |||||
5 | =head1 SYNOPSIS | ||||
6 | |||||
7 | use PPIx::Regexp::Dumper; | ||||
8 | PPIx::Regexp::Dumper->new( 'qr{foo|bar}smx' ) | ||||
9 | ->print(); | ||||
10 | |||||
11 | =head1 INHERITANCE | ||||
12 | |||||
13 | C<PPIx::Regexp::Token::Operator> is a | ||||
14 | L<PPIx::Regexp::Token|PPIx::Regexp::Token>. | ||||
15 | |||||
16 | C<PPIx::Regexp::Token::Operator> has no descendants. | ||||
17 | |||||
18 | =head1 DESCRIPTION | ||||
19 | |||||
20 | This class represents an operator. In a character class, it represents | ||||
21 | the negation (C<^>) and range (C<->) operators. Outside a character | ||||
22 | class, it represents the alternation (C<|>) operator. | ||||
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::Operator; | ||||
32 | |||||
33 | 2 | 23µs | 2 | 42µs | # spent 28µs (14+14) within PPIx::Regexp::Token::Operator::BEGIN@33 which was called:
# once (14µs+14µs) by PPIx::Regexp::Tokenizer::BEGIN@36 at line 33 # spent 28µs making 1 call to PPIx::Regexp::Token::Operator::BEGIN@33
# spent 14µs making 1 call to strict::import |
34 | 2 | 25µs | 2 | 19µs | # spent 14µs (8+5) within PPIx::Regexp::Token::Operator::BEGIN@34 which was called:
# once (8µs+5µs) by PPIx::Regexp::Tokenizer::BEGIN@36 at line 34 # spent 14µs making 1 call to PPIx::Regexp::Token::Operator::BEGIN@34
# spent 5µs making 1 call to warnings::import |
35 | |||||
36 | 2 | 26µs | 2 | 139µs | # spent 74µs (8+66) within PPIx::Regexp::Token::Operator::BEGIN@36 which was called:
# once (8µs+66µs) by PPIx::Regexp::Tokenizer::BEGIN@36 at line 36 # spent 74µs making 1 call to PPIx::Regexp::Token::Operator::BEGIN@36
# spent 66µs making 1 call to base::import |
37 | |||||
38 | 2 | 25µs | 2 | 54µs | # spent 31µs (8+23) within PPIx::Regexp::Token::Operator::BEGIN@38 which was called:
# once (8µs+23µs) by PPIx::Regexp::Tokenizer::BEGIN@36 at line 38 # spent 31µs making 1 call to PPIx::Regexp::Token::Operator::BEGIN@38
# spent 23µs making 1 call to Exporter::import |
39 | 2 | 168µs | 2 | 53µs | # spent 30µs (8+22) within PPIx::Regexp::Token::Operator::BEGIN@39 which was called:
# once (8µs+22µs) by PPIx::Regexp::Tokenizer::BEGIN@36 at line 39 # spent 30µs making 1 call to PPIx::Regexp::Token::Operator::BEGIN@39
# spent 22µs making 1 call to Exporter::import |
40 | |||||
41 | 1 | 600ns | our $VERSION = '0.036'; | ||
42 | |||||
43 | # Return true if the token can be quantified, and false otherwise | ||||
44 | # sub can_be_quantified { return }; | ||||
45 | |||||
46 | # These will be intercepted by PPIx::Regexp::Token::Literal if they are | ||||
47 | # really literals, so here we may process them unconditionally. | ||||
48 | |||||
49 | # Note that if we receive a '-' we unconditionally make it an operator, | ||||
50 | # relying on the lexer to turn it back into a literal if necessary. | ||||
51 | |||||
52 | 1 | 3µs | my %operator = map { $_ => 1 } qw{ | - }; | ||
53 | |||||
54 | sub _treat_as_literal { | ||||
55 | my ( $token ) = @_; | ||||
56 | return __instance( $token, 'PPIx::Regexp::Token::Literal' ) || | ||||
57 | __instance( $token, 'PPIx::Regexp::Token::Interpolation' ); | ||||
58 | } | ||||
59 | |||||
60 | sub __PPIX_TOKENIZER__regexp { | ||||
61 | my ( $class, $tokenizer, $character ) = @_; | ||||
62 | |||||
63 | # We only receive the '-' if we are inside a character class. But it | ||||
64 | # is only an operator if it is preceded and followed by literals. We | ||||
65 | # can use prior() because there are no insignificant tokens inside a | ||||
66 | # character class. | ||||
67 | if ( $character eq '-' ) { | ||||
68 | |||||
69 | _treat_as_literal( $tokenizer->prior() ) | ||||
70 | or return $tokenizer->make_token( 1, TOKEN_LITERAL ); | ||||
71 | |||||
72 | my @tokens = ( $tokenizer->make_token( 1 ) ); | ||||
73 | push @tokens, $tokenizer->get_token(); | ||||
74 | |||||
75 | _treat_as_literal( $tokens[1] ) | ||||
76 | or bless $tokens[0], TOKEN_LITERAL; | ||||
77 | |||||
78 | return ( @tokens ); | ||||
79 | } | ||||
80 | |||||
81 | return $operator{$character}; | ||||
82 | } | ||||
83 | |||||
84 | 1 | 4µs | 1; | ||
85 | |||||
86 | __END__ |