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