This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
In Perl_yylex, move the declaration of orig_keyword, gv and gvp down to
[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',
46 );
d30bcfc1 47
4c3bbe0f
MHM
48my %pos = map { ($_ => 1) } @pos;
49
50my $t = Devel::Tokenizer::C->new( TokenFunc => \&perl_keyword
51 , TokenString => 'name'
52 , StringLength => 'len'
53 , MergeSwitches => 1
54 );
55
56$t->add_tokens(@pos, @neg, 'elseif');
d30bcfc1 57
4c3bbe0f
MHM
58my $switch = $t->generate(Indent => ' ');
59
60print <<END;
61/*
62 * The following code was generated by $0.
63 */
64
65I32
672994ce 66Perl_keyword (pTHX_ const char *name, I32 len)
4c3bbe0f
MHM
67{
68$switch
69unknown:
70 return 0;
71}
72END
73
74sub perl_keyword
75{
76 my $k = shift;
77 my $sign = $pos{$k} ? '' : '-';
78
79 if ($k eq 'elseif') {
80 return <<END;
d30bcfc1
NC
81if(ckWARN_d(WARN_SYNTAX))
82 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
4c3bbe0f
MHM
83END
84 }
0d863452
RH
85 elsif (my $feature = $feature_kw{$k}) {
86 my $feature_len = length($feature);
87 $feature =~ s/([\\"])/\\$1/g;
88 return <<END;
89return (FEATURE_IS_ENABLED("$feature", $feature_len) ? ${sign}KEY_$k : 0);
90END
91 }
4c3bbe0f
MHM
92 return <<END;
93return ${sign}KEY_$k;
94END
95}