blob: 8eb2860307e5b4bc4bd05287fbb23ae6ca6bcb11 [file] [log] [blame]
Guido van Rossumeb8c9721997-03-20 19:45:51 +00001#! /usr/bin/env python
Guido van Rossum54f22ed2000-02-04 15:10:34 +00002
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"""
Guido van Rossum90d556f1997-03-20 19:44:30 +000012
Raymond Hettingeredc853e2002-10-30 05:17:22 +000013__all__ = ["iskeyword", "kwlist"]
Skip Montanaro17ab1232001-01-24 06:27:27 +000014
Guido van Rossumeb8c9721997-03-20 19:45:51 +000015kwlist = [
16#--start keywords--
17 'and',
Thomas Wouters1f1c16a2006-02-28 22:50:17 +000018 'as',
Guido van Rossumed57d761997-07-23 18:10:52 +000019 'assert',
Guido van Rossumeb8c9721997-03-20 19:45:51 +000020 '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',
Thomas Wouters1f1c16a2006-02-28 22:50:17 +000046 'with',
Tim Peters46376682001-06-19 00:26:25 +000047 'yield',
Guido van Rossumeb8c9721997-03-20 19:45:51 +000048#--end keywords--
49 ]
Guido van Rossum90d556f1997-03-20 19:44:30 +000050
Raymond Hettinger70ef8692003-12-02 07:48:15 +000051iskeyword = frozenset(kwlist).__contains__
Guido van Rossumeb8c9721997-03-20 19:45:51 +000052
53def main():
Eric S. Raymondee5e61d2001-02-09 09:10:35 +000054 import sys, re
Guido van Rossumeb8c9721997-03-20 19:45:51 +000055
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
Guido van Rossum4d819841997-03-20 20:40:45 +000062 fp = open(iptfile)
Guido van Rossum9694fca1997-10-22 21:00:49 +000063 strprog = re.compile('"([^"]+)"')
Guido van Rossum4d819841997-03-20 20:40:45 +000064 lines = []
Georg Brandl1ea8cb42008-01-21 17:22:06 +000065 for line in fp:
Raymond Hettingerbac788a2004-05-04 09:21:43 +000066 if '{1, "' in line:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000067 match = strprog.search(line)
68 if match:
69 lines.append(" '" + match.group(1) + "',\n")
Guido van Rossumeb8c9721997-03-20 19:45:51 +000070 fp.close()
Guido van Rossum4d819841997-03-20 20:40:45 +000071 lines.sort()
Guido van Rossumeb8c9721997-03-20 19:45:51 +000072
73 # load the output skeleton from the target
Guido van Rossum4d819841997-03-20 20:40:45 +000074 fp = open(optfile)
75 format = fp.readlines()
76 fp.close()
Guido van Rossumeb8c9721997-03-20 19:45:51 +000077
Guido van Rossum4d819841997-03-20 20:40:45 +000078 # insert the lines of keywords
Guido van Rossumeb8c9721997-03-20 19:45:51 +000079 try:
80 start = format.index("#--start keywords--\n") + 1
81 end = format.index("#--end keywords--\n")
Guido van Rossum4d819841997-03-20 20:40:45 +000082 format[start:end] = lines
Guido van Rossumeb8c9721997-03-20 19:45:51 +000083 except ValueError:
84 sys.stderr.write("target does not contain format markers\n")
Guido van Rossum4d819841997-03-20 20:40:45 +000085 sys.exit(1)
Guido van Rossumeb8c9721997-03-20 19:45:51 +000086
87 # write the output file
Guido van Rossum4d819841997-03-20 20:40:45 +000088 fp = open(optfile, 'w')
Eric S. Raymondee5e61d2001-02-09 09:10:35 +000089 fp.write(''.join(format))
Guido van Rossumeb8c9721997-03-20 19:45:51 +000090 fp.close()
91
Guido van Rossum9694fca1997-10-22 21:00:49 +000092if __name__ == "__main__":
93 main()