Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
Guido van Rossum | 54f22ed | 2000-02-04 15:10:34 +0000 | [diff] [blame] | 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 | |
| 10 | python Lib/keyword.py |
| 11 | """ |
Guido van Rossum | 90d556f | 1997-03-20 19:44:30 +0000 | [diff] [blame] | 12 | |
Raymond Hettinger | edc853e | 2002-10-30 05:17:22 +0000 | [diff] [blame] | 13 | __all__ = ["iskeyword", "kwlist"] |
Skip Montanaro | 17ab123 | 2001-01-24 06:27:27 +0000 | [diff] [blame] | 14 | |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 15 | kwlist = [ |
| 16 | #--start keywords-- |
| 17 | 'and', |
Guido van Rossum | ed57d76 | 1997-07-23 18:10:52 +0000 | [diff] [blame] | 18 | 'assert', |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 19 | 'break', |
| 20 | 'class', |
| 21 | 'continue', |
| 22 | 'def', |
| 23 | 'del', |
| 24 | 'elif', |
| 25 | 'else', |
| 26 | 'except', |
| 27 | 'exec', |
| 28 | 'finally', |
| 29 | 'for', |
| 30 | 'from', |
| 31 | 'global', |
| 32 | 'if', |
| 33 | 'import', |
| 34 | 'in', |
| 35 | 'is', |
| 36 | 'lambda', |
| 37 | 'not', |
| 38 | 'or', |
| 39 | 'pass', |
| 40 | 'print', |
| 41 | 'raise', |
| 42 | 'return', |
| 43 | 'try', |
| 44 | 'while', |
Tim Peters | 4637668 | 2001-06-19 00:26:25 +0000 | [diff] [blame] | 45 | 'yield', |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 46 | #--end keywords-- |
| 47 | ] |
Guido van Rossum | 90d556f | 1997-03-20 19:44:30 +0000 | [diff] [blame] | 48 | |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 49 | kwdict = {} |
| 50 | for keyword in kwlist: |
| 51 | kwdict[keyword] = 1 |
Guido van Rossum | 90d556f | 1997-03-20 19:44:30 +0000 | [diff] [blame] | 52 | |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 53 | iskeyword = kwdict.has_key |
| 54 | |
| 55 | def main(): |
Eric S. Raymond | ee5e61d | 2001-02-09 09:10:35 +0000 | [diff] [blame] | 56 | import sys, re |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 57 | |
| 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 |
Guido van Rossum | 4d81984 | 1997-03-20 20:40:45 +0000 | [diff] [blame] | 64 | fp = open(iptfile) |
Guido van Rossum | 9694fca | 1997-10-22 21:00:49 +0000 | [diff] [blame] | 65 | strprog = re.compile('"([^"]+)"') |
Guido van Rossum | 4d81984 | 1997-03-20 20:40:45 +0000 | [diff] [blame] | 66 | lines = [] |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 67 | while 1: |
| 68 | line = fp.readline() |
| 69 | if not line: break |
Eric S. Raymond | ee5e61d | 2001-02-09 09:10:35 +0000 | [diff] [blame] | 70 | if line.find('{1, "') > -1: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 71 | match = strprog.search(line) |
| 72 | if match: |
| 73 | lines.append(" '" + match.group(1) + "',\n") |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 74 | fp.close() |
Guido van Rossum | 4d81984 | 1997-03-20 20:40:45 +0000 | [diff] [blame] | 75 | lines.sort() |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 76 | |
| 77 | # load the output skeleton from the target |
Guido van Rossum | 4d81984 | 1997-03-20 20:40:45 +0000 | [diff] [blame] | 78 | fp = open(optfile) |
| 79 | format = fp.readlines() |
| 80 | fp.close() |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 81 | |
Guido van Rossum | 4d81984 | 1997-03-20 20:40:45 +0000 | [diff] [blame] | 82 | # insert the lines of keywords |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 83 | try: |
| 84 | start = format.index("#--start keywords--\n") + 1 |
| 85 | end = format.index("#--end keywords--\n") |
Guido van Rossum | 4d81984 | 1997-03-20 20:40:45 +0000 | [diff] [blame] | 86 | format[start:end] = lines |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 87 | except ValueError: |
| 88 | sys.stderr.write("target does not contain format markers\n") |
Guido van Rossum | 4d81984 | 1997-03-20 20:40:45 +0000 | [diff] [blame] | 89 | sys.exit(1) |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 90 | |
| 91 | # write the output file |
Guido van Rossum | 4d81984 | 1997-03-20 20:40:45 +0000 | [diff] [blame] | 92 | fp = open(optfile, 'w') |
Eric S. Raymond | ee5e61d | 2001-02-09 09:10:35 +0000 | [diff] [blame] | 93 | fp.write(''.join(format)) |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 94 | fp.close() |
| 95 | |
Guido van Rossum | 9694fca | 1997-10-22 21:00:49 +0000 | [diff] [blame] | 96 | if __name__ == "__main__": |
| 97 | main() |