blob: 150c2bc46d229c6340a1bdf0f9ea513a7353e197 [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
Guido van Rossum495da292019-03-07 12:38:08 -080053kwlist.append('async')
54kwlist.append('await')
55kwlist.sort()
56
Raymond Hettinger70ef8692003-12-02 07:48:15 +000057iskeyword = frozenset(kwlist).__contains__
Guido van Rossumeb8c9721997-03-20 19:45:51 +000058
59def main():
Eric S. Raymondee5e61d2001-02-09 09:10:35 +000060 import sys, re
Guido van Rossumeb8c9721997-03-20 19:45:51 +000061
62 args = sys.argv[1:]
63 iptfile = args and args[0] or "Python/graminit.c"
64 if len(args) > 1: optfile = args[1]
65 else: optfile = "Lib/keyword.py"
66
R David Murrayf0f7cea2013-04-25 12:01:36 -040067 # load the output skeleton from the target, taking care to preserve its
68 # newline convention.
69 with open(optfile, newline='') as fp:
70 format = fp.readlines()
71 nl = format[0][len(format[0].strip()):] if format else '\n'
72
Guido van Rossumeb8c9721997-03-20 19:45:51 +000073 # scan the source file for keywords
Florent Xicluna7dde7922010-09-03 19:52:03 +000074 with open(iptfile) as fp:
75 strprog = re.compile('"([^"]+)"')
76 lines = []
77 for line in fp:
78 if '{1, "' in line:
79 match = strprog.search(line)
80 if match:
R David Murrayf0f7cea2013-04-25 12:01:36 -040081 lines.append(" '" + match.group(1) + "'," + nl)
Guido van Rossum4d819841997-03-20 20:40:45 +000082 lines.sort()
Guido van Rossumeb8c9721997-03-20 19:45:51 +000083
R David Murrayf0f7cea2013-04-25 12:01:36 -040084 # insert the lines of keywords into the skeleton
Guido van Rossumeb8c9721997-03-20 19:45:51 +000085 try:
R David Murrayf0f7cea2013-04-25 12:01:36 -040086 start = format.index("#--start keywords--" + nl) + 1
87 end = format.index("#--end keywords--" + nl)
Guido van Rossum4d819841997-03-20 20:40:45 +000088 format[start:end] = lines
Guido van Rossumeb8c9721997-03-20 19:45:51 +000089 except ValueError:
90 sys.stderr.write("target does not contain format markers\n")
Guido van Rossum4d819841997-03-20 20:40:45 +000091 sys.exit(1)
Guido van Rossumeb8c9721997-03-20 19:45:51 +000092
93 # write the output file
R David Murrayf0f7cea2013-04-25 12:01:36 -040094 with open(optfile, 'w', newline='') as fp:
95 fp.writelines(format)
Guido van Rossumeb8c9721997-03-20 19:45:51 +000096
Guido van Rossum9694fca1997-10-22 21:00:49 +000097if __name__ == "__main__":
98 main()