Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 1 | #! /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 Rossum | 9694fca | 1997-10-22 21:00:49 +0000 | [diff] [blame] | 10 | # python Lib/keyword.py |
Guido van Rossum | 90d556f | 1997-03-20 19:44:30 +0000 | [diff] [blame] | 11 | |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 12 | kwlist = [ |
| 13 | #--start keywords-- |
| 14 | 'and', |
Guido van Rossum | ed57d76 | 1997-07-23 18:10:52 +0000 | [diff] [blame] | 15 | 'assert', |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 16 | '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 Rossum | 90d556f | 1997-03-20 19:44:30 +0000 | [diff] [blame] | 44 | |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 45 | kwdict = {} |
| 46 | for keyword in kwlist: |
| 47 | kwdict[keyword] = 1 |
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 | iskeyword = kwdict.has_key |
| 50 | |
| 51 | def main(): |
Guido van Rossum | 9694fca | 1997-10-22 21:00:49 +0000 | [diff] [blame] | 52 | import sys, re, string |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 53 | |
| 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 Rossum | 4d81984 | 1997-03-20 20:40:45 +0000 | [diff] [blame] | 60 | fp = open(iptfile) |
Guido van Rossum | 9694fca | 1997-10-22 21:00:49 +0000 | [diff] [blame] | 61 | strprog = re.compile('"([^"]+)"') |
Guido van Rossum | 4d81984 | 1997-03-20 20:40:45 +0000 | [diff] [blame] | 62 | lines = [] |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 63 | while 1: |
| 64 | line = fp.readline() |
| 65 | if not line: break |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 66 | if string.find(line, '{1, "') > -1: |
| 67 | match = strprog.search(line) |
| 68 | if match: |
| 69 | lines.append(" '" + match.group(1) + "',\n") |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 70 | fp.close() |
Guido van Rossum | 4d81984 | 1997-03-20 20:40:45 +0000 | [diff] [blame] | 71 | lines.sort() |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 72 | |
| 73 | # load the output skeleton from the target |
Guido van Rossum | 4d81984 | 1997-03-20 20:40:45 +0000 | [diff] [blame] | 74 | fp = open(optfile) |
| 75 | format = fp.readlines() |
| 76 | fp.close() |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 77 | |
Guido van Rossum | 4d81984 | 1997-03-20 20:40:45 +0000 | [diff] [blame] | 78 | # insert the lines of keywords |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 79 | try: |
| 80 | start = format.index("#--start keywords--\n") + 1 |
| 81 | end = format.index("#--end keywords--\n") |
Guido van Rossum | 4d81984 | 1997-03-20 20:40:45 +0000 | [diff] [blame] | 82 | format[start:end] = lines |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 83 | except ValueError: |
| 84 | sys.stderr.write("target does not contain format markers\n") |
Guido van Rossum | 4d81984 | 1997-03-20 20:40:45 +0000 | [diff] [blame] | 85 | sys.exit(1) |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 86 | |
| 87 | # write the output file |
Guido van Rossum | 4d81984 | 1997-03-20 20:40:45 +0000 | [diff] [blame] | 88 | fp = open(optfile, 'w') |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 89 | fp.write(string.join(format, '')) |
| 90 | fp.close() |
| 91 | |
Guido van Rossum | 9694fca | 1997-10-22 21:00:49 +0000 | [diff] [blame] | 92 | if __name__ == "__main__": |
| 93 | main() |