/usr/share/perl5/PPIx/Regexp/StringTokenizer.pm is in libppix-regexp-perl 0.055-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | package PPIx::Regexp::StringTokenizer;
use 5.006;
use strict;
use warnings;
use base qw{ PPIx::Regexp::Tokenizer };
use Carp;
use PPIx::Regexp::Constant qw{
TOKEN_UNKNOWN
};
our $VERSION = '0.055';
{
# Names of classes containing tokenization machinery. There are few
# known ordering requirements, since each class recognizes its own,
# and I have tried to prevent overlap. Absent such constraints, the
# order is in perceived frequency of acceptance, to keep the search
# as short as possible. If I were conscientious I would gather
# statistics on this.
my @classes = ( # TODO make readonly when acceptable way appears
'PPIx::Regexp::Token::Literal',
'PPIx::Regexp::Token::Interpolation',
'PPIx::Regexp::Token::Control', # Note 1
# 'PPIx::Regexp::Token::CharClass::Simple', # Note 2
# 'PPIx::Regexp::Token::Quantifier',
# 'PPIx::Regexp::Token::Greediness',
# 'PPIx::Regexp::Token::CharClass::POSIX', # Note 3
# 'PPIx::Regexp::Token::Structure',
# 'PPIx::Regexp::Token::Assertion',
# 'PPIx::Regexp::Token::Backreference',
# 'PPIx::Regexp::Token::Operator', # Note 4
);
# Note 1: If we are in quote mode ( \Q ... \E ), Control makes a
# literal out of anything it sees other than \E. So it
# needs to come before almost all other tokenizers. Not
# Literal, which already makes literals, and not
# Interpolation, which is legal in quote mode, but
# everything else.
# Note 2: CharClass::Simple must come after Literal, because it
# relies on Literal to recognize a Unicode named character
# ( \N{something} ), so any \N that comes through to it
# must be the \N simple character class (which represents
# anything but a newline, and was introduced in Perl
# 5.11.0.
# Note 3: CharClass::POSIX has to come before Structure, since both
# look for square brackets, and CharClass::POSIX is the
# more particular.
# Note 4: Operator relies on Literal making the characters literal
# if they appear in a context where they can not be
# operators, and Control making them literals if quoting,
# so it must come after both.
# Return the declared tokenizer classes.
sub __tokenizer_classes {
return @classes;
}
}
my %bare_delim = map { $_ => 1 } qw{ ' " ` };
sub __PPIX_TOKENIZER__init {
my ( $self ) = @_;
my @tokens;
if ( $self->find_regexp( qr{ \A \s* << }smx ) ) {
my ( $leading_white, $next_white, $delim );
if ( $self->find_regexp( qr{ \A ( \s* ) << ( \w+ \n ) }smx ) ) {
( $leading_white, $delim ) = $self->capture();
$next_white = '';
} elsif ( $self->find_regexp(
qr{ \A ( \s* ) << ( \s+ ) ( ( ["'] ) .*? \4 \n ) }smx )
) {
( $leading_white, $next_white, $delim ) = $self->capture();
} else {
return $self->__init_error();
}
$self->{type} = '<<';
$self->{delimiter_start} = $delim;
if ( $delim =~ s/ \A ( ["'] ) ( .* ) \1 \n \z /$2\n/smx ) {
my $quote = $1;
$delim =~ s/ \\ (?= \Q$quote\E ) //smxg;
}
'' ne $leading_white
and push @tokens, $self->make_token( length $leading_white,
'PPIx::Regexp::Token::Whitespace' );
push @tokens, $self->make_token( length $self->{type},
'PPIx::Regexp::Token::Structure' );
'' ne $next_white
and push @tokens, $self->make_token( length $next_white,
'PPIx::Regexp::Token::Whitespace' );
push @tokens, $self->make_token( length $self->{delimiter_start},
'PPIx::Regexp::Token::Delimiter' );
my ( $offset ) = $self->find_regexp( qr{ \Q$delim\E }smx )
or return $self->__init_error();
my $cursor_limit = $self->{cursor_curr} + $offset;
$self->{trace}
and warn "Tokenizer found here doc end delimiter at $cursor_limit\n";
$self->{cursor_limit} = $cursor_limit;
$self->{cursor_modifiers} = $cursor_limit + length $delim;
$self->{delimiter_finish} = $delim;
} elsif ( $self->find_regexp(
qr{ \A ( \s* ) ( qq | q | qx )? ( \s* ) ( [^\w\s] ) }smx ) )
{
my ( $leading_white, $type, $next_white, $delim ) = $self->capture();
unless ( defined $type ) {
$bare_delim{$delim}
or return $self->__init_error();
$type = '';
}
$self->{type} = $type;
'' ne $leading_white
and push @tokens, $self->make_token( length $leading_white,
'PPIx::Regexp::Token::Whitespace' );
push @tokens, $self->make_token( length $type,
'PPIx::Regexp::Token::Structure' );
'' ne $next_white
and push @tokens, $self->make_token( length $next_white,
'PPIx::Regexp::Token::Whitespace' );
$self->{delimiter_start} = substr
$self->{content},
$self->{cursor_curr},
1;
$self->{trace}
and warn "Tokenizer found string start delimiter '$self->{delimiter_start}' at $self->{cursor_curr}\n";
my $offset = $self->find_matching_delimiter()
or return $self->__init_error(
'Tokenizer found mismatched string delimiters' );
my $cursor_limit = $self->{cursor_curr} + $offset;
$self->{trace}
and warn "Tokenizer found string end delimiter at $cursor_limit\n";
$self->{cursor_limit} = $cursor_limit;
$self->{cursor_modifiers} = $cursor_limit + 1;
$self->{delimiter_finish} = substr
$self->{content},
$self->{cursor_limit},
1;
push @tokens, $self->make_token( 1,
'PPIx::Regexp::Token::Delimiter' );
} else {
return $self->__init_error();
}
{
pos $self->{content} = $self->{cursor_modifiers};
local $self->{cursor_curr} = $self->{cursor_modifiers};
local $self->{cursor_limit} = length $self->{content};
my @trailing;
if ( my $len = $self->find_regexp( qr{ \A \s+ }smx ) ) {
push @trailing, $self->make_token( $len,
'PPIx::Regexp::Token::Whitespace' );
}
if ( my $len = $self->find_regexp( qr{ \A .+ }smx ) ) {
push @trailing, $self->make_token( $len, TOKEN_UNKNOWN, {
error => 'Trailing characters after expression',
} );
}
$self->{trailing_tokens} = \@trailing;
$self->{effective_modifiers} = undef;
$self->{modifiers} = [ {} ];
}
$self->{find} = undef;
$self->_set_mode( 'repl' );
return @tokens;
}
# Return the number of extra delimited parts. This will be 0 for all
# strings.
sub __number_of_extra_parts {
return 0;
}
# Return the classes for the parts of the expression.
sub __part_classes {
return ( 'PPIx::Regexp::Structure::Replacement' );
}
{
my %from_delim = map { $_ => 1 } '', 'qx', '<<';
my %from_type = map { $_ => 1 } qw{ qq qx };
sub interpolates {
my ( $self ) = @_;
$from_delim{$self->{type}}
and return $self->{delimiter_start} !~ m/ \A ' /smx;
return $from_type{$self->{type}};
}
}
1;
__END__
=head1 NAME
PPIx::Regexp::StringTokenizer - Tokenize a string literal
=head1 SYNOPSIS
use PPIx::Regexp::Dumper;
PPIx::Regexp::Dumper->new( 'qq{foo$bar}', parse => 'string' )
->print();
C<PPIx::Regexp::StringTokenizer> is a
L<PPIx::Regexp::Tokenizer|PPIx::Regexp::Tokenizer>.
C<PPIx::Regexp::StringTokenizer> has no descendants.
=head1 DESCRIPTION
This class provides tokenization of string literals. It is deprecated in
favor of the use of L<PPIx::QuoteLike|PPIx::QuoteLike>.
=head1 METHODS
This class supports no public methods over and above those of the
superclass.
=head1 SEE ALSO
L<PPIx::Regexp::Tokenizer|PPIx::Regexp::Tokenizer>.
=head1 SUPPORT
Support is by the author. Please file bug reports at
L<http://rt.cpan.org>, or in electronic mail to the author.
=head1 AUTHOR
Tom Wyant F<wyant at cpan dot org>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2015-2018 by Thomas R. Wyant, III
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl 5.10.0. For more details, see the full text
of the licenses in the directory LICENSES.
This program is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of
merchantability or fitness for a particular purpose.
=cut
# ex: set textwidth=72 :
|