annotate Lib/keyword.py @ 5817:48b94de85bf3 legacy-trunk

Extensive changes by AMK.
author Guido van Rossum <guido@python.org>
date Thu, 17 Jul 1997 16:29:42 +0000
parents bd5e2c2c1e08
children 46cd352c7638
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5204
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
1 #! /usr/bin/env python
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
2 #
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
3 # Keywords (from "graminit.c")
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
4 #
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
5 # This file is automatically generated; please don't muck it up!
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
6 #
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
7 # To update the symbols in this file, 'cd' to the top directory of
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
8 # the python source tree after building the interpreter and run:
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
9 #
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
10 # PYTHONPATH=./Lib ./python Lib/keyword.py
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
11 #
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
12 # (this path allows the import of string.py and regexmodule.so
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
13 # for a site with no installation in place)
5203
05c7d8b4ffd6 Simple module to publish list of Python keywords.
Guido van Rossum <guido@python.org>
parents:
diff changeset
14
5204
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
15 kwlist = [
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
16 #--start keywords--
5205
b39203983de6 Added __assert__.
Guido van Rossum <guido@python.org>
parents: 5204
diff changeset
17 '__assert__',
5204
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
18 'and',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
19 'break',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
20 'class',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
21 'continue',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
22 'def',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
23 'del',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
24 'elif',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
25 'else',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
26 'except',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
27 'exec',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
28 'finally',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
29 'for',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
30 'from',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
31 'global',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
32 'if',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
33 'import',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
34 'in',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
35 'is',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
36 'lambda',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
37 'not',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
38 'or',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
39 'pass',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
40 'print',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
41 'raise',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
42 'return',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
43 'try',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
44 'while',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
45 #--end keywords--
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
46 ]
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
47
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
48 kwdict = {}
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
49 for keyword in kwlist:
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
50 kwdict[keyword] = 1
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
51
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
52 iskeyword = kwdict.has_key
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
53
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
54 def main():
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
55 import sys, regex, string
5203
05c7d8b4ffd6 Simple module to publish list of Python keywords.
Guido van Rossum <guido@python.org>
parents:
diff changeset
56
5204
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
57 args = sys.argv[1:]
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
58 iptfile = args and args[0] or "Python/graminit.c"
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
59 if len(args) > 1: optfile = args[1]
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
60 else: optfile = "Lib/keyword.py"
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
61
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
62 # scan the source file for keywords
5206
bd5e2c2c1e08 Ping's new version -- more efficient at finding the keywords.
Guido van Rossum <guido@python.org>
parents: 5205
diff changeset
63 fp = open(iptfile)
5204
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
64 strprog = regex.compile('"\([^"]+\)"')
5206
bd5e2c2c1e08 Ping's new version -- more efficient at finding the keywords.
Guido van Rossum <guido@python.org>
parents: 5205
diff changeset
65 lines = []
5204
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
66 while 1:
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
67 line = fp.readline()
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
68 if not line: break
5206
bd5e2c2c1e08 Ping's new version -- more efficient at finding the keywords.
Guido van Rossum <guido@python.org>
parents: 5205
diff changeset
69 if string.find(line, '{1, "') > -1 and strprog.search(line) > -1:
bd5e2c2c1e08 Ping's new version -- more efficient at finding the keywords.
Guido van Rossum <guido@python.org>
parents: 5205
diff changeset
70 lines.append(" '" + strprog.group(1) + "',\n")
bd5e2c2c1e08 Ping's new version -- more efficient at finding the keywords.
Guido van Rossum <guido@python.org>
parents: 5205
diff changeset
71 fp.close()
bd5e2c2c1e08 Ping's new version -- more efficient at finding the keywords.
Guido van Rossum <guido@python.org>
parents: 5205
diff changeset
72 lines.sort()
bd5e2c2c1e08 Ping's new version -- more efficient at finding the keywords.
Guido van Rossum <guido@python.org>
parents: 5205
diff changeset
73
bd5e2c2c1e08 Ping's new version -- more efficient at finding the keywords.
Guido van Rossum <guido@python.org>
parents: 5205
diff changeset
74 # load the output skeleton from the target
bd5e2c2c1e08 Ping's new version -- more efficient at finding the keywords.
Guido van Rossum <guido@python.org>
parents: 5205
diff changeset
75 fp = open(optfile)
bd5e2c2c1e08 Ping's new version -- more efficient at finding the keywords.
Guido van Rossum <guido@python.org>
parents: 5205
diff changeset
76 format = fp.readlines()
5204
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
77 fp.close()
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
78
5206
bd5e2c2c1e08 Ping's new version -- more efficient at finding the keywords.
Guido van Rossum <guido@python.org>
parents: 5205
diff changeset
79 # insert the lines of keywords
5204
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
80 try:
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
81 start = format.index("#--start keywords--\n") + 1
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
82 end = format.index("#--end keywords--\n")
5206
bd5e2c2c1e08 Ping's new version -- more efficient at finding the keywords.
Guido van Rossum <guido@python.org>
parents: 5205
diff changeset
83 format[start:end] = lines
5204
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
84 except ValueError:
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
85 sys.stderr.write("target does not contain format markers\n")
5206
bd5e2c2c1e08 Ping's new version -- more efficient at finding the keywords.
Guido van Rossum <guido@python.org>
parents: 5205
diff changeset
86 sys.exit(1)
5204
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
87
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
88 # write the output file
5206
bd5e2c2c1e08 Ping's new version -- more efficient at finding the keywords.
Guido van Rossum <guido@python.org>
parents: 5205
diff changeset
89 fp = open(optfile, 'w')
5204
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
90 fp.write(string.join(format, ''))
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
91 fp.close()
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
92
5206
bd5e2c2c1e08 Ping's new version -- more efficient at finding the keywords.
Guido van Rossum <guido@python.org>
parents: 5205
diff changeset
93 if __name__ == "__main__": main()