| 1 | =head1 NAME | ||||||||||
| 2 | |||||||||||
| 3 | PPIx::Regexp::Token::Backtrack - Represent backtrack control. | ||||||||||
| 4 | |||||||||||
| 5 | =head1 SYNOPSIS | ||||||||||
| 6 | |||||||||||
| 7 | use PPIx::Regexp::Dumper; | ||||||||||
| 8 | PPIx::Regexp::Dumper->new( 'qr{(*ACCEPT)}smx' ) | ||||||||||
| 9 | ->print(); | ||||||||||
| 10 | |||||||||||
| 11 | =head1 INHERITANCE | ||||||||||
| 12 | |||||||||||
| 13 | C<PPIx::Regexp::Token::Backtrack> is a | ||||||||||
| 14 | L<PPIx::Regexp::Token|PPIx::Regexp::Token>. | ||||||||||
| 15 | |||||||||||
| 16 | C<PPIx::Regexp::Token::Backtrack> has no descendants. | ||||||||||
| 17 | |||||||||||
| 18 | =head1 DESCRIPTION | ||||||||||
| 19 | |||||||||||
| 20 | This class represents one of the backtrack controls. | ||||||||||
| 21 | |||||||||||
| 22 | =head1 METHODS | ||||||||||
| 23 | |||||||||||
| 24 | This class provides no public methods beyond those provided by its | ||||||||||
| 25 | superclass. | ||||||||||
| 26 | |||||||||||
| 27 | =cut | ||||||||||
| 28 | |||||||||||
| 29 | package PPIx::Regexp::Token::Backtrack; | ||||||||||
| 30 | |||||||||||
| 31 | 9 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 32 | 9 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 33 | |||||||||||
| 34 | 9 | ▶ | use base qw{ PPIx::Regexp::Token }; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 35 | |||||||||||
| 36 | 9 | ▶ | use PPIx::Regexp::Constant qw{ @CARP_NOT }; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 37 | |||||||||||
| 38 | 9 | our $VERSION = '0.092'; | |||||||||
| 39 | |||||||||||
| 40 | # Return true if the token can be quantified, and false otherwise | ||||||||||
| 41 | 8 | ▶ | sub can_be_quantified { return }; | ||||||||
|
Subroutine
can_be_quantified: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 42 | |||||||||||
| 43 | { | ||||||||||
| 44 | |||||||||||
| 45 | 9 | my %explanation = ( | |||||||||
| 46 | ACCEPT => 'Causes match to succeed at the point of the (*ACCEPT)', | ||||||||||
| 47 | COMMIT => 'Causes match failure when backtracked into on failure', | ||||||||||
| 48 | FAIL => 'Always fails, forcing backtrack', | ||||||||||
| 49 | MARK => 'Name branches of alternation, target for (*SKIP)', | ||||||||||
| 50 | PRUNE => 'Prevent backtracking past here on failure', | ||||||||||
| 51 | SKIP => 'Like (*PRUNE) but also discards match to this point', | ||||||||||
| 52 | THEN => 'Force next alternation on failure', | ||||||||||
| 53 | ); | ||||||||||
| 54 | |||||||||||
| 55 | 9 | ▶ | sub explain { | ||||||||
|
Subroutine
explain: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 56 | 9 | my ( $self ) = @_; | |||||||||
| 57 | 9 | my $verb = $self->verb(); | |||||||||
| 58 | 9 | ▶ | defined( my $expl = $explanation{$verb} ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | or return $self->__no_explanation(); | ||||||||||
| 60 | 9 | return $expl; | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | 9 | my %synonym = ( | |||||||||
| 64 | '' => 'MARK', | ||||||||||
| 65 | F => 'FAIL', | ||||||||||
| 66 | ); | ||||||||||
| 67 | |||||||||||
| 68 | =head2 arg | ||||||||||
| 69 | |||||||||||
| 70 | This method returns the backtrack control argument specified by the | ||||||||||
| 71 | element. This is the text after the first colon (C<':'>), or the empty | ||||||||||
| 72 | string (C<''>) if none was specified. | ||||||||||
| 73 | |||||||||||
| 74 | =cut | ||||||||||
| 75 | |||||||||||
| 76 | 0 | ▶ | sub arg { | ||||||||
|
Subroutine
arg: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 77 | 0 | my ( $self ) = @_; | |||||||||
| 78 | 0 | my $content = $self->content(); | |||||||||
| 79 | 0 | $content =~ s/ [^:]* //smx; # ( | |||||||||
| 80 | 0 | $content =~ s/ \) //smx; | |||||||||
| 81 | 0 | return $content; | |||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | =head2 verb | ||||||||||
| 85 | |||||||||||
| 86 | This method returns the backtrack control verb represented by the | ||||||||||
| 87 | element. This is the text up to but not including the first colon | ||||||||||
| 88 | (C<':'>) if any. If the element specifies C<''> or C<'F">, this method | ||||||||||
| 89 | will return C<'MARK'> or C<'FAIL'>, respectively. | ||||||||||
| 90 | |||||||||||
| 91 | =cut | ||||||||||
| 92 | |||||||||||
| 93 | 9 | ▶ | sub verb { | ||||||||
|
Subroutine
verb: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 94 | 9 | my ( $self ) = @_; | |||||||||
| 95 | 9 | my $content = $self->content(); | |||||||||
| 96 | 9 | $content =~ s/ \( \* //smx; | |||||||||
| 97 | 9 | $content =~ s/ [:)] .* //smx; | |||||||||
| 98 | 9 | ▶ | defined( my $syn = $synonym{$content} ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 99 | or return $content; | ||||||||||
| 100 | 2 | return $syn; | |||||||||
| 101 | } | ||||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | 9 | ▶ | sub perl_version_introduced { | ||||||||
|
Subroutine
perl_version_introduced: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 105 | 9 | return '5.009005'; | |||||||||
| 106 | } | ||||||||||
| 107 | |||||||||||
| 108 | # This must be implemented by tokens which do not recognize themselves. | ||||||||||
| 109 | # The return is a list of list references. Each list reference must | ||||||||||
| 110 | # contain a regular expression that recognizes the token, and optionally | ||||||||||
| 111 | # a reference to a hash to pass to make_token as the class-specific | ||||||||||
| 112 | # arguments. The regular expression MUST be anchored to the beginning of | ||||||||||
| 113 | # the string. | ||||||||||
| 114 | # Note that we have to require a non-lowercase letter after the asterisk | ||||||||||
| 115 | # to avoid grabbing the so-caled alpha_assertions introduced with | ||||||||||
| 116 | # 5.27.9. | ||||||||||
| 117 | # Optimized code ( (*{...}) and (**{...}) ), introduced in 5.37.8, broke | ||||||||||
| 118 | # the non-lowercase requirement. I replaced that with requiring an | ||||||||||
| 119 | # uppercase or a colon (the latter because in (*MARK:foo) you can omit | ||||||||||
| 120 | # the 'MARK'). | ||||||||||
| 121 | 9 | ▶ | sub __PPIX_TOKEN__recognize { | ||||||||
|
Subroutine
__PPIX_TOKEN__recognize: called CC=1 SCAR=0.0
| |||||||||||
| 122 | 9 | return ( [ qr{ \A \( \* [[:upper:]:] [^\)]* \) }smx ] ); | |||||||||
| 123 | } | ||||||||||
| 124 | |||||||||||
| 125 | # This class gets recognized by PPIx::Regexp::Token::Structure as part | ||||||||||
| 126 | # of its left parenthesis processing. | ||||||||||
| 127 | |||||||||||
| 128 | =begin comment | ||||||||||
| 129 | |||||||||||
| 130 | sub __PPIX_TOKENIZER__regexp { | ||||||||||
| 131 | my ( $class, $tokenizer, $character ) = @_; | ||||||||||
| 132 | |||||||||||
| 133 | return $character eq 'x' ? 1 : 0; | ||||||||||
| 134 | } | ||||||||||
| 135 | |||||||||||
| 136 | =end comment | ||||||||||
| 137 | |||||||||||
| 138 | =cut | ||||||||||
| 139 | |||||||||||
| 140 | 9 | 1; | |||||||||
| 141 | |||||||||||
| 142 | __END__ | ||||||||||