Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b753bc0

Browse files
committed
doc: Generate keywords table automatically
The SQL keywords table in the documentation had until now been generated by some ad hoc scripting outside the source tree once for each major release. This changes it to an automated process. We have the PostgreSQL keywords available in a parseable format in parser/kwlist.h. For the relevant SQL standard versions, keep the keyword lists in new text files. A new script generate-keywords-table.pl pulls it all together and produces a DocBook table. The final output in the documentation should be identical after this change. Discussion: https://www.postgresql.org/message-id/flat/07daeadd-8c82-0d95-5e19-e350502cb749%402ndquadrant.com
1 parent 7db0cde commit b753bc0

19 files changed

+1645
-5361
lines changed

doc/src/sgml/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
/features-supported.sgml
1616
/features-unsupported.sgml
1717
/errcodes-table.sgml
18+
/keywords-table.sgml
1819
/version.sgml
1920
# Assorted byproducts from building the above
2021
/postgres.xml

doc/src/sgml/Makefile

+5-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ override XSLTPROCFLAGS += --stringparam pg.version '$(VERSION)'
5353

5454

5555
GENERATED_SGML = version.sgml \
56-
features-supported.sgml features-unsupported.sgml errcodes-table.sgml
56+
features-supported.sgml features-unsupported.sgml errcodes-table.sgml \
57+
keywords-table.sgml
5758

5859
ALLSGML := $(wildcard $(srcdir)/*.sgml $(srcdir)/ref/*.sgml) $(GENERATED_SGML)
5960

@@ -96,6 +97,9 @@ features-unsupported.sgml: $(top_srcdir)/src/backend/catalog/sql_feature_package
9697
errcodes-table.sgml: $(top_srcdir)/src/backend/utils/errcodes.txt generate-errcodes-table.pl
9798
$(PERL) $(srcdir)/generate-errcodes-table.pl $< > $@
9899

100+
keywords-table.sgml: $(top_srcdir)/src/include/parser/kwlist.h $(wildcard $(srcdir)/keywords/sql*.txt) generate-keywords-table.pl
101+
$(PERL) $(srcdir)/generate-keywords-table.pl $(srcdir) > $@
102+
99103

100104
##
101105
## Generation of some text files.

doc/src/sgml/filelist.sgml

+1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@
175175
<!ENTITY features-unsupported SYSTEM "features-unsupported.sgml">
176176

177177
<!ENTITY errcodes-table SYSTEM "errcodes-table.sgml">
178+
<!ENTITY keywords-table SYSTEM "keywords-table.sgml">
178179

179180
<!-- back matter -->
180181
<!ENTITY biblio SYSTEM "biblio.sgml">
+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/usr/bin/perl
2+
#
3+
# Generate the keywords table file
4+
# Copyright (c) 2019, PostgreSQL Global Development Group
5+
6+
use strict;
7+
use warnings;
8+
9+
my @sql_versions = reverse sort ('1992', '2008', '2011');
10+
11+
my $srcdir = $ARGV[0];
12+
13+
my %keywords;
14+
15+
# read SQL keywords
16+
17+
foreach my $ver (@sql_versions)
18+
{
19+
foreach my $res ('reserved', 'nonreserved')
20+
{
21+
foreach my $file (glob "$srcdir/keywords/sql${ver}*-${res}.txt")
22+
{
23+
open my $fh, '<', $file or die;
24+
25+
while (<$fh>)
26+
{
27+
chomp;
28+
$keywords{$_}{$ver}{$res} = 1;
29+
}
30+
31+
close $fh;
32+
}
33+
}
34+
}
35+
36+
# read PostgreSQL keywords
37+
38+
open my $fh, '<', "$srcdir/../../../src/include/parser/kwlist.h" or die;
39+
40+
while (<$fh>)
41+
{
42+
if (/^PG_KEYWORD\("(\w+)", \w+, (\w+)_KEYWORD\)/)
43+
{
44+
$keywords{ uc $1 }{'pg'}{ lc $2 } = 1;
45+
}
46+
}
47+
48+
close $fh;
49+
50+
# print output
51+
52+
print "<!-- autogenerated, do not edit -->\n";
53+
54+
print <<END;
55+
<table id="keywords-table">
56+
<title><acronym>SQL</acronym> Key Words</title>
57+
58+
<tgroup cols="5">
59+
<thead>
60+
<row>
61+
<entry>Key Word</entry>
62+
<entry><productname>PostgreSQL</productname></entry>
63+
END
64+
65+
foreach my $ver (@sql_versions)
66+
{
67+
my $s = ($ver eq '1992' ? 'SQL-92' : "SQL:$ver");
68+
print " <entry>$s</entry>\n";
69+
}
70+
71+
print <<END;
72+
</row>
73+
</thead>
74+
75+
<tbody>
76+
END
77+
78+
foreach my $word (sort keys %keywords)
79+
{
80+
print " <row>\n";
81+
print " <entry><token>$word</token></entry>\n";
82+
83+
print " <entry>";
84+
if ($keywords{$word}{pg}{'unreserved'})
85+
{
86+
print "non-reserved";
87+
}
88+
elsif ($keywords{$word}{pg}{'col_name'})
89+
{
90+
print "non-reserved (cannot be function or type)";
91+
}
92+
elsif ($keywords{$word}{pg}{'type_func_name'})
93+
{
94+
print "reserved (can be function or type)";
95+
}
96+
elsif ($keywords{$word}{pg}{'reserved'})
97+
{
98+
print "reserved";
99+
}
100+
print "</entry>\n";
101+
102+
foreach my $ver (@sql_versions)
103+
{
104+
print " <entry>";
105+
if ($keywords{$word}{$ver}{'reserved'})
106+
{
107+
print "reserved";
108+
}
109+
elsif ($keywords{$word}{$ver}{'nonreserved'})
110+
{
111+
print "non-reserved";
112+
}
113+
print "</entry>\n";
114+
}
115+
print " </row>\n";
116+
}
117+
118+
print <<END;
119+
</tbody>
120+
</tgroup>
121+
</table>
122+
END

0 commit comments

Comments
 (0)