This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Integrate:
[perl5.git] / perl_keyword.pl
CommitLineData
35f810b8
NC
1
2# How to generate the logic of the lookup table Perl_keyword() in toke.c
3
9ff906c0 4use Devel::Tokenizer::C 0.05;
35f810b8 5use strict;
64446b2f 6use warnings;
35f810b8
NC
7
8my @pos = qw(__DATA__ __END__ AUTOLOAD BEGIN CHECK DESTROY do delete defined
9 END else eval elsif exists for format foreach grep goto glob INIT
10 if last local m my map next no our pos print printf package
11 prototype q qr qq qw qx redo return require s scalar sort split
12 study sub tr tie tied use undef until untie unless while y);
13
64446b2f 14# In 5.8.x there is no err
35f810b8
NC
15my @neg = qw(__FILE__ __LINE__ __PACKAGE__ and abs alarm atan2 accept bless
16 bind binmode CORE cmp chr cos chop close chdir chomp chmod chown
17 crypt chroot caller connect closedir continue die dump dbmopen
64446b2f 18 dbmclose eq eof exp exit exec each endgrent endpwent
35f810b8
NC
19 endnetent endhostent endservent endprotoent fork fcntl flock
20 fileno formline getppid getpgrp getpwent getpwnam getpwuid
21 getpeername getprotoent getpriority getprotobyname
22 getprotobynumber gethostbyname gethostbyaddr gethostent
23 getnetbyname getnetbyaddr getnetent getservbyname getservbyport
24 getservent getsockname getsockopt getgrent getgrnam getgrgid
25 getlogin getc gt ge gmtime hex int index ioctl join keys kill lt
26 le lc log link lock lstat length listen lcfirst localtime mkdir
27 msgctl msgget msgrcv msgsnd ne not or ord oct open opendir pop
28 push pack pipe quotemeta ref read rand recv rmdir reset rename
29 rindex reverse readdir readlink readline readpipe rewinddir seek
30 send semop select semctl semget setpgrp seekdir setpwent setgrent
31 setnetent setsockopt sethostent setservent setpriority
32 setprotoent shift shmctl shmget shmread shmwrite shutdown sin
33 sleep socket socketpair sprintf splice sqrt srand stat substr
34 system symlink syscall sysopen sysread sysseek syswrite tell time
35 times telldir truncate uc utime umask unpack unlink unshift
36 ucfirst values vec warn wait write waitpid wantarray x xor);
37
64446b2f
NC
38my %pos = map { ($_ => 1) } @pos;
39
40my $t = Devel::Tokenizer::C->new( TokenFunc => \&perl_keyword
41 , TokenString => 'name'
42 , StringLength => 'len'
43 , MergeSwitches => 1
44 );
45
46$t->add_tokens(@pos, @neg, 'elseif');
35f810b8 47
64446b2f
NC
48my $switch = $t->generate(Indent => ' ');
49
50print <<END;
51/*
52 * The following code was generated by $0.
53 */
54
55I32
56Perl_keyword (pTHX_ char *name, I32 len)
57{
58$switch
59unknown:
60 return 0;
61}
62END
63
64sub perl_keyword
65{
66 my $k = shift;
67 my $sign = $pos{$k} ? '' : '-';
68
69 if ($k eq 'elseif') {
70 return <<END;
35f810b8
NC
71if(ckWARN_d(WARN_SYNTAX))
72 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
64446b2f
NC
73END
74 }
35f810b8 75
64446b2f
NC
76 return <<END;
77return ${sign}KEY_$k;
78END
79}