Quick update to the README file. For intros and books we now point to
[python/dscho.git] / Lib / keyword.py
blob0c3dec2acafaebd0dbbfdd2ca9252c8b9a3636c3
1 #! /usr/bin/env python
3 """Keywords (from "graminit.c")
5 This file is automatically generated; please don't muck it up!
7 To update the symbols in this file, 'cd' to the top directory of
8 the python source tree after building the interpreter and run:
10 python Lib/keyword.py
11 """
13 kwlist = [
14 #--start keywords--
15 'and',
16 'assert',
17 'break',
18 'class',
19 'continue',
20 'def',
21 'del',
22 'elif',
23 'else',
24 'except',
25 'exec',
26 'finally',
27 'for',
28 'from',
29 'global',
30 'if',
31 'import',
32 'in',
33 'is',
34 'lambda',
35 'not',
36 'or',
37 'pass',
38 'print',
39 'raise',
40 'return',
41 'try',
42 'while',
43 #--end keywords--
46 kwdict = {}
47 for keyword in kwlist:
48 kwdict[keyword] = 1
50 iskeyword = kwdict.has_key
52 def main():
53 import sys, re, string
55 args = sys.argv[1:]
56 iptfile = args and args[0] or "Python/graminit.c"
57 if len(args) > 1: optfile = args[1]
58 else: optfile = "Lib/keyword.py"
60 # scan the source file for keywords
61 fp = open(iptfile)
62 strprog = re.compile('"([^"]+)"')
63 lines = []
64 while 1:
65 line = fp.readline()
66 if not line: break
67 if string.find(line, '{1, "') > -1:
68 match = strprog.search(line)
69 if match:
70 lines.append(" '" + match.group(1) + "',\n")
71 fp.close()
72 lines.sort()
74 # load the output skeleton from the target
75 fp = open(optfile)
76 format = fp.readlines()
77 fp.close()
79 # insert the lines of keywords
80 try:
81 start = format.index("#--start keywords--\n") + 1
82 end = format.index("#--end keywords--\n")
83 format[start:end] = lines
84 except ValueError:
85 sys.stderr.write("target does not contain format markers\n")
86 sys.exit(1)
88 # write the output file
89 fp = open(optfile, 'w')
90 fp.write(string.join(format, ''))
91 fp.close()
93 if __name__ == "__main__":
94 main()