1 | n/a | #! /usr/bin/env python3 |
---|
2 | n/a | |
---|
3 | n/a | """Keywords (from "graminit.c") |
---|
4 | n/a | |
---|
5 | n/a | This file is automatically generated; please don't muck it up! |
---|
6 | n/a | |
---|
7 | n/a | To update the symbols in this file, 'cd' to the top directory of |
---|
8 | n/a | the python source tree after building the interpreter and run: |
---|
9 | n/a | |
---|
10 | n/a | ./python Lib/keyword.py |
---|
11 | n/a | """ |
---|
12 | n/a | |
---|
13 | n/a | __all__ = ["iskeyword", "kwlist"] |
---|
14 | n/a | |
---|
15 | n/a | kwlist = [ |
---|
16 | n/a | #--start keywords-- |
---|
17 | n/a | 'False', |
---|
18 | n/a | 'None', |
---|
19 | n/a | 'True', |
---|
20 | n/a | 'and', |
---|
21 | n/a | 'as', |
---|
22 | n/a | 'assert', |
---|
23 | n/a | 'break', |
---|
24 | n/a | 'class', |
---|
25 | n/a | 'continue', |
---|
26 | n/a | 'def', |
---|
27 | n/a | 'del', |
---|
28 | n/a | 'elif', |
---|
29 | n/a | 'else', |
---|
30 | n/a | 'except', |
---|
31 | n/a | 'finally', |
---|
32 | n/a | 'for', |
---|
33 | n/a | 'from', |
---|
34 | n/a | 'global', |
---|
35 | n/a | 'if', |
---|
36 | n/a | 'import', |
---|
37 | n/a | 'in', |
---|
38 | n/a | 'is', |
---|
39 | n/a | 'lambda', |
---|
40 | n/a | 'nonlocal', |
---|
41 | n/a | 'not', |
---|
42 | n/a | 'or', |
---|
43 | n/a | 'pass', |
---|
44 | n/a | 'raise', |
---|
45 | n/a | 'return', |
---|
46 | n/a | 'try', |
---|
47 | n/a | 'while', |
---|
48 | n/a | 'with', |
---|
49 | n/a | 'yield', |
---|
50 | n/a | #--end keywords-- |
---|
51 | n/a | ] |
---|
52 | n/a | |
---|
53 | n/a | iskeyword = frozenset(kwlist).__contains__ |
---|
54 | n/a | |
---|
55 | n/a | def main(): |
---|
56 | n/a | import sys, re |
---|
57 | n/a | |
---|
58 | n/a | args = sys.argv[1:] |
---|
59 | n/a | iptfile = args and args[0] or "Python/graminit.c" |
---|
60 | n/a | if len(args) > 1: optfile = args[1] |
---|
61 | n/a | else: optfile = "Lib/keyword.py" |
---|
62 | n/a | |
---|
63 | n/a | # load the output skeleton from the target, taking care to preserve its |
---|
64 | n/a | # newline convention. |
---|
65 | n/a | with open(optfile, newline='') as fp: |
---|
66 | n/a | format = fp.readlines() |
---|
67 | n/a | nl = format[0][len(format[0].strip()):] if format else '\n' |
---|
68 | n/a | |
---|
69 | n/a | # scan the source file for keywords |
---|
70 | n/a | with open(iptfile) as fp: |
---|
71 | n/a | strprog = re.compile('"([^"]+)"') |
---|
72 | n/a | lines = [] |
---|
73 | n/a | for line in fp: |
---|
74 | n/a | if '{1, "' in line: |
---|
75 | n/a | match = strprog.search(line) |
---|
76 | n/a | if match: |
---|
77 | n/a | lines.append(" '" + match.group(1) + "'," + nl) |
---|
78 | n/a | lines.sort() |
---|
79 | n/a | |
---|
80 | n/a | # insert the lines of keywords into the skeleton |
---|
81 | n/a | try: |
---|
82 | n/a | start = format.index("#--start keywords--" + nl) + 1 |
---|
83 | n/a | end = format.index("#--end keywords--" + nl) |
---|
84 | n/a | format[start:end] = lines |
---|
85 | n/a | except ValueError: |
---|
86 | n/a | sys.stderr.write("target does not contain format markers\n") |
---|
87 | n/a | sys.exit(1) |
---|
88 | n/a | |
---|
89 | n/a | # write the output file |
---|
90 | n/a | with open(optfile, 'w', newline='') as fp: |
---|
91 | n/a | fp.writelines(format) |
---|
92 | n/a | |
---|
93 | n/a | if __name__ == "__main__": |
---|
94 | n/a | main() |
---|