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-- |
Guido van Rossum | 486364b | 2007-06-30 05:01:58 +0000 | [diff] [blame] | 17 | 'False', |
| 18 | 'None', |
| 19 | 'True', |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 20 | 'and', |
Thomas Wouters | 1f1c16a | 2006-02-28 22:50:17 +0000 | [diff] [blame] | 21 | 'as', |
Guido van Rossum | ed57d76 | 1997-07-23 18:10:52 +0000 | [diff] [blame] | 22 | 'assert', |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 23 | 'break', |
| 24 | 'class', |
| 25 | 'continue', |
| 26 | 'def', |
| 27 | 'del', |
| 28 | 'elif', |
| 29 | 'else', |
| 30 | 'except', |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 31 | 'finally', |
| 32 | 'for', |
| 33 | 'from', |
| 34 | 'global', |
| 35 | 'if', |
| 36 | 'import', |
| 37 | 'in', |
| 38 | 'is', |
| 39 | 'lambda', |
Jack Diederich | 4b7f317 | 2007-02-28 20:21:30 +0000 | [diff] [blame] | 40 | 'nonlocal', |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 41 | 'not', |
| 42 | 'or', |
| 43 | 'pass', |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 44 | 'raise', |
| 45 | 'return', |
| 46 | 'try', |
| 47 | 'while', |
Thomas Wouters | 1f1c16a | 2006-02-28 22:50:17 +0000 | [diff] [blame] | 48 | 'with', |
Tim Peters | 4637668 | 2001-06-19 00:26:25 +0000 | [diff] [blame] | 49 | 'yield', |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 50 | #--end keywords-- |
| 51 | ] |
Guido van Rossum | 90d556f | 1997-03-20 19:44:30 +0000 | [diff] [blame] | 52 | |
Raymond Hettinger | 70ef869 | 2003-12-02 07:48:15 +0000 | [diff] [blame] | 53 | iskeyword = frozenset(kwlist).__contains__ |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 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 |
Raymond Hettinger | bac788a | 2004-05-04 09:21:43 +0000 | [diff] [blame] | 70 | if '{1, "' in line: |
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() |