blob: 3cf8a2e7af9a38175c58f7c505ba94a95d7b29ff [file] [log] [blame]
Guido van Rossumeb8c9721997-03-20 19:45:51 +00001#! /usr/bin/env python
2#
3# Keywords (from "graminit.c")
4#
5# This file is automatically generated; please don't muck it up!
6#
7# To update the symbols in this file, 'cd' to the top directory of
8# the python source tree after building the interpreter and run:
9#
Guido van Rossum9694fca1997-10-22 21:00:49 +000010# python Lib/keyword.py
Guido van Rossum90d556f1997-03-20 19:44:30 +000011
Guido van Rossumeb8c9721997-03-20 19:45:51 +000012kwlist = [
13#--start keywords--
14 'and',
Guido van Rossumed57d761997-07-23 18:10:52 +000015 'assert',
Guido van Rossumeb8c9721997-03-20 19:45:51 +000016 'break',
17 'class',
18 'continue',
19 'def',
20 'del',
21 'elif',
22 'else',
23 'except',
24 'exec',
25 'finally',
26 'for',
27 'from',
28 'global',
29 'if',
30 'import',
31 'in',
32 'is',
33 'lambda',
34 'not',
35 'or',
36 'pass',
37 'print',
38 'raise',
39 'return',
40 'try',
41 'while',
42#--end keywords--
43 ]
Guido van Rossum90d556f1997-03-20 19:44:30 +000044
Guido van Rossumeb8c9721997-03-20 19:45:51 +000045kwdict = {}
46for keyword in kwlist:
47 kwdict[keyword] = 1
Guido van Rossum90d556f1997-03-20 19:44:30 +000048
Guido van Rossumeb8c9721997-03-20 19:45:51 +000049iskeyword = kwdict.has_key
50
51def main():
Guido van Rossum9694fca1997-10-22 21:00:49 +000052 import sys, re, string
Guido van Rossumeb8c9721997-03-20 19:45:51 +000053
54 args = sys.argv[1:]
55 iptfile = args and args[0] or "Python/graminit.c"
56 if len(args) > 1: optfile = args[1]
57 else: optfile = "Lib/keyword.py"
58
59 # scan the source file for keywords
Guido van Rossum4d819841997-03-20 20:40:45 +000060 fp = open(iptfile)
Guido van Rossum9694fca1997-10-22 21:00:49 +000061 strprog = re.compile('"([^"]+)"')
Guido van Rossum4d819841997-03-20 20:40:45 +000062 lines = []
Guido van Rossumeb8c9721997-03-20 19:45:51 +000063 while 1:
64 line = fp.readline()
65 if not line: break
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000066 if string.find(line, '{1, "') > -1:
67 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')
Guido van Rossumeb8c9721997-03-20 19:45:51 +000089 fp.write(string.join(format, ''))
90 fp.close()
91
Guido van Rossum9694fca1997-10-22 21:00:49 +000092if __name__ == "__main__":
93 main()