Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate all keywords from immediately-following single quotes. #77

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Revision history for Perl extension PPI
- Moved repository to GitHub: https://github.com/adamkennedy/PPI

Details:
- Disallow Perl4 package separator ' immediately after keywords
(GitHub #58) (MOREGAN)
- Stop directing bugs to rt.cpan.org (GitHub #40) (MOREGAN)
- Fix documentation reference to List::Util (RT #75308) (RWSTAUNER)
- Improve scalability of parsing long lines, and remove the size
Expand Down
43 changes: 33 additions & 10 deletions lib/PPI/Token/Word.pm
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ now, look at L<Perl::Critic::Utils>.
use strict;
use PPI::Token ();

use vars qw{$VERSION @ISA %OPERATOR %QUOTELIKE};
use vars qw{$VERSION @ISA %OPERATOR %QUOTELIKE %KEYWORDS};
BEGIN {
$VERSION = '1.218';
@ISA = 'PPI::Token';
Expand All @@ -57,6 +57,35 @@ BEGIN {
'tr' => 'Regexp::Transliterate',
'y' => 'Regexp::Transliterate',
);

# List of keywords is from regen/keywords.pl in the perl source.
%KEYWORDS = map { $_ => 1 } qw{
abs accept alarm and atan2 bind binmode bless break caller chdir chmod
chomp chop chown chr chroot close closedir cmp connect continue cos
crypt dbmclose dbmopen default defined delete die do dump each else
elsif endgrent endhostent endnetent endprotoent endpwent endservent
eof eq eval evalbytes exec exists exit exp fc fcntl fileno flock for
foreach fork format formline ge getc getgrent getgrgid getgrnam
gethostbyaddr gethostbyname gethostent getlogin getnetbyaddr
getnetbyname getnetent getpeername getpgrp getppid getpriority
getprotobyname getprotobynumber getprotoent getpwent getpwnam
getpwuid getservbyname getservbyport getservent getsockname
getsockopt given glob gmtime goto grep gt hex if index int ioctl join
keys kill last lc lcfirst le length link listen local localtime lock
log lstat lt m map mkdir msgctl msgget msgrcv msgsnd my ne next no
not oct open opendir or ord our pack package pipe pop pos print
printf prototype push q qq qr quotemeta qw qx rand read readdir
readline readlink readpipe recv redo ref rename require reset return
reverse rewinddir rindex rmdir s say scalar seek seekdir select semctl
semget semop send setgrent sethostent setnetent setpgrp
setpriority setprotoent setpwent setservent setsockopt shift shmctl
shmget shmread shmwrite shutdown sin sleep socket socketpair sort
splice split sprintf sqrt srand stat state study sub substr symlink
syscall sysopen sysread sysseek system syswrite tell telldir tie tied
time times tr truncate uc ucfirst umask undef unless unlink unpack
unshift untie until use utime values vec wait waitpid wantarray warn
when while write x xor y
};
}

=pod
Expand Down Expand Up @@ -133,12 +162,6 @@ sub method_call {
}


my %backoff = map { $_ => 1 } qw{
eq ne ge le gt lt
q qq qx qw qr m s tr y
pack unpack
};

sub __TOKENIZER__on_char {
my $class = shift;
my $t = shift;
Expand All @@ -149,8 +172,8 @@ sub __TOKENIZER__on_char {
my $word = $1;
# Special Case: If we accidentally treat eq'foo' like
# the word "eq'foo", then just make 'eq' (or whatever
# else is in the %backoff hash.
if ( $word =~ /^(\w+)'/ && $backoff{$1} ) {
# else is in the %KEYWORDS hash.
if ( $word =~ /^(\w+)'/ && $KEYWORDS{$1} ) {
$word = $1;
}
$t->{token}->{content} .= $word;
Expand Down Expand Up @@ -220,7 +243,7 @@ sub __TOKENIZER__commit {
# Special Case: If we accidentally treat eq'foo' like the word "eq'foo",
# then unwind it and just make it 'eq' (or the other stringy comparitors)
my $word = $1;
if ( $word =~ /^(\w+)'/ && $backoff{$1} ) {
if ( $word =~ /^(\w+)'/ && $KEYWORDS{$1} ) {
$word = $1;
}

Expand Down
Loading