blob: 431991dcf4ace65b4818822d476ba963a7ba9586 [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',
Jelle Zijlstraac317702017-10-05 20:24:46 -070023 'async',
24 'await',
Guido van Rossumeb8c9721997-03-20 19:45:51 +000025 'break',
26 'class',
27 'continue',
28 'def',
29 'del',
30 'elif',
31 'else',
32 'except',
Guido van Rossumeb8c9721997-03-20 19:45:51 +000033 'finally',
34 'for',
35 'from',
36 'global',
37 'if',
38 'import',
39 'in',
40 'is',
41 'lambda',
Jack Diederich4b7f3172007-02-28 20:21:30 +000042 'nonlocal',
Guido van Rossumeb8c9721997-03-20 19:45:51 +000043 'not',
44 'or',
45 'pass',
Guido van Rossumeb8c9721997-03-20 19:45:51 +000046 'raise',
47 'return',
48 'try',
49 'while',
Thomas Wouters1f1c16a2006-02-28 22:50:17 +000050 'with',
Tim Peters46376682001-06-19 00:26:25 +000051 'yield',
Guido van Rossumeb8c9721997-03-20 19:45:51 +000052#--end keywords--
53 ]
Guido van Rossum90d556f1997-03-20 19:44:30 +000054
Raymond Hettinger70ef8692003-12-02 07:48:15 +000055iskeyword = frozenset(kwlist).__contains__
Guido van Rossumeb8c9721997-03-20 19:45:51 +000056
57def main():
Eric S. Raymondee5e61d2001-02-09 09:10:35 +000058 import sys, re
Guido van Rossumeb8c9721997-03-20 19:45:51 +000059
60 args = sys.argv[1:]
61 iptfile = args and args[0] or "Python/graminit.c"
62 if len(args) > 1: optfile = args[1]
63 else: optfile = "Lib/keyword.py"
64
R David Murrayf0f7cea2013-04-25 12:01:36 -040065 # load the output skeleton from the target, taking care to preserve its
66 # newline convention.
67 with open(optfile, newline='') as fp:
68 format = fp.readlines()
69 nl = format[0][len(format[0].strip()):] if format else '\n'
70
Guido van Rossumeb8c9721997-03-20 19:45:51 +000071 # scan the source file for keywords
Florent Xicluna7dde7922010-09-03 19:52:03 +000072 with open(iptfile) as fp:
73 strprog = re.compile('"([^"]+)"')
74 lines = []
75 for line in fp:
76 if '{1, "' in line:
77 match = strprog.search(line)
78 if match:
R David Murrayf0f7cea2013-04-25 12:01:36 -040079 lines.append(" '" + match.group(1) + "'," + nl)
Guido van Rossum4d819841997-03-20 20:40:45 +000080 lines.sort()
Guido van Rossumeb8c9721997-03-20 19:45:51 +000081
R David Murrayf0f7cea2013-04-25 12:01:36 -040082 # insert the lines of keywords into the skeleton
Guido van Rossumeb8c9721997-03-20 19:45:51 +000083 try:
R David Murrayf0f7cea2013-04-25 12:01:36 -040084 start = format.index("#--start keywords--" + nl) + 1
85 end = format.index("#--end keywords--" + nl)
Guido van Rossum4d819841997-03-20 20:40:45 +000086 format[start:end] = lines
Guido van Rossumeb8c9721997-03-20 19:45:51 +000087 except ValueError:
88 sys.stderr.write("target does not contain format markers\n")
Guido van Rossum4d819841997-03-20 20:40:45 +000089 sys.exit(1)
Guido van Rossumeb8c9721997-03-20 19:45:51 +000090
91 # write the output file
R David Murrayf0f7cea2013-04-25 12:01:36 -040092 with open(optfile, 'w', newline='') as fp:
93 fp.writelines(format)
Guido van Rossumeb8c9721997-03-20 19:45:51 +000094
Guido van Rossum9694fca1997-10-22 21:00:49 +000095if __name__ == "__main__":
96 main()