blob: c4db6c511af0f490f1083de4dca2c39da665ae2c [file] [log] [blame]
Guido van Rossum47478871996-08-21 14:32:37 +00001#! /usr/bin/env python
Guido van Rossume7b146f2000-02-04 15:28:42 +00002
3"""Token constants (from "token.h")."""
4
Guido van Rossum47478871996-08-21 14:32:37 +00005# 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 Rossum9694fca1997-10-22 21:00:49 +000010# python Lib/token.py
Guido van Rossumb31c7f71993-11-11 10:31:23 +000011
Guido van Rossum47478871996-08-21 14:32:37 +000012#--start constants--
Guido van Rossumb31c7f71993-11-11 10:31:23 +000013ENDMARKER = 0
14NAME = 1
15NUMBER = 2
16STRING = 3
17NEWLINE = 4
18INDENT = 5
19DEDENT = 6
20LPAR = 7
21RPAR = 8
22LSQB = 9
23RSQB = 10
24COLON = 11
25COMMA = 12
26SEMI = 13
27PLUS = 14
28MINUS = 15
29STAR = 16
30SLASH = 17
31VBAR = 18
32AMPER = 19
33LESS = 20
34GREATER = 21
35EQUAL = 22
36DOT = 23
37PERCENT = 24
38BACKQUOTE = 25
39LBRACE = 26
40RBRACE = 27
41EQEQUAL = 28
42NOTEQUAL = 29
43LESSEQUAL = 30
44GREATEREQUAL = 31
45TILDE = 32
46CIRCUMFLEX = 33
47LEFTSHIFT = 34
48RIGHTSHIFT = 35
Guido van Rossum154a5391996-07-21 02:17:52 +000049DOUBLESTAR = 36
Thomas Wouters34052622000-08-24 21:08:39 +000050PLUSEQUAL = 37
51MINEQUAL = 38
52STAREQUAL = 39
53SLASHEQUAL = 40
54PERCENTEQUAL = 41
55AMPEREQUAL = 42
56VBAREQUAL = 43
57CIRCUMFLEXEQUAL = 44
58LEFTSHIFTEQUAL = 45
59RIGHTSHIFTEQUAL = 46
60DOUBLESTAREQUAL = 47
Tim Petersa38d2602001-08-08 06:35:56 +000061DOUBLESLASH = 48
62DOUBLESLASHEQUAL = 49
Anthony Baxterc2a5a632004-08-02 06:10:11 +000063AT = 50
64OP = 51
65ERRORTOKEN = 52
66N_TOKENS = 53
Guido van Rossum47478871996-08-21 14:32:37 +000067NT_OFFSET = 256
68#--end constants--
Guido van Rossumb31c7f71993-11-11 10:31:23 +000069
Guido van Rossumb31c7f71993-11-11 10:31:23 +000070tok_name = {}
Fred Drakee3dbc7e1997-10-06 21:28:04 +000071for _name, _value in globals().items():
72 if type(_value) is type(0):
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000073 tok_name[_value] = _name
Fred Drakee3dbc7e1997-10-06 21:28:04 +000074
Guido van Rossumb31c7f71993-11-11 10:31:23 +000075
Guido van Rossum154a5391996-07-21 02:17:52 +000076def ISTERMINAL(x):
77 return x < NT_OFFSET
78
79def ISNONTERMINAL(x):
80 return x >= NT_OFFSET
81
82def ISEOF(x):
83 return x == ENDMARKER
Guido van Rossum47478871996-08-21 14:32:37 +000084
85
86def main():
Guido van Rossum9694fca1997-10-22 21:00:49 +000087 import re
Guido van Rossum47478871996-08-21 14:32:37 +000088 import sys
89 args = sys.argv[1:]
90 inFileName = args and args[0] or "Include/token.h"
91 outFileName = "Lib/token.py"
92 if len(args) > 1:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000093 outFileName = args[1]
Guido van Rossum47478871996-08-21 14:32:37 +000094 try:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000095 fp = open(inFileName)
Guido van Rossum47478871996-08-21 14:32:37 +000096 except IOError, err:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000097 sys.stdout.write("I/O error: %s\n" % str(err))
98 sys.exit(1)
Eric S. Raymondb08b2d32001-02-09 11:10:16 +000099 lines = fp.read().split("\n")
Guido van Rossum47478871996-08-21 14:32:37 +0000100 fp.close()
Guido van Rossum9694fca1997-10-22 21:00:49 +0000101 prog = re.compile(
Michael W. Hudsonadf16062002-10-03 09:42:01 +0000102 "#define[ \t][ \t]*([A-Z0-9][A-Z0-9_]*)[ \t][ \t]*([0-9][0-9]*)",
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000103 re.IGNORECASE)
Guido van Rossum47478871996-08-21 14:32:37 +0000104 tokens = {}
105 for line in lines:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000106 match = prog.match(line)
107 if match:
108 name, val = match.group(1, 2)
Eric S. Raymond6e025bc2001-02-10 00:22:33 +0000109 val = int(val)
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000110 tokens[val] = name # reverse so we can sort them...
Guido van Rossum47478871996-08-21 14:32:37 +0000111 keys = tokens.keys()
112 keys.sort()
113 # load the output skeleton from the target:
114 try:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000115 fp = open(outFileName)
Guido van Rossum47478871996-08-21 14:32:37 +0000116 except IOError, err:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000117 sys.stderr.write("I/O error: %s\n" % str(err))
118 sys.exit(2)
Eric S. Raymondb08b2d32001-02-09 11:10:16 +0000119 format = fp.read().split("\n")
Guido van Rossum47478871996-08-21 14:32:37 +0000120 fp.close()
121 try:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000122 start = format.index("#--start constants--") + 1
123 end = format.index("#--end constants--")
Guido van Rossum47478871996-08-21 14:32:37 +0000124 except ValueError:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000125 sys.stderr.write("target does not contain format markers")
126 sys.exit(3)
Guido van Rossum47478871996-08-21 14:32:37 +0000127 lines = []
128 for val in keys:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000129 lines.append("%s = %d" % (tokens[val], val))
Guido van Rossum47478871996-08-21 14:32:37 +0000130 format[start:end] = lines
131 try:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000132 fp = open(outFileName, 'w')
Guido van Rossum47478871996-08-21 14:32:37 +0000133 except IOError, err:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000134 sys.stderr.write("I/O error: %s\n" % str(err))
135 sys.exit(4)
Eric S. Raymondb08b2d32001-02-09 11:10:16 +0000136 fp.write("\n".join(format))
Guido van Rossum47478871996-08-21 14:32:37 +0000137 fp.close()
138
139
140if __name__ == "__main__":
141 main()