1#! /usr/bin/env python3 2 3"""Keywords (from "graminit.c") 4 5This file is automatically generated; please don't muck it up! 6 7To update the symbols in this file, 'cd' to the top directory of 8the python source tree after building the interpreter and run: 9 10 ./python Lib/keyword.py 11""" 12 13__all__ = ["iskeyword", "kwlist"] 14 15kwlist = [ 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-- 51 ] 52 53iskeyword = frozenset(kwlist).__contains__ 54 55def main(): 56 import sys, re 57 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" 62 63 # load the output skeleton from the target, taking care to preserve its 64 # newline convention. 65 with open(optfile, newline='') as fp: 66 format = fp.readlines() 67 nl = format[0][len(format[0].strip()):] if format else '\n' 68 69 # scan the source file for keywords 70 with open(iptfile) as fp: 71 strprog = re.compile('"([^"]+)"') 72 lines = [] 73 for line in fp: 74 if '{1, "' in line: 75 match = strprog.search(line) 76 if match: 77 lines.append(" '" + match.group(1) + "'," + nl) 78 lines.sort() 79 80 # insert the lines of keywords into the skeleton 81 try: 82 start = format.index("#--start keywords--" + nl) + 1 83 end = format.index("#--end keywords--" + nl) 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 with open(optfile, 'w', newline='') as fp: 91 fp.writelines(format) 92 93if __name__ == "__main__": 94 main() 95