| 1 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||
| 3 | PPIx::Regexp::Token::GroupType::Assertion - Represent a look ahead or look behind assertion | ||||||||||||||||||||||||||||||||||||||
| 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::GroupType::Assertion> is a | ||||||||||||||||||||||||||||||||||||||
| 14 | L<PPIx::Regexp::Token::GroupType|PPIx::Regexp::Token::GroupType>. | ||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||
| 16 | C<PPIx::Regexp::Token::GroupType::Assertion> has no descendants. | ||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||
| 18 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||
| 20 | This class represents the parenthesized look ahead and look behind | ||||||||||||||||||||||||||||||||||||||
| 21 | assertions. | ||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||
| 23 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||
| 25 | This class provides the following public methods beyond those provided | ||||||||||||||||||||||||||||||||||||||
| 26 | by its superclass. | ||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||
| 28 | =cut | ||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||
| 30 | package PPIx::Regexp::Token::GroupType::Assertion; | ||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||
| 32 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 33 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||
| 35 | 9 | ▶ | use base qw{ PPIx::Regexp::Token::GroupType }; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||
| 37 | 9 | ▶ | use PPIx::Regexp::Constant qw{ | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 38 | COOKIE_LOOKAROUND_ASSERTION | ||||||||||||||||||||||||||||||||||||||
| 39 | @CARP_NOT | ||||||||||||||||||||||||||||||||||||||
| 40 | 9 | }; | |||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||
| 42 | 9 | our $VERSION = '0.092'; | |||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||
| 44 | 9 | ▶ | use constant EXPL_NLA => 'Negative look-ahead assertion'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 45 | 9 | ▶ | use constant EXPL_NLB => 'Negative look-behind assertion'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 46 | 9 | ▶ | use constant EXPL_PLA => 'Positive look-ahead assertion'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 47 | 9 | ▶ | use constant EXPL_PLB => 'Positive look-behind assertion'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||
| 49 | 9 | ▶ | use constant DEF => { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||
| 51 | '?!' => { | ||||||||||||||||||||||||||||||||||||||
| 52 | expl => EXPL_NLA, | ||||||||||||||||||||||||||||||||||||||
| 53 | look_ahead => 1, | ||||||||||||||||||||||||||||||||||||||
| 54 | }, | ||||||||||||||||||||||||||||||||||||||
| 55 | '*nla:' => { | ||||||||||||||||||||||||||||||||||||||
| 56 | expl => EXPL_NLA, | ||||||||||||||||||||||||||||||||||||||
| 57 | intro => '5.027009', | ||||||||||||||||||||||||||||||||||||||
| 58 | look_ahead => 1, | ||||||||||||||||||||||||||||||||||||||
| 59 | }, | ||||||||||||||||||||||||||||||||||||||
| 60 | '*negative_lookahead:' => { | ||||||||||||||||||||||||||||||||||||||
| 61 | expl => EXPL_NLA, | ||||||||||||||||||||||||||||||||||||||
| 62 | intro => '5.027009', | ||||||||||||||||||||||||||||||||||||||
| 63 | look_ahead => 1, | ||||||||||||||||||||||||||||||||||||||
| 64 | }, | ||||||||||||||||||||||||||||||||||||||
| 65 | '?<!' => { | ||||||||||||||||||||||||||||||||||||||
| 66 | expl => EXPL_NLB, | ||||||||||||||||||||||||||||||||||||||
| 67 | intro => '5.005', | ||||||||||||||||||||||||||||||||||||||
| 68 | }, | ||||||||||||||||||||||||||||||||||||||
| 69 | '*nlb:' => { | ||||||||||||||||||||||||||||||||||||||
| 70 | expl => EXPL_NLB, | ||||||||||||||||||||||||||||||||||||||
| 71 | intro => '5.027009', | ||||||||||||||||||||||||||||||||||||||
| 72 | }, | ||||||||||||||||||||||||||||||||||||||
| 73 | '*negative_lookbehind:' => { | ||||||||||||||||||||||||||||||||||||||
| 74 | expl => EXPL_NLB, | ||||||||||||||||||||||||||||||||||||||
| 75 | intro => '5.027009', | ||||||||||||||||||||||||||||||||||||||
| 76 | }, | ||||||||||||||||||||||||||||||||||||||
| 77 | '?=' => { | ||||||||||||||||||||||||||||||||||||||
| 78 | expl => EXPL_PLA, | ||||||||||||||||||||||||||||||||||||||
| 79 | look_ahead => 1, | ||||||||||||||||||||||||||||||||||||||
| 80 | positive => 1, | ||||||||||||||||||||||||||||||||||||||
| 81 | }, | ||||||||||||||||||||||||||||||||||||||
| 82 | '*pla:' => { | ||||||||||||||||||||||||||||||||||||||
| 83 | expl => EXPL_PLA, | ||||||||||||||||||||||||||||||||||||||
| 84 | intro => '5.027009', | ||||||||||||||||||||||||||||||||||||||
| 85 | look_ahead => 1, | ||||||||||||||||||||||||||||||||||||||
| 86 | positive => 1, | ||||||||||||||||||||||||||||||||||||||
| 87 | }, | ||||||||||||||||||||||||||||||||||||||
| 88 | '*positive_lookahead:' => { | ||||||||||||||||||||||||||||||||||||||
| 89 | expl => EXPL_PLA, | ||||||||||||||||||||||||||||||||||||||
| 90 | intro => '5.027009', | ||||||||||||||||||||||||||||||||||||||
| 91 | look_ahead => 1, | ||||||||||||||||||||||||||||||||||||||
| 92 | positive => 1, | ||||||||||||||||||||||||||||||||||||||
| 93 | }, | ||||||||||||||||||||||||||||||||||||||
| 94 | '?<=' => { | ||||||||||||||||||||||||||||||||||||||
| 95 | expl => EXPL_PLB, | ||||||||||||||||||||||||||||||||||||||
| 96 | intro => '5.005', | ||||||||||||||||||||||||||||||||||||||
| 97 | positive => 1, | ||||||||||||||||||||||||||||||||||||||
| 98 | }, | ||||||||||||||||||||||||||||||||||||||
| 99 | '*plb:' => { | ||||||||||||||||||||||||||||||||||||||
| 100 | expl => EXPL_PLB, | ||||||||||||||||||||||||||||||||||||||
| 101 | intro => '5.027009', | ||||||||||||||||||||||||||||||||||||||
| 102 | positive => 1, | ||||||||||||||||||||||||||||||||||||||
| 103 | }, | ||||||||||||||||||||||||||||||||||||||
| 104 | '*positive_lookbehind:' => { | ||||||||||||||||||||||||||||||||||||||
| 105 | expl => EXPL_PLB, | ||||||||||||||||||||||||||||||||||||||
| 106 | intro => '5.027009', | ||||||||||||||||||||||||||||||||||||||
| 107 | positive => 1, | ||||||||||||||||||||||||||||||||||||||
| 108 | }, | ||||||||||||||||||||||||||||||||||||||
| 109 | 9 | }; | |||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||
| 111 | 9 | __PACKAGE__->__setup_class(); | |||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||
| 113 | 48 | ▶ | sub __match_setup { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__match_setup: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 114 | 48 | my ( undef, $tokenizer ) = @_; # $class not used | |||||||||||||||||||||||||||||||||||||
| 115 | 48 | ▶ | $tokenizer->__cookie_exists( COOKIE_LOOKAROUND_ASSERTION ) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 116 | and return; | ||||||||||||||||||||||||||||||||||||||
| 117 | 45 | my $nest_depth = 1; | |||||||||||||||||||||||||||||||||||||
| 118 | 233 | ▶ | $tokenizer->cookie( COOKIE_LOOKAROUND_ASSERTION, sub { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||
| 119 | 233 | my ( undef, $token ) = @_; # $tokenizer not used | |||||||||||||||||||||||||||||||||||||
| 120 | $token | ||||||||||||||||||||||||||||||||||||||
| 121 | and $token->isa( 'PPIx::Regexp::Token::Structure' ) | ||||||||||||||||||||||||||||||||||||||
| 122 | and $nest_depth += ( { | ||||||||||||||||||||||||||||||||||||||
| 123 | '(' => 1, | ||||||||||||||||||||||||||||||||||||||
| 124 | ')' => -1, | ||||||||||||||||||||||||||||||||||||||
| 125 | 233 | ▶ | }->{ $token->content() } || 0 ); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
$token and $token->isa("PPIx::Regexp::Token::Structure")
{'(', 1, ')', -1}->{$token->content} || 0
MC/DC50%1/2
$token and $token->isa("PPIx::Regexp::Token::Structure")
$token
$token->isa("PPIx::Regexp::Token::Structure")
MC/DC100%1/1
{'(', 1, ')', -1}->{$token->content} || 0
{'(', 1, ')', -1}->{$token->content}
Truth table66%2/3
A and B
A= $tokenB= $token->isa("PPIx::Regexp::Token::Structure")
Truth table100%2/2
A
A= {'(', 1, ')', -1}->{$token->content}
| |||||||||||||||||||||||||||||||||||||||
| 126 | 233 | return $nest_depth; | |||||||||||||||||||||||||||||||||||||
| 127 | }, | ||||||||||||||||||||||||||||||||||||||
| 128 | 45 | ); | |||||||||||||||||||||||||||||||||||||
| 129 | 45 | return; | |||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||
| 132 | =head2 is_look_ahead | ||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||
| 134 | This method returns a true value if the assertion is a look-ahead | ||||||||||||||||||||||||||||||||||||||
| 135 | assertion, or a false value if it is a look-behind assertion. | ||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||
| 137 | =cut | ||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||
| 139 | 17 | ▶ | sub is_look_ahead { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
is_look_ahead: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 140 | 17 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||
| 141 | 17 | return $self->DEF->{ $self->unescaped_content() }->{look_ahead}; | |||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||
| 144 | =head2 is_positive | ||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||
| 146 | This method returns a true value if the assertion is a positive | ||||||||||||||||||||||||||||||||||||||
| 147 | assertion, or a false value if it is a negative assertion. | ||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||
| 149 | =cut | ||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | sub is_positive { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
is_positive: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 152 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||
| 153 | 0 | return $self->DEF->{ $self->unescaped_content() }->{positive}; | |||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||
| 156 | 9 | 1; | |||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||
| 158 | __END__ | ||||||||||||||||||||||||||||||||||||||