blob: c89708157f28f83d0bf4fff16c25ea2bb7066a03 [file] [log] [blame]
Guido van Rossumeb8c9721997-03-20 19:45:51 +00001#! /usr/bin/env python
Guido van Rossum54f22ed2000-02-04 15:10:34 +00002
3"""Keywords (from "graminit.c")
4
5This file is automatically generated; please don't muck it up!
6
7To update the symbols in this file, 'cd' to the top directory of
8the python source tree after building the interpreter and run:
9
10 python Lib/keyword.py
11"""
Guido van Rossum90d556f1997-03-20 19:44:30 +000012
Raymond Hettingeredc853e2002-10-30 05:17:22 +000013__all__ = ["iskeyword", "kwlist"]
Skip Montanaro17ab1232001-01-24 06:27:27 +000014
Guido van Rossumeb8c9721997-03-20 19:45:51 +000015kwlist = [
16#--start keywords--
17 'and',
Guido van Rossumed57d761997-07-23 18:10:52 +000018 'assert',
Guido van Rossumeb8c9721997-03-20 19:45:51 +000019 'break',
20 'class',
21 'continue',
22 'def',
23 'del',
24 'elif',
25 'else',
26 'except',
27 'exec',
28 'finally',
29 'for',
30 'from',
31 'global',
32 'if',
33 'import',
34 'in',
35 'is',
36 'lambda',
37 'not',
38 'or',
39 'pass',
40 'print',
41 'raise',
42 'return',
43 'try',
44 'while',
Tim Peters46376682001-06-19 00:26:25 +000045 'yield',
Guido van Rossumeb8c9721997-03-20 19:45:51 +000046#--end keywords--
47 ]
Guido van Rossum90d556f1997-03-20 19:44:30 +000048
Guido van Rossumeb8c9721997-03-20 19:45:51 +000049kwdict = {}
50for keyword in kwlist:
51 kwdict[keyword] = 1
Guido van Rossum90d556f1997-03-20 19:44:30 +000052
Guido van Rossumeb8c9721997-03-20 19:45:51 +000053iskeyword = kwdict.has_key
54
55def main():
Eric S. Raymondee5e61d2001-02-09 09:10:35 +000056 import sys, re
Guido van Rossumeb8c9721997-03-20 19:45:51 +000057
58 args = sys.argv[1:]
59 iptfile = args and args[0] or "Python/graminit.c"
60 if len(args) > 1: optfile = args[1]
61 else: optfile = "Lib/keyword.py"
62
63 # scan the source file for keywords
Guido van Rossum4d819841997-03-20 20:40:45 +000064 fp = open(iptfile)
Guido van Rossum9694fca1997-10-22 21:00:49 +000065 strprog = re.compile('"([^"]+)"')
Guido van Rossum4d819841997-03-20 20:40:45 +000066 lines = []
Guido van Rossumeb8c9721997-03-20 19:45:51 +000067 while 1:
68 line = fp.readline()
69 if not line: break
Eric S. Raymondee5e61d2001-02-09 09:10:35 +000070 if line.find('{1, "') > -1:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000071 match = strprog.search(line)
72 if match:
73 lines.append(" '" + match.group(1) + "',\n")
Guido van Rossumeb8c9721997-03-20 19:45:51 +000074 fp.close()
Guido van Rossum4d819841997-03-20 20:40:45 +000075 lines.sort()
Guido van Rossumeb8c9721997-03-20 19:45:51 +000076
77 # load the output skeleton from the target
Guido van Rossum4d819841997-03-20 20:40:45 +000078 fp = open(optfile)
79 format = fp.readlines()
80 fp.close()
Guido van Rossumeb8c9721997-03-20 19:45:51 +000081
Guido van Rossum4d819841997-03-20 20:40:45 +000082 # insert the lines of keywords
Guido van Rossumeb8c9721997-03-20 19:45:51 +000083 try:
84 start = format.index("#--start keywords--\n") + 1
85 end = format.index("#--end keywords--\n")
Guido van Rossum4d819841997-03-20 20:40:45 +000086 format[start:end] = lines
Guido van Rossumeb8c9721997-03-20 19:45:51 +000087 except ValueError:
88 sys.stderr.write("target does not contain format markers\n")
Guido van Rossum4d819841997-03-20 20:40:45 +000089 sys.exit(1)
Guido van Rossumeb8c9721997-03-20 19:45:51 +000090
91 # write the output file
Guido van Rossum4d819841997-03-20 20:40:45 +000092 fp = open(optfile, 'w')
Eric S. Raymondee5e61d2001-02-09 09:10:35 +000093 fp.write(''.join(format))
Guido van Rossumeb8c9721997-03-20 19:45:51 +000094 fp.close()
95
Guido van Rossum9694fca1997-10-22 21:00:49 +000096if __name__ == "__main__":
97 main()