2019-05-07 15:29:39 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
#
|
Allow most keywords to be used as column labels without requiring AS.
Up to now, if you tried to omit "AS" before a column label in a SELECT
list, it would only work if the column label was an IDENT, that is not
any known keyword. This is rather unfriendly considering that we have
so many keywords and are constantly growing more. In the wake of commit
1ed6b8956 it's possible to improve matters quite a bit.
We'd originally tried to make this work by having some of the existing
keyword categories be allowed without AS, but that didn't work too well,
because each category contains a few special cases that don't work
without AS. Instead, invent an entirely orthogonal keyword property
"can be bare column label", and mark all keywords that way for which
we don't get shift/reduce errors by doing so.
It turns out that of our 450 current keywords, all but 39 can be made
bare column labels, improving the situation by over 90%. This number
might move around a little depending on future grammar work, but it's
a pretty nice improvement.
Mark Dilger, based on work by myself and Robert Haas;
review by John Naylor
Discussion: https://postgr.es/m/38ca86db-42ab-9b48-2902-337a0d6b8311@2ndquadrant.com
2020-09-18 22:46:26 +02:00
|
|
|
# Generate the keywords table for the documentation's SQL Key Words appendix
|
|
|
|
#
|
2022-01-08 01:04:57 +01:00
|
|
|
# Copyright (c) 2019-2022, PostgreSQL Global Development Group
|
2019-05-07 15:29:39 +02:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2019-05-14 09:56:40 +02:00
|
|
|
my @sql_versions = reverse sort ('1992', '2011', '2016');
|
2019-05-07 15:29:39 +02:00
|
|
|
|
|
|
|
my $srcdir = $ARGV[0];
|
|
|
|
|
|
|
|
my %keywords;
|
Allow most keywords to be used as column labels without requiring AS.
Up to now, if you tried to omit "AS" before a column label in a SELECT
list, it would only work if the column label was an IDENT, that is not
any known keyword. This is rather unfriendly considering that we have
so many keywords and are constantly growing more. In the wake of commit
1ed6b8956 it's possible to improve matters quite a bit.
We'd originally tried to make this work by having some of the existing
keyword categories be allowed without AS, but that didn't work too well,
because each category contains a few special cases that don't work
without AS. Instead, invent an entirely orthogonal keyword property
"can be bare column label", and mark all keywords that way for which
we don't get shift/reduce errors by doing so.
It turns out that of our 450 current keywords, all but 39 can be made
bare column labels, improving the situation by over 90%. This number
might move around a little depending on future grammar work, but it's
a pretty nice improvement.
Mark Dilger, based on work by myself and Robert Haas;
review by John Naylor
Discussion: https://postgr.es/m/38ca86db-42ab-9b48-2902-337a0d6b8311@2ndquadrant.com
2020-09-18 22:46:26 +02:00
|
|
|
my %as_keywords;
|
2019-05-07 15:29:39 +02:00
|
|
|
|
Allow most keywords to be used as column labels without requiring AS.
Up to now, if you tried to omit "AS" before a column label in a SELECT
list, it would only work if the column label was an IDENT, that is not
any known keyword. This is rather unfriendly considering that we have
so many keywords and are constantly growing more. In the wake of commit
1ed6b8956 it's possible to improve matters quite a bit.
We'd originally tried to make this work by having some of the existing
keyword categories be allowed without AS, but that didn't work too well,
because each category contains a few special cases that don't work
without AS. Instead, invent an entirely orthogonal keyword property
"can be bare column label", and mark all keywords that way for which
we don't get shift/reduce errors by doing so.
It turns out that of our 450 current keywords, all but 39 can be made
bare column labels, improving the situation by over 90%. This number
might move around a little depending on future grammar work, but it's
a pretty nice improvement.
Mark Dilger, based on work by myself and Robert Haas;
review by John Naylor
Discussion: https://postgr.es/m/38ca86db-42ab-9b48-2902-337a0d6b8311@2ndquadrant.com
2020-09-18 22:46:26 +02:00
|
|
|
# read SQL-spec keywords
|
2019-05-07 15:29:39 +02:00
|
|
|
|
|
|
|
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>)
|
|
|
|
{
|
Allow most keywords to be used as column labels without requiring AS.
Up to now, if you tried to omit "AS" before a column label in a SELECT
list, it would only work if the column label was an IDENT, that is not
any known keyword. This is rather unfriendly considering that we have
so many keywords and are constantly growing more. In the wake of commit
1ed6b8956 it's possible to improve matters quite a bit.
We'd originally tried to make this work by having some of the existing
keyword categories be allowed without AS, but that didn't work too well,
because each category contains a few special cases that don't work
without AS. Instead, invent an entirely orthogonal keyword property
"can be bare column label", and mark all keywords that way for which
we don't get shift/reduce errors by doing so.
It turns out that of our 450 current keywords, all but 39 can be made
bare column labels, improving the situation by over 90%. This number
might move around a little depending on future grammar work, but it's
a pretty nice improvement.
Mark Dilger, based on work by myself and Robert Haas;
review by John Naylor
Discussion: https://postgr.es/m/38ca86db-42ab-9b48-2902-337a0d6b8311@2ndquadrant.com
2020-09-18 22:46:26 +02:00
|
|
|
if (/^PG_KEYWORD\("(\w+)", \w+, (\w+)_KEYWORD\, (\w+)\)/)
|
2019-05-07 15:29:39 +02:00
|
|
|
{
|
|
|
|
$keywords{ uc $1 }{'pg'}{ lc $2 } = 1;
|
Allow most keywords to be used as column labels without requiring AS.
Up to now, if you tried to omit "AS" before a column label in a SELECT
list, it would only work if the column label was an IDENT, that is not
any known keyword. This is rather unfriendly considering that we have
so many keywords and are constantly growing more. In the wake of commit
1ed6b8956 it's possible to improve matters quite a bit.
We'd originally tried to make this work by having some of the existing
keyword categories be allowed without AS, but that didn't work too well,
because each category contains a few special cases that don't work
without AS. Instead, invent an entirely orthogonal keyword property
"can be bare column label", and mark all keywords that way for which
we don't get shift/reduce errors by doing so.
It turns out that of our 450 current keywords, all but 39 can be made
bare column labels, improving the situation by over 90%. This number
might move around a little depending on future grammar work, but it's
a pretty nice improvement.
Mark Dilger, based on work by myself and Robert Haas;
review by John Naylor
Discussion: https://postgr.es/m/38ca86db-42ab-9b48-2902-337a0d6b8311@2ndquadrant.com
2020-09-18 22:46:26 +02:00
|
|
|
$as_keywords{ uc $1 } = 1 if $3 eq 'AS_LABEL';
|
2019-05-07 15:29:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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">
|
2020-05-06 21:58:23 +02:00
|
|
|
<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*"/>
|
2019-05-07 15:29:39 +02:00
|
|
|
<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)
|
|
|
|
{
|
2020-05-12 02:03:55 +02:00
|
|
|
# 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);
|
|
|
|
|
2019-05-07 15:29:39 +02:00
|
|
|
print " <row>\n";
|
2020-05-12 02:03:55 +02:00
|
|
|
print " <entry><token>$printword</token></entry>\n";
|
2019-05-07 15:29:39 +02:00
|
|
|
|
|
|
|
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";
|
|
|
|
}
|
Allow most keywords to be used as column labels without requiring AS.
Up to now, if you tried to omit "AS" before a column label in a SELECT
list, it would only work if the column label was an IDENT, that is not
any known keyword. This is rather unfriendly considering that we have
so many keywords and are constantly growing more. In the wake of commit
1ed6b8956 it's possible to improve matters quite a bit.
We'd originally tried to make this work by having some of the existing
keyword categories be allowed without AS, but that didn't work too well,
because each category contains a few special cases that don't work
without AS. Instead, invent an entirely orthogonal keyword property
"can be bare column label", and mark all keywords that way for which
we don't get shift/reduce errors by doing so.
It turns out that of our 450 current keywords, all but 39 can be made
bare column labels, improving the situation by over 90%. This number
might move around a little depending on future grammar work, but it's
a pretty nice improvement.
Mark Dilger, based on work by myself and Robert Haas;
review by John Naylor
Discussion: https://postgr.es/m/38ca86db-42ab-9b48-2902-337a0d6b8311@2ndquadrant.com
2020-09-18 22:46:26 +02:00
|
|
|
if ($as_keywords{$word})
|
|
|
|
{
|
|
|
|
print ", requires <literal>AS</literal>";
|
|
|
|
}
|
2019-05-07 15:29:39 +02:00
|
|
|
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
|