This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regen/mk_invlists.pl: Add dependency
[perl5.git] / regen / keywords.pl
CommitLineData
eada5d41 1#!/usr/bin/perl -w
f133ac5d 2#
6294c161
DM
3# Regenerate (overwriting only if changed):
4#
f133ac5d 5# keywords.h keywords.c
6294c161
DM
6#
7# from information stored in the DATA section of this file.
8#
9# Accepts the standard regen_lib -q and -v args.
6294c161 10
eada5d41 11use strict;
f133ac5d 12use Devel::Tokenizer::C 0.05;
a0d0e21e 13
af001346 14require 'regen/regen_lib.pl';
b6b9a099 15
cc49830d
NC
16my $h = open_new('keywords.h', '>',
17 { by => 'regen/keywords.pl', from => 'its data',
18 file => 'keywords.h', style => '*',
19 copyright => [1994 .. 1997, 1999 .. 2002, 2005 .. 2007]});
20my $c = open_new('keywords.c', '>',
21 { by => 'regen/keywords.pl', from => 'its data', style => '*'});
d6376244 22
f133ac5d 23my %by_strength;
a0d0e21e 24
eada5d41 25my $keynum = 0;
a0d0e21e
LW
26while (<DATA>) {
27 chop;
28 next unless $_;
29 next if /^#/;
f133ac5d
NC
30 my ($strength, $keyword) = /^([- +])([A-Z_a-z2]+)/;
31 die "Bad line '$_'" unless defined $strength;
32 print $h tab(5, "#define KEY_$keyword"), $keynum++, "\n";
33 push @{$by_strength{$strength}}, $keyword;
a0d0e21e
LW
34}
35
e36901c8
FC
36# If this hash changes, make sure the equivalent hash in
37# dist/B-Deparse/Deparse.pm is also updated.
f133ac5d
NC
38my %feature_kw = (
39 given => 'switch',
40 when => 'switch',
41 default => 'switch',
42 # continue is already a keyword
43 break => 'switch',
b6b9a099 44
f133ac5d 45 say => 'say',
a0d0e21e 46
f133ac5d 47 state => 'state',
7d789282
FC
48
49 evalbytes=>'evalbytes',
84ed0108
FC
50
51 __SUB__ => '__SUB__',
838f2281
BF
52
53 fc => 'fc',
f133ac5d
NC
54 );
55
56my %pos = map { ($_ => 1) } @{$by_strength{'+'}};
57
58my $t = Devel::Tokenizer::C->new(TokenFunc => \&perl_keyword,
59 TokenString => 'name',
60 StringLength => 'len',
61 MergeSwitches => 1,
62 );
63
64$t->add_tokens(@{$by_strength{'+'}}, @{$by_strength{'-'}}, 'elseif');
65
66my $switch = $t->generate(Indent => ' ');
67
68print $c <<"END";
69#include "EXTERN.h"
70#define PERL_IN_KEYWORDS_C
71#include "perl.h"
72#include "keywords.h"
2846acbf 73#include "feature.h"
f133ac5d
NC
74
75I32
76Perl_keyword (pTHX_ const char *name, I32 len, bool all_keywords)
77{
f133ac5d
NC
78 PERL_ARGS_ASSERT_KEYWORD;
79
80$switch
81unknown:
82 return 0;
83}
84END
85
86sub perl_keyword
87{
88 my $k = shift;
89 my $sign = $pos{$k} ? '' : '-';
90
91 if ($k eq 'elseif') {
92 return <<END;
93Perl_ck_warner_d(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
94END
95 }
96 elsif (my $feature = $feature_kw{$k}) {
97 $feature =~ s/([\\"])/\\$1/g;
98 return <<END;
2846acbf 99return (all_keywords || FEATURE_\U$feature\E_IS_ENABLED ? ${sign}KEY_$k : 0);
f133ac5d
NC
100END
101 }
102 return <<END;
103return ${sign}KEY_$k;
a0d0e21e 104END
f133ac5d
NC
105}
106
107read_only_bottom_close_and_rename($_, [$0]) foreach $c, $h;
108
c2f605db
FC
109
110# coresub_op in op.c expects __FILE__, __LINE__ and __PACKAGE__ to be the
111# first three.
112
f133ac5d
NC
113__END__
114
115 NULL
116-__FILE__
117-__LINE__
118-__PACKAGE__
119+__DATA__
120+__END__
84ed0108 121-__SUB__
f133ac5d
NC
122+AUTOLOAD
123+BEGIN
124+UNITCHECK
f133ac5d
NC
125+DESTROY
126+END
127+INIT
128+CHECK
129-abs
130-accept
131-alarm
132-and
133-atan2
134-bind
135-binmode
136-bless
137-break
138-caller
139-chdir
140-chmod
141-chomp
142-chop
143-chown
144-chr
145-chroot
146-close
147-closedir
148-cmp
149-connect
150-continue
151-cos
152-crypt
153-dbmclose
154-dbmopen
155+default
156+defined
157+delete
158-die
159+do
160-dump
161-each
162+else
163+elsif
164-endgrent
165-endhostent
166-endnetent
167-endprotoent
168-endpwent
169-endservent
170-eof
171-eq
172+eval
7d789282 173-evalbytes
f133ac5d
NC
174-exec
175+exists
176-exit
177-exp
838f2281 178-fc
f133ac5d
NC
179-fcntl
180-fileno
181-flock
182+for
183+foreach
184-fork
185+format
186-formline
187-ge
188-getc
189-getgrent
190-getgrgid
191-getgrnam
192-gethostbyaddr
193-gethostbyname
194-gethostent
195-getlogin
196-getnetbyaddr
197-getnetbyname
198-getnetent
199-getpeername
200-getpgrp
201-getppid
202-getpriority
203-getprotobyname
204-getprotobynumber
205-getprotoent
206-getpwent
207-getpwnam
208-getpwuid
209-getservbyname
210-getservbyport
211-getservent
212-getsockname
213-getsockopt
214+given
215+glob
216-gmtime
217+goto
218+grep
219-gt
220-hex
221+if
222-index
223-int
224-ioctl
225-join
226-keys
227-kill
228+last
229-lc
230-lcfirst
231-le
232-length
233-link
234-listen
235+local
236-localtime
237-lock
238-log
239-lstat
240-lt
241+m
242+map
243-mkdir
244-msgctl
245-msgget
246-msgrcv
247-msgsnd
248+my
249-ne
250+next
251+no
252-not
253-oct
254-open
255-opendir
256-or
257-ord
258+our
259-pack
260+package
261-pipe
262-pop
263+pos
264+print
265+printf
266+prototype
267-push
268+q
269+qq
270+qr
271-quotemeta
272+qw
273+qx
274-rand
275-read
276-readdir
277-readline
278-readlink
279-readpipe
280-recv
281+redo
282-ref
283-rename
284+require
285-reset
286+return
287-reverse
288-rewinddir
289-rindex
290-rmdir
291+s
292+say
293+scalar
294-seek
295-seekdir
296-select
297-semctl
298-semget
299-semop
300-send
301-setgrent
302-sethostent
303-setnetent
304-setpgrp
305-setpriority
306-setprotoent
307-setpwent
308-setservent
309-setsockopt
310-shift
311-shmctl
312-shmget
313-shmread
314-shmwrite
315-shutdown
316-sin
317-sleep
318-socket
319-socketpair
320+sort
321-splice
322+split
323-sprintf
324-sqrt
325-srand
326-stat
327+state
328+study
329+sub
330-substr
331-symlink
332-syscall
333-sysopen
334-sysread
335-sysseek
336-system
337-syswrite
338-tell
339-telldir
340-tie
341-tied
342-time
343-times
344+tr
345-truncate
346-uc
347-ucfirst
348-umask
349+undef
350+unless
351-unlink
352-unpack
353-unshift
354-untie
355+until
356+use
357-utime
358-values
359-vec
360-wait
361-waitpid
362-wantarray
363-warn
364+when
365+while
366-write
367-x
368-xor
369+y