1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
#!/usr/bin/perl
#
# Generate the keywords table for the documentation's SQL Key Words appendix
#
# Copyright (c) 2019-2022, PostgreSQL Global Development Group
use strict;
use warnings;
my @sql_versions = reverse sort ('1992', '2011', '2016');
my $srcdir = $ARGV[0];
my %keywords;
my %as_keywords;
# read SQL-spec keywords
foreach my $ver (@sql_versions)
{
foreach my $res ('reserved', 'nonreserved')
{
foreach my $file (glob "$srcdir/keywords/sql${ver}*-${res}.txt")
{
open my $fh, '<', $file or die;
while (<$fh>)
{
chomp;
$keywords{$_}{$ver}{$res} = 1;
}
close $fh;
}
}
}
# read PostgreSQL keywords
open my $fh, '<', "$srcdir/../../../src/include/parser/kwlist.h" or die;
while (<$fh>)
{
if (/^PG_KEYWORD\("(\w+)", \w+, (\w+)_KEYWORD\, (\w+)\)/)
{
$keywords{ uc $1 }{'pg'}{ lc $2 } = 1;
$as_keywords{ uc $1 } = 1 if $3 eq 'AS_LABEL';
}
}
close $fh;
# print output
print "<!-- autogenerated, do not edit -->\n";
print <<END;
<table id="keywords-table">
<title><acronym>SQL</acronym> Key Words</title>
<tgroup cols="5">
<colspec colname="col1" colwidth="5*"/>
<colspec colname="col2" colwidth="3*"/>
<colspec colname="col3" colwidth="2*"/>
<colspec colname="col4" colwidth="2*"/>
<colspec colname="col5" colwidth="2*"/>
<thead>
<row>
<entry>Key Word</entry>
<entry><productname>PostgreSQL</productname></entry>
END
foreach my $ver (@sql_versions)
{
my $s = ($ver eq '1992' ? 'SQL-92' : "SQL:$ver");
print " <entry>$s</entry>\n";
}
print <<END;
</row>
</thead>
<tbody>
END
foreach my $word (sort keys %keywords)
{
# Insert zwsp's into very long keywords, so that they can be broken
# into multiple lines in PDF format (or narrow HTML windows).
my $printword = $word;
$printword =~ s/_/_&zwsp;/g if (length($printword) > 20);
print " <row>\n";
print " <entry><token>$printword</token></entry>\n";
print " <entry>";
if ($keywords{$word}{pg}{'unreserved'})
{
print "non-reserved";
}
elsif ($keywords{$word}{pg}{'col_name'})
{
print "non-reserved (cannot be function or type)";
}
elsif ($keywords{$word}{pg}{'type_func_name'})
{
print "reserved (can be function or type)";
}
elsif ($keywords{$word}{pg}{'reserved'})
{
print "reserved";
}
if ($as_keywords{$word})
{
print ", requires <literal>AS</literal>";
}
print "</entry>\n";
foreach my $ver (@sql_versions)
{
print " <entry>";
if ($keywords{$word}{$ver}{'reserved'})
{
print "reserved";
}
elsif ($keywords{$word}{$ver}{'nonreserved'})
{
print "non-reserved";
}
print "</entry>\n";
}
print " </row>\n";
}
print <<END;
</tbody>
</tgroup>
</table>
END
|