Merged revisions 81181 via svnmerge from
[python/dscho.git] / Lib / keyword.py
bloba7abe2b4197f4935669a44c375383df2a78c72f0
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 __all__ = ["iskeyword", "kwlist"]
15 kwlist = [
16 #--start keywords--
17 'False',
18 'None',
19 'True',
20 'and',
21 'as',
22 'assert',
23 'break',
24 'class',
25 'continue',
26 'def',
27 'del',
28 'elif',
29 'else',
30 'except',
31 'finally',
32 'for',
33 'from',
34 'global',
35 'if',
36 'import',
37 'in',
38 'is',
39 'lambda',
40 'nonlocal',
41 'not',
42 'or',
43 'pass',
44 'raise',
45 'return',
46 'try',
47 'while',
48 'with',
49 'yield',
50 #--end keywords--
53 iskeyword = frozenset(kwlist).__contains__
55 def main():
56 import sys, re
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"
63 # scan the source file for keywords
64 fp = open(iptfile)
65 strprog = re.compile('"([^"]+)"')
66 lines = []
67 for line in fp:
68 if '{1, "' in line:
69 match = strprog.search(line)
70 if match:
71 lines.append(" '" + match.group(1) + "',\n")
72 fp.close()
73 lines.sort()
75 # load the output skeleton from the target
76 fp = open(optfile)
77 format = fp.readlines()
78 fp.close()
80 # insert the lines of keywords
81 try:
82 start = format.index("#--start keywords--\n") + 1
83 end = format.index("#--end keywords--\n")
84 format[start:end] = lines
85 except ValueError:
86 sys.stderr.write("target does not contain format markers\n")
87 sys.exit(1)
89 # write the output file
90 fp = open(optfile, 'w')
91 fp.write(''.join(format))
92 fp.close()
94 if __name__ == "__main__":
95 main()