Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
Guido van Rossum | e7b146f | 2000-02-04 15:28:42 +0000 | [diff] [blame] | 2 | |
| 3 | """Token constants (from "token.h").""" |
| 4 | |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 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/token.py |
Guido van Rossum | b31c7f7 | 1993-11-11 10:31:23 +0000 | [diff] [blame] | 11 | |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 12 | #--start constants-- |
Guido van Rossum | b31c7f7 | 1993-11-11 10:31:23 +0000 | [diff] [blame] | 13 | ENDMARKER = 0 |
| 14 | NAME = 1 |
| 15 | NUMBER = 2 |
| 16 | STRING = 3 |
| 17 | NEWLINE = 4 |
| 18 | INDENT = 5 |
| 19 | DEDENT = 6 |
| 20 | LPAR = 7 |
| 21 | RPAR = 8 |
| 22 | LSQB = 9 |
| 23 | RSQB = 10 |
| 24 | COLON = 11 |
| 25 | COMMA = 12 |
| 26 | SEMI = 13 |
| 27 | PLUS = 14 |
| 28 | MINUS = 15 |
| 29 | STAR = 16 |
| 30 | SLASH = 17 |
| 31 | VBAR = 18 |
| 32 | AMPER = 19 |
| 33 | LESS = 20 |
| 34 | GREATER = 21 |
| 35 | EQUAL = 22 |
| 36 | DOT = 23 |
| 37 | PERCENT = 24 |
Guido van Rossum | b31c7f7 | 1993-11-11 10:31:23 +0000 | [diff] [blame] | 38 | LBRACE = 26 |
| 39 | RBRACE = 27 |
| 40 | EQEQUAL = 28 |
| 41 | NOTEQUAL = 29 |
| 42 | LESSEQUAL = 30 |
| 43 | GREATEREQUAL = 31 |
| 44 | TILDE = 32 |
| 45 | CIRCUMFLEX = 33 |
| 46 | LEFTSHIFT = 34 |
| 47 | RIGHTSHIFT = 35 |
Guido van Rossum | 154a539 | 1996-07-21 02:17:52 +0000 | [diff] [blame] | 48 | DOUBLESTAR = 36 |
Thomas Wouters | 3405262 | 2000-08-24 21:08:39 +0000 | [diff] [blame] | 49 | PLUSEQUAL = 37 |
| 50 | MINEQUAL = 38 |
| 51 | STAREQUAL = 39 |
| 52 | SLASHEQUAL = 40 |
| 53 | PERCENTEQUAL = 41 |
| 54 | AMPEREQUAL = 42 |
| 55 | VBAREQUAL = 43 |
| 56 | CIRCUMFLEXEQUAL = 44 |
| 57 | LEFTSHIFTEQUAL = 45 |
| 58 | RIGHTSHIFTEQUAL = 46 |
| 59 | DOUBLESTAREQUAL = 47 |
Tim Peters | a38d260 | 2001-08-08 06:35:56 +0000 | [diff] [blame] | 60 | DOUBLESLASH = 48 |
| 61 | DOUBLESLASHEQUAL = 49 |
Anthony Baxter | c2a5a63 | 2004-08-02 06:10:11 +0000 | [diff] [blame] | 62 | AT = 50 |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 63 | RARROW = 51 |
Georg Brandl | dde0028 | 2007-03-18 19:01:53 +0000 | [diff] [blame] | 64 | ELLIPSIS = 52 |
| 65 | OP = 53 |
| 66 | ERRORTOKEN = 54 |
| 67 | N_TOKENS = 55 |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 68 | NT_OFFSET = 256 |
| 69 | #--end constants-- |
Guido van Rossum | b31c7f7 | 1993-11-11 10:31:23 +0000 | [diff] [blame] | 70 | |
Guido van Rossum | b31c7f7 | 1993-11-11 10:31:23 +0000 | [diff] [blame] | 71 | tok_name = {} |
Guido van Rossum | cc2b016 | 2007-02-11 06:12:03 +0000 | [diff] [blame] | 72 | for _name, _value in list(globals().items()): |
Fred Drake | e3dbc7e | 1997-10-06 21:28:04 +0000 | [diff] [blame] | 73 | if type(_value) is type(0): |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 74 | tok_name[_value] = _name |
Christian Heimes | 836baa5 | 2008-02-26 08:18:30 +0000 | [diff] [blame] | 75 | del _name, _value |
Fred Drake | e3dbc7e | 1997-10-06 21:28:04 +0000 | [diff] [blame] | 76 | |
Guido van Rossum | b31c7f7 | 1993-11-11 10:31:23 +0000 | [diff] [blame] | 77 | |
Guido van Rossum | 154a539 | 1996-07-21 02:17:52 +0000 | [diff] [blame] | 78 | def ISTERMINAL(x): |
| 79 | return x < NT_OFFSET |
| 80 | |
| 81 | def ISNONTERMINAL(x): |
| 82 | return x >= NT_OFFSET |
| 83 | |
| 84 | def ISEOF(x): |
| 85 | return x == ENDMARKER |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 86 | |
| 87 | |
| 88 | def main(): |
Guido van Rossum | 9694fca | 1997-10-22 21:00:49 +0000 | [diff] [blame] | 89 | import re |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 90 | import sys |
| 91 | args = sys.argv[1:] |
| 92 | inFileName = args and args[0] or "Include/token.h" |
| 93 | outFileName = "Lib/token.py" |
| 94 | if len(args) > 1: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 95 | outFileName = args[1] |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 96 | try: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 97 | fp = open(inFileName) |
Guido van Rossum | b940e11 | 2007-01-10 16:19:56 +0000 | [diff] [blame] | 98 | except IOError as err: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 99 | sys.stdout.write("I/O error: %s\n" % str(err)) |
| 100 | sys.exit(1) |
Eric S. Raymond | b08b2d3 | 2001-02-09 11:10:16 +0000 | [diff] [blame] | 101 | lines = fp.read().split("\n") |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 102 | fp.close() |
Guido van Rossum | 9694fca | 1997-10-22 21:00:49 +0000 | [diff] [blame] | 103 | prog = re.compile( |
Michael W. Hudson | adf1606 | 2002-10-03 09:42:01 +0000 | [diff] [blame] | 104 | "#define[ \t][ \t]*([A-Z0-9][A-Z0-9_]*)[ \t][ \t]*([0-9][0-9]*)", |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 105 | re.IGNORECASE) |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 106 | tokens = {} |
| 107 | for line in lines: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 108 | match = prog.match(line) |
| 109 | if match: |
| 110 | name, val = match.group(1, 2) |
Eric S. Raymond | 6e025bc | 2001-02-10 00:22:33 +0000 | [diff] [blame] | 111 | val = int(val) |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 112 | tokens[val] = name # reverse so we can sort them... |
Guido van Rossum | c145ef3 | 2007-02-26 14:08:27 +0000 | [diff] [blame] | 113 | keys = sorted(tokens.keys()) |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 114 | # load the output skeleton from the target: |
| 115 | try: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 116 | fp = open(outFileName) |
Guido van Rossum | b940e11 | 2007-01-10 16:19:56 +0000 | [diff] [blame] | 117 | except IOError as err: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 118 | sys.stderr.write("I/O error: %s\n" % str(err)) |
| 119 | sys.exit(2) |
Eric S. Raymond | b08b2d3 | 2001-02-09 11:10:16 +0000 | [diff] [blame] | 120 | format = fp.read().split("\n") |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 121 | fp.close() |
| 122 | try: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 123 | start = format.index("#--start constants--") + 1 |
| 124 | end = format.index("#--end constants--") |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 125 | except ValueError: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 126 | sys.stderr.write("target does not contain format markers") |
| 127 | sys.exit(3) |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 128 | lines = [] |
| 129 | for val in keys: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 130 | lines.append("%s = %d" % (tokens[val], val)) |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 131 | format[start:end] = lines |
| 132 | try: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 133 | fp = open(outFileName, 'w') |
Guido van Rossum | b940e11 | 2007-01-10 16:19:56 +0000 | [diff] [blame] | 134 | except IOError as err: |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 135 | sys.stderr.write("I/O error: %s\n" % str(err)) |
| 136 | sys.exit(4) |
Eric S. Raymond | b08b2d3 | 2001-02-09 11:10:16 +0000 | [diff] [blame] | 137 | fp.write("\n".join(format)) |
Guido van Rossum | 4747887 | 1996-08-21 14:32:37 +0000 | [diff] [blame] | 138 | fp.close() |
| 139 | |
| 140 | |
| 141 | if __name__ == "__main__": |
| 142 | main() |