| 1 | =head1 NAME | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | PPIx::Regexp::Token - Base class for PPIx::Regexp tokens. | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | use PPIx::Regexp::Dumper; | ||||||||||||||||||||||||||||
| 8 | PPIx::Regexp::Dumper->new( 'qr{foo}' )->print(); | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | =head1 INHERITANCE | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | C<PPIx::Regexp::Token> is a | ||||||||||||||||||||||||||||
| 13 | L<PPIx::Regexp::Element|PPIx::Regexp::Element>. | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | C<PPIx::Regexp::Token> is the parent of | ||||||||||||||||||||||||||||
| 16 | L<PPIx::Regexp::Token::Assertion|PPIx::Regexp::Token::Assertion>, | ||||||||||||||||||||||||||||
| 17 | L<PPIx::Regexp::Token::Backtrack|PPIx::Regexp::Token::Backtrack>, | ||||||||||||||||||||||||||||
| 18 | L<PPIx::Regexp::Token::CharClass|PPIx::Regexp::Token::CharClass>, | ||||||||||||||||||||||||||||
| 19 | L<PPIx::Regexp::Token::Code|PPIx::Regexp::Token::Code>, | ||||||||||||||||||||||||||||
| 20 | L<PPIx::Regexp::Token::Comment|PPIx::Regexp::Token::Comment>, | ||||||||||||||||||||||||||||
| 21 | L<PPIx::Regexp::Token::Control|PPIx::Regexp::Token::Control>, | ||||||||||||||||||||||||||||
| 22 | L<PPIx::Regexp::Token::Greediness|PPIx::Regexp::Token::Greediness>, | ||||||||||||||||||||||||||||
| 23 | L<PPIx::Regexp::Token::GroupType|PPIx::Regexp::Token::GroupType>, | ||||||||||||||||||||||||||||
| 24 | L<PPIx::Regexp::Token::Literal|PPIx::Regexp::Token::Literal>, | ||||||||||||||||||||||||||||
| 25 | L<PPIx::Regexp::Token::Modifier|PPIx::Regexp::Token::Modifier>, | ||||||||||||||||||||||||||||
| 26 | L<PPIx::Regexp::Token::NoOp|PPIx::Regexp::Token::NoOp>, | ||||||||||||||||||||||||||||
| 27 | L<PPIx::Regexp::Token::Operator|PPIx::Regexp::Token::Operator>, | ||||||||||||||||||||||||||||
| 28 | L<PPIx::Regexp::Token::Quantifier|PPIx::Regexp::Token::Quantifier>, | ||||||||||||||||||||||||||||
| 29 | L<PPIx::Regexp::Token::Reference|PPIx::Regexp::Token::Reference>, | ||||||||||||||||||||||||||||
| 30 | L<PPIx::Regexp::Token::Structure|PPIx::Regexp::Token::Structure>, | ||||||||||||||||||||||||||||
| 31 | L<PPIx::Regexp::Token::Unknown|PPIx::Regexp::Token::Unknown> and | ||||||||||||||||||||||||||||
| 32 | L<PPIx::Regexp::Token::Unmatched|PPIx::Regexp::Token::Unmatched>. | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | This class represents the base of the class hierarchy for tokens in the | ||||||||||||||||||||||||||||
| 37 | L<PPIx::Regexp|PPIx::Regexp> package. | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | =head1 METHODS | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | This class provides no public methods beyond those provided by its | ||||||||||||||||||||||||||||
| 42 | superclass. | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =cut | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | package PPIx::Regexp::Token; | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 49 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 9 | ▶ | use base qw{PPIx::Regexp::Element}; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 9 | ▶ | use Carp qw{ confess }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 54 | 9 | ▶ | use PPIx::Regexp::Constant qw{ MINIMUM_PERL @CARP_NOT }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 9 | our $VERSION = '0.092'; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 9 | ▶ | use constant TOKENIZER_ARGUMENT_REQUIRED => 0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 5497 | ▶ | sub __new { | ||||||||||||||||||||||||||
|
Subroutine
__new: called CC=6 SCAR=18.7
| |||||||||||||||||||||||||||||
| 61 | 5497 | my ( $class, $content, %arg ) = @_; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | not $class->TOKENIZER_ARGUMENT_REQUIRED() | ||||||||||||||||||||||||||||
| 64 | or $arg{tokenizer} | ||||||||||||||||||||||||||||
| 65 | 5497 | ▶ | or confess 'Programming error - tokenizer not provided'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $class->TOKENIZER_ARGUMENT_REQUIRED or $arg{"tokenizer"}
MC/DC0%0/2
not $class->TOKENIZER_ARGUMENT_REQUIRED or $arg{"tokenizer"}
not $class->TOKENIZER_ARGUMENT_REQUIRED
$arg{"tokenizer"}
Truth table66%2/3
not(A) or B
A= not $class->TOKENIZER_ARGUMENT_REQUIREDB= $arg{"tokenizer"}
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 5497 | my $self = { | |||||||||||||||||||||||||||
| 68 | content => $content, | ||||||||||||||||||||||||||||
| 69 | }; | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 5497 | foreach my $key ( qw{ | |||||||||||||||||||||||||||
| 72 | explanation perl_version_introduced perl_version_removed | ||||||||||||||||||||||||||||
| 73 | } ) { | ||||||||||||||||||||||||||||
| 74 | defined $arg{$key} | ||||||||||||||||||||||||||||
| 75 | 16491 | ▶ | and $self->{$key} = $arg{$key}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 5497 | ▶ | bless $self, ref $class || $class; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||
| 79 | 5497 | return $self; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 10843 | ▶ | sub content { | ||||||||||||||||||||||||||
|
Subroutine
content: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 83 | 10843 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 84 | 10843 | return $self->{content}; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =head2 first_token | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | This method returns its invocant. | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =cut | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 13 | ▶ | sub first_token { | ||||||||||||||||||||||||||
|
Subroutine
first_token: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 94 | 13 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 95 | 13 | return $self; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =head2 last_token | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | This method returns its invocant. | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =cut | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 96 | ▶ | sub last_token { | ||||||||||||||||||||||||||
|
Subroutine
last_token: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 105 | 96 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 106 | 96 | return $self; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 91 | ▶ | sub perl_version_introduced { | ||||||||||||||||||||||||||
|
Subroutine
perl_version_introduced: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 110 | 91 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 111 | return defined $self->{perl_version_introduced} ? | ||||||||||||||||||||||||||||
| 112 | $self->{perl_version_introduced} : | ||||||||||||||||||||||||||||
| 113 | 91 | ▶ | MINIMUM_PERL; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 546 | ▶ | sub perl_version_removed { | ||||||||||||||||||||||||||
|
Subroutine
perl_version_removed: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 117 | 546 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 118 | 546 | return $self->{perl_version_removed}; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 126 | ▶ | sub unescaped_content { | ||||||||||||||||||||||||||
|
Subroutine
unescaped_content: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 122 | 126 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 123 | 126 | my $content = $self->content(); | |||||||||||||||||||||||||||
| 124 | 126 | $content =~ s/ \\ (?= . ) //smxg; | |||||||||||||||||||||||||||
| 125 | 126 | return $content; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 69 | ▶ | sub scontent { | ||||||||||||||||||||||||||
|
Subroutine
scontent: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 129 | 69 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 130 | $self->significant() | ||||||||||||||||||||||||||||
| 131 | 69 | ▶ | and return $self->{content}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | 20 | return; | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | # Called by the lexer once it has done its worst to all the tokens. | ||||||||||||||||||||||||||||
| 136 | # Called as a method with the lexer as argument. The return is the | ||||||||||||||||||||||||||||
| 137 | # number of parse failures discovered when finalizing. | ||||||||||||||||||||||||||||
| 138 | 1618 | ▶ | sub __PPIX_LEXER__finalize { | ||||||||||||||||||||||||||
|
Subroutine
__PPIX_LEXER__finalize: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 139 | 1618 | return 0; | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 9 | 1; | |||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | __END__ | ||||||||||||||||||||||||||||