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 | |
R David Murray | f0f7cea | 2013-04-25 12:01:36 -0400 | [diff] [blame] | 63 | # load the output skeleton from the target, taking care to preserve its |
| 64 | # newline convention. |
| 65 | with open(optfile, newline='') as fp: |
| 66 | format = fp.readlines() |
| 67 | nl = format[0][len(format[0].strip()):] if format else '\n' |
| 68 | |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 69 | # scan the source file for keywords |
Florent Xicluna | 7dde792 | 2010-09-03 19:52:03 +0000 | [diff] [blame] | 70 | with open(iptfile) as fp: |
| 71 | strprog = re.compile('"([^"]+)"') |
| 72 | lines = [] |
| 73 | for line in fp: |
| 74 | if '{1, "' in line: |
| 75 | match = strprog.search(line) |
| 76 | if match: |
R David Murray | f0f7cea | 2013-04-25 12:01:36 -0400 | [diff] [blame] | 77 | lines.append(" '" + match.group(1) + "'," + nl) |
Guido van Rossum | 4d81984 | 1997-03-20 20:40:45 +0000 | [diff] [blame] | 78 | lines.sort() |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 79 | |
R David Murray | f0f7cea | 2013-04-25 12:01:36 -0400 | [diff] [blame] | 80 | # insert the lines of keywords into the skeleton |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 81 | try: |
R David Murray | f0f7cea | 2013-04-25 12:01:36 -0400 | [diff] [blame] | 82 | start = format.index("#--start keywords--" + nl) + 1 |
| 83 | end = format.index("#--end keywords--" + nl) |
Guido van Rossum | 4d81984 | 1997-03-20 20:40:45 +0000 | [diff] [blame] | 84 | format[start:end] = lines |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 85 | except ValueError: |
| 86 | sys.stderr.write("target does not contain format markers\n") |
Guido van Rossum | 4d81984 | 1997-03-20 20:40:45 +0000 | [diff] [blame] | 87 | sys.exit(1) |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 88 | |
| 89 | # write the output file |
R David Murray | f0f7cea | 2013-04-25 12:01:36 -0400 | [diff] [blame] | 90 | with open(optfile, 'w', newline='') as fp: |
| 91 | fp.writelines(format) |
Guido van Rossum | eb8c972 | 1997-03-20 19:45:51 +0000 | [diff] [blame] | 92 | |
Guido van Rossum | 9694fca | 1997-10-22 21:00:49 +0000 | [diff] [blame] | 93 | if __name__ == "__main__": |
| 94 | main() |