summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarko Kreen2013-02-20 20:23:43 +0000
committerMarko Kreen2013-02-20 20:23:43 +0000
commite99a53bfd59eda75d499c811ceb9696620777234 (patch)
treecca5631e075e28489c2077ddd89d1749cf3decf5
parent7524030ac84b5d8757d5b6ce8b7b2842edc16a44 (diff)
kwcheck.py: compare postgres keywords table
-rwxr-xr-xmisc/kwcheck.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/misc/kwcheck.py b/misc/kwcheck.py
new file mode 100755
index 00000000..713167a8
--- /dev/null
+++ b/misc/kwcheck.py
@@ -0,0 +1,50 @@
+#! /usr/bin/env python
+
+import sys
+import re
+
+import pkgloader
+pkgloader.require('skytools', '3.0')
+import skytools.quoting
+
+kwmap = skytools.quoting._ident_kwmap
+
+fn = "/opt/src/pgsql/postgresql/src/include/parser/kwlist.h"
+if len(sys.argv) == 2:
+ fn = sys.argv[1]
+
+rc = re.compile(r'PG_KEYWORD[(]"(.*)" , \s* \w+ , \s* (\w+) [)]', re.X)
+
+data = open(fn, 'r').read()
+full_map = {}
+cur_map = {}
+print "== new =="
+for kw, cat in rc.findall(data):
+ full_map[kw] = 1
+ if cat == 'UNRESERVED_KEYWORD':
+ continue
+ if cat == 'COL_NAME_KEYWORD':
+ continue
+ cur_map[kw] = 1
+ if kw not in kwmap:
+ print kw, cat
+ kwmap[kw] = 1
+
+print "== obsolete =="
+kws = kwmap.keys()
+kws.sort()
+for k in kws:
+ if k not in full_map:
+ print k, '(not in full_map)'
+ elif k not in cur_map:
+ print k, '(not in cur_map)'
+
+print "== full list =="
+ln = ""
+for k in kws:
+ ln += '"%s":1, ' % k
+ if len(ln) > 70:
+ print ln.strip()
+ ln = ""
+print ln.strip()
+