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