]> git.lizzy.rs Git - plan9front.git/blob - sys/lib/python/keyword.py
dist/mkfile: run binds in subshell
[plan9front.git] / sys / lib / python / keyword.py
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         'as',
19         'assert',
20         'break',
21         'class',
22         'continue',
23         'def',
24         'del',
25         'elif',
26         'else',
27         'except',
28         'exec',
29         'finally',
30         'for',
31         'from',
32         'global',
33         'if',
34         'import',
35         'in',
36         'is',
37         'lambda',
38         'not',
39         'or',
40         'pass',
41         'print',
42         'raise',
43         'return',
44         'try',
45         'while',
46         'with',
47         'yield',
48 #--end keywords--
49         ]
50
51 iskeyword = frozenset(kwlist).__contains__
52
53 def main():
54     import sys, re
55
56     args = sys.argv[1:]
57     iptfile = args and args[0] or "Python/graminit.c"
58     if len(args) > 1: optfile = args[1]
59     else: optfile = "Lib/keyword.py"
60
61     # scan the source file for keywords
62     fp = open(iptfile)
63     strprog = re.compile('"([^"]+)"')
64     lines = []
65     while 1:
66         line = fp.readline()
67         if not line: break
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()
74
75     # load the output skeleton from the target
76     fp = open(optfile)
77     format = fp.readlines()
78     fp.close()
79
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)
88
89     # write the output file
90     fp = open(optfile, 'w')
91     fp.write(''.join(format))
92     fp.close()
93
94 if __name__ == "__main__":
95     main()