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', |
Thomas Wouters | 1f1c16a | 2006-02-28 22:50:17 +0000 | [diff] [blame] | 18 | 'as', |
Guido van Rossum | ed57d76 | 1997-07-23 18:10:52 +0000 | [diff] [blame] | 19 | 'assert', |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 20 | 'break', |
| 21 | 'class', |
| 22 | 'continue', |
| 23 | 'def', |
| 24 | 'del', |
| 25 | 'elif', |
| 26 | 'else', |
| 27 | 'except', |
| 28 | 'exec', |
| 29 | 'finally', |
| 30 | 'for', |
| 31 | 'from', |
| 32 | 'global', |
| 33 | 'if', |
| 34 | 'import', |
| 35 | 'in', |
| 36 | 'is', |
| 37 | 'lambda', |
| 38 | 'not', |
| 39 | 'or', |
| 40 | 'pass', |
| 41 | 'print', |
| 42 | 'raise', |
| 43 | 'return', |
| 44 | 'try', |
| 45 | 'while', |
Thomas Wouters | 1f1c16a | 2006-02-28 22:50:17 +0000 | [diff] [blame] | 46 | 'with', |
Tim Peters | 4637668 | 2001-06-19 00:26:25 +0000 | [diff] [blame] | 47 | 'yield', |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 48 | #--end keywords-- |
| 49 | ] |
Guido van Rossum | 90d556f | 1997-03-20 19:44:30 +0000 | [diff] [blame] | 50 | |
Raymond Hettinger | 70ef869 | 2003-12-02 07:48:15 +0000 | [diff] [blame] | 51 | iskeyword = frozenset(kwlist).__contains__ |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 52 | |
| 53 | def main(): |
Eric S. Raymond | ee5e61d | 2001-02-09 09:10:35 +0000 | [diff] [blame] | 54 | import sys, re |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 55 | |
| 56 | args = sys.argv[1:] |
| 57 | iptfile = args and args[0] or "Python/graminit.c" |
| 58 | if len(args) > 1: optfile = args[1] |
| 59 | else: optfile = "Lib/keyword.py" |
| 60 | |
| 61 | # scan the source file for keywords |
Guido van Rossum | 4d81984 | 1997-03-20 20:40:45 +0000 | [diff] [blame] | 62 | fp = open(iptfile) |
Guido van Rossum | 9694fca | 1997-10-22 21:00:49 +0000 | [diff] [blame] | 63 | strprog = re.compile('"([^"]+)"') |
Guido van Rossum | 4d81984 | 1997-03-20 20:40:45 +0000 | [diff] [blame] | 64 | lines = [] |
Georg Brandl | 1ea8cb4 | 2008-01-21 17:22:06 +0000 | [diff] [blame] | 65 | for line in fp: |
Raymond Hettinger | bac788a | 2004-05-04 09:21:43 +0000 | [diff] [blame] | 66 | if '{1, "' in line: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 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') |
Eric S. Raymond | ee5e61d | 2001-02-09 09:10:35 +0000 | [diff] [blame] | 89 | fp.write(''.join(format)) |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 90 | fp.close() |
| 91 | |
Guido van Rossum | 9694fca | 1997-10-22 21:00:49 +0000 | [diff] [blame] | 92 | if __name__ == "__main__": |
| 93 | main() |