Benjamin Peterson | 90f5ba5 | 2010-03-11 22:53:45 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python3 |
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 | |
Éric Araujo | e1886bf | 2011-11-29 16:45:34 +0100 | [diff] [blame] | 10 | ./python Lib/keyword.py |
Guido van Rossum | 54f22ed | 2000-02-04 15:10:34 +0000 | [diff] [blame] | 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 |
Florent Xicluna | 7dde792 | 2010-09-03 19:52:03 +0000 | [diff] [blame] | 64 | with open(iptfile) as fp: |
| 65 | strprog = re.compile('"([^"]+)"') |
| 66 | lines = [] |
| 67 | for line in fp: |
| 68 | if '{1, "' in line: |
| 69 | match = strprog.search(line) |
| 70 | if match: |
| 71 | lines.append(" '" + match.group(1) + "',\n") |
Guido van Rossum | 4d81984 | 1997-03-20 20:40:45 +0000 | [diff] [blame] | 72 | lines.sort() |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 73 | |
| 74 | # load the output skeleton from the target |
Florent Xicluna | 7dde792 | 2010-09-03 19:52:03 +0000 | [diff] [blame] | 75 | with open(optfile) as fp: |
| 76 | format = fp.readlines() |
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() |