#!/usr/bin/perl -w # # Regenerate (overwriting only if changed): # # keywords.h keywords.c # # from information stored in the DATA section of this file. # # Accepts the standard regen_lib -q and -v args. use strict; use Devel::Tokenizer::C 0.05; require 'regen/regen_lib.pl'; my $h = safer_open('keywords.h-new', 'keywords.h'); my $c = safer_open('keywords.c-new', 'keywords.c'); print $h read_only_top(lang => 'C', by => 'regen/keywords.pl', from => 'its data', file => 'keywords.h', style => '*', copyright => [1994 .. 1997, 1999 .. 2002, 2005 .. 2007]); print $c read_only_top(lang => 'C', by => 'regen/keywords.pl', from => 'its data', style => '*'); my %by_strength; my $keynum = 0; while () { chop; next unless $_; next if /^#/; my ($strength, $keyword) = /^([- +])([A-Z_a-z2]+)/; die "Bad line '$_'" unless defined $strength; print $h tab(5, "#define KEY_$keyword"), $keynum++, "\n"; push @{$by_strength{$strength}}, $keyword; } my %feature_kw = ( given => 'switch', when => 'switch', default => 'switch', # continue is already a keyword break => 'switch', say => 'say', state => 'state', ); my %pos = map { ($_ => 1) } @{$by_strength{'+'}}; my $t = Devel::Tokenizer::C->new(TokenFunc => \&perl_keyword, TokenString => 'name', StringLength => 'len', MergeSwitches => 1, ); $t->add_tokens(@{$by_strength{'+'}}, @{$by_strength{'-'}}, 'elseif'); my $switch = $t->generate(Indent => ' '); print $c <<"END"; #include "EXTERN.h" #define PERL_IN_KEYWORDS_C #include "perl.h" #include "keywords.h" I32 Perl_keyword (pTHX_ const char *name, I32 len, bool all_keywords) { dVAR; PERL_ARGS_ASSERT_KEYWORD; $switch unknown: return 0; } END sub perl_keyword { my $k = shift; my $sign = $pos{$k} ? '' : '-'; if ($k eq 'elseif') { return <