blob: dad39cc377963f3ab4de706c2b1bb8d579425291 [file] [log] [blame]
Benjamin Peterson90f5ba52010-03-11 22:53:45 +00001#! /usr/bin/env python3
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
Éric Araujoe1886bf2011-11-29 16:45:34 +010010 ./python Lib/keyword.py
Guido van Rossum54f22ed2000-02-04 15:10:34 +000011"""
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--
Guido van Rossum486364b2007-06-30 05:01:58 +000017 'False',
18 'None',
19 'True',
Guido van Rossumeb8c9721997-03-20 19:45:51 +000020 'and',
Thomas Wouters1f1c16a2006-02-28 22:50:17 +000021 'as',
Guido van Rossumed57d761997-07-23 18:10:52 +000022 'assert',
Guido van Rossumeb8c9721997-03-20 19:45:51 +000023 'break',
24 'class',
25 'continue',
26 'def',
27 'del',
28 'elif',
29 'else',
30 'except',
Guido van Rossumeb8c9721997-03-20 19:45:51 +000031 'finally',
32 'for',
33 'from',
34 'global',
35 'if',
36 'import',
37 'in',
38 'is',
39 'lambda',
Jack Diederich4b7f3172007-02-28 20:21:30 +000040 'nonlocal',
Guido van Rossumeb8c9721997-03-20 19:45:51 +000041 'not',
42 'or',
43 'pass',
Guido van Rossumeb8c9721997-03-20 19:45:51 +000044 'raise',
45 'return',
46 'try',
47 'while',
Thomas Wouters1f1c16a2006-02-28 22:50:17 +000048 'with',
Tim Peters46376682001-06-19 00:26:25 +000049 'yield',
Guido van Rossumeb8c9721997-03-20 19:45:51 +000050#--end keywords--
51 ]
Guido van Rossum90d556f1997-03-20 19:44:30 +000052
Raymond Hettinger70ef8692003-12-02 07:48:15 +000053iskeyword = frozenset(kwlist).__contains__
Guido van Rossumeb8c9721997-03-20 19:45:51 +000054
55def main():
Eric S. Raymondee5e61d2001-02-09 09:10:35 +000056 import sys, re
Guido van Rossumeb8c9721997-03-20 19:45:51 +000057
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 # scan the source file for keywords
Florent Xicluna7dde7922010-09-03 19:52:03 +000064 with open(iptfile) as fp:
65 strprog = re.compile('"([^"]+)"')
66 lines = []
67 for line in fp:
68 if '{1, "' in line:
69 match = strprog.search(line)
70 if match:
71 lines.append(" '" + match.group(1) + "',\n")
Guido van Rossum4d819841997-03-20 20:40:45 +000072 lines.sort()
Guido van Rossumeb8c9721997-03-20 19:45:51 +000073
74 # load the output skeleton from the target
Florent Xicluna7dde7922010-09-03 19:52:03 +000075 with open(optfile) as fp:
76 format = fp.readlines()
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()