|  | 
| 1 |  | -#!/usr/bin/perl | 
|  | 1 | +#!/usr/bin/perl -w | 
|  | 2 | + | 
|  | 3 | +use strict; | 
| 2 | 4 | 
 | 
| 3 | 5 | # Check that the keyword lists in gram.y and kwlist.h are sane. Run from | 
| 4 | 6 | # the top directory, or pass a path to a top directory as argument. | 
| 5 | 7 | # | 
| 6 |  | -# $PostgreSQL: pgsql/src/tools/check_keywords.pl,v 1.1 2009/04/29 05:05:57 heikki Exp $ | 
|  | 8 | +# $PostgreSQL: pgsql/src/tools/check_keywords.pl,v 1.2 2009/04/30 10:26:35 heikki Exp $ | 
|  | 9 | + | 
|  | 10 | +my $path; | 
| 7 | 11 | 
 | 
| 8 | 12 | if (@ARGV) { | 
| 9 | 13 | 	$path = $ARGV[0]; | 
| 10 | 14 | 	shift @ARGV; | 
|  | 15 | +} else { | 
|  | 16 | +	$path = ".";  | 
| 11 | 17 | } | 
| 12 | 18 | 
 | 
| 13 |  | -if ($path eq '') { $path = "."; } | 
| 14 |  | - | 
| 15 | 19 | $[ = 1;			# set array base to 1 | 
| 16 | 20 | $, = ' ';		# set output field separator | 
| 17 | 21 | $\ = "\n";		# set output record separator | 
| 18 | 22 | 
 | 
|  | 23 | +my %keyword_categories; | 
| 19 | 24 | $keyword_categories{'unreserved_keyword'} = 'UNRESERVED_KEYWORD'; | 
| 20 | 25 | $keyword_categories{'col_name_keyword'} = 'COL_NAME_KEYWORD'; | 
| 21 | 26 | $keyword_categories{'type_func_name_keyword'} = 'TYPE_FUNC_NAME_KEYWORD'; | 
| 22 | 27 | $keyword_categories{'reserved_keyword'} = 'RESERVED_KEYWORD'; | 
| 23 | 28 | 
 | 
| 24 |  | -$gram_filename = "$path/src/backend/parser/gram.y"; | 
| 25 |  | -open(GRAM, $gram_filename) || die("Could not open $gram_filename!"); | 
|  | 29 | +my $gram_filename = "$path/src/backend/parser/gram.y"; | 
|  | 30 | +open(GRAM, $gram_filename) || die("Could not open : $gram_filename"); | 
|  | 31 | + | 
|  | 32 | +my ($S, $s, $k, $n, $kcat); | 
|  | 33 | +my $comment; | 
|  | 34 | +my @arr; | 
|  | 35 | +my %keywords; | 
|  | 36 | + | 
| 26 | 37 | line: while (<GRAM>) { | 
| 27 | 38 |     chomp;	# strip record separator | 
| 28 |  | -    @Fld = split(' ', $_, -1); | 
| 29 | 39 | 
 | 
| 30 | 40 |     $S = $_; | 
| 31 | 41 |     # Make sure any braces are split | 
|  | 
| 50 | 60 |     $n = (@arr = split(' ', $S)); | 
| 51 | 61 | 
 | 
| 52 | 62 |     # Ok, we're in a keyword list. Go through each field in turn | 
| 53 |  | -    for ($fieldIndexer = 1; $fieldIndexer <= $n; $fieldIndexer++) { | 
|  | 63 | +    for (my $fieldIndexer = 1; $fieldIndexer <= $n; $fieldIndexer++) { | 
| 54 | 64 | 	if ($arr[$fieldIndexer] eq '*/' && $comment) { | 
| 55 | 65 | 	    $comment = 0; | 
| 56 | 66 | 	    next; | 
|  | 
| 69 | 79 | 
 | 
| 70 | 80 | 	if ($arr[$fieldIndexer] eq ';') { | 
| 71 | 81 | 	    # end of keyword list | 
| 72 |  | -	    $line = ''; | 
| 73 | 82 | 	    $kcat = ''; | 
| 74 | 83 | 	    next; | 
| 75 | 84 | 	} | 
|  | 
| 85 | 94 | close GRAM; | 
| 86 | 95 | 
 | 
| 87 | 96 | # Check that all keywords are in alphabetical order | 
|  | 97 | +my ($prevkword, $kword, $bare_kword); | 
| 88 | 98 | foreach $kcat (keys %keyword_categories) { | 
| 89 | 99 |     $prevkword = ''; | 
| 90 | 100 | 
 | 
|  | 
| 103 | 113 | # kwhashes is a hash of hashes, keyed by keyword category id, e.g. | 
| 104 | 114 | # UNRESERVED_KEYWORD. Each inner hash is a keyed by keyword id, e.g. ABORT_P | 
| 105 | 115 | # with a dummy value. | 
|  | 116 | +my %kwhashes; | 
| 106 | 117 | while ( my ($kcat, $kcat_id) = each(%keyword_categories) ) { | 
| 107 | 118 |     @arr = @{$keywords{$kcat}}; | 
| 108 | 119 | 
 | 
|  | 
| 114 | 125 | 
 | 
| 115 | 126 | # Now read in kwlist.h | 
| 116 | 127 | 
 | 
| 117 |  | -$kwlist_filename = "$path/src/include/parser/kwlist.h"; | 
| 118 |  | -open(KWLIST, $kwlist_filename) || die("Could not open $kwlist_filename!"); | 
|  | 128 | +my $kwlist_filename = "$path/src/include/parser/kwlist.h"; | 
|  | 129 | +open(KWLIST, $kwlist_filename) || die("Could not open : $kwlist_filename"); | 
| 119 | 130 | 
 | 
| 120 |  | -$prevkwstring = ''; | 
|  | 131 | +my $prevkwstring = ''; | 
|  | 132 | +my $bare_kwname; | 
|  | 133 | +my %kwhash; | 
| 121 | 134 | kwlist_line: while (<KWLIST>) { | 
| 122 | 135 |     my($line) = $_; | 
| 123 | 136 | 
 | 
|  | 
0 commit comments