Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | #! /usr/bin/env python |
2 | ||
3 | """Keywords (from "graminit.c") | |
4 | ||
5 | This file is automatically generated; please don't muck it up! | |
6 | ||
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: | |
9 | ||
10 | python Lib/keyword.py | |
11 | """ | |
12 | ||
13 | __all__ = ["iskeyword", "kwlist"] | |
14 | ||
15 | kwlist = [ | |
16 | #--start keywords-- | |
17 | 'and', | |
18 | 'assert', | |
19 | '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', | |
45 | 'yield', | |
46 | #--end keywords-- | |
47 | ] | |
48 | ||
49 | iskeyword = frozenset(kwlist).__contains__ | |
50 | ||
51 | def main(): | |
52 | import sys, re | |
53 | ||
54 | args = sys.argv[1:] | |
55 | iptfile = args and args[0] or "Python/graminit.c" | |
56 | if len(args) > 1: optfile = args[1] | |
57 | else: optfile = "Lib/keyword.py" | |
58 | ||
59 | # scan the source file for keywords | |
60 | fp = open(iptfile) | |
61 | strprog = re.compile('"([^"]+)"') | |
62 | lines = [] | |
63 | while 1: | |
64 | line = fp.readline() | |
65 | if not line: break | |
66 | if '{1, "' in line: | |
67 | match = strprog.search(line) | |
68 | if match: | |
69 | lines.append(" '" + match.group(1) + "',\n") | |
70 | fp.close() | |
71 | lines.sort() | |
72 | ||
73 | # load the output skeleton from the target | |
74 | fp = open(optfile) | |
75 | format = fp.readlines() | |
76 | fp.close() | |
77 | ||
78 | # insert the lines of keywords | |
79 | try: | |
80 | start = format.index("#--start keywords--\n") + 1 | |
81 | end = format.index("#--end keywords--\n") | |
82 | format[start:end] = lines | |
83 | except ValueError: | |
84 | sys.stderr.write("target does not contain format markers\n") | |
85 | sys.exit(1) | |
86 | ||
87 | # write the output file | |
88 | fp = open(optfile, 'w') | |
89 | fp.write(''.join(format)) | |
90 | fp.close() | |
91 | ||
92 | if __name__ == "__main__": | |
93 | main() |