blob: c77d3430bedca3e21bb4a9693818bc7335a3f85f [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
63OP = 50
64ERRORTOKEN = 51
65N_TOKENS = 52
Guido van Rossum47478871996-08-21 14:32:37 +000066NT_OFFSET = 256
67#--end constants--
Guido van Rossumb31c7f71993-11-11 10:31:23 +000068
Guido van Rossumb31c7f71993-11-11 10:31:23 +000069tok_name = {}
Fred Drakee3dbc7e1997-10-06 21:28:04 +000070for _name, _value in globals().items():
71 if type(_value) is type(0):
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000072 tok_name[_value] = _name
Fred Drakee3dbc7e1997-10-06 21:28:04 +000073
Guido van Rossumb31c7f71993-11-11 10:31:23 +000074
Guido van Rossum154a5391996-07-21 02:17:52 +000075def ISTERMINAL(x):
76 return x < NT_OFFSET
77
78def ISNONTERMINAL(x):
79 return x >= NT_OFFSET
80
81def ISEOF(x):
82 return x == ENDMARKER
Guido van Rossum47478871996-08-21 14:32:37 +000083
84
85def main():
Guido van Rossum9694fca1997-10-22 21:00:49 +000086 import re
Guido van Rossum47478871996-08-21 14:32:37 +000087 import sys
88 args = sys.argv[1:]
89 inFileName = args and args[0] or "Include/token.h"
90 outFileName = "Lib/token.py"
91 if len(args) > 1:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000092 outFileName = args[1]
Guido van Rossum47478871996-08-21 14:32:37 +000093 try:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000094 fp = open(inFileName)
Guido van Rossum47478871996-08-21 14:32:37 +000095 except IOError, err:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000096 sys.stdout.write("I/O error: %s\n" % str(err))
97 sys.exit(1)
Eric S. Raymondb08b2d32001-02-09 11:10:16 +000098 lines = fp.read().split("\n")
Guido van Rossum47478871996-08-21 14:32:37 +000099 fp.close()
Guido van Rossum9694fca1997-10-22 21:00:49 +0000100 prog = re.compile(
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000101 "#define[ \t][ \t]*([A-Z][A-Z_]*)[ \t][ \t]*([0-9][0-9]*)",
102 re.IGNORECASE)
Guido van Rossum47478871996-08-21 14:32:37 +0000103 tokens = {}
104 for line in lines:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000105 match = prog.match(line)
106 if match:
107 name, val = match.group(1, 2)
Eric S. Raymond6e025bc2001-02-10 00:22:33 +0000108 val = int(val)
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000109 tokens[val] = name # reverse so we can sort them...
Guido van Rossum47478871996-08-21 14:32:37 +0000110 keys = tokens.keys()
111 keys.sort()
112 # load the output skeleton from the target:
113 try:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000114 fp = open(outFileName)
Guido van Rossum47478871996-08-21 14:32:37 +0000115 except IOError, err:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000116 sys.stderr.write("I/O error: %s\n" % str(err))
117 sys.exit(2)
Eric S. Raymondb08b2d32001-02-09 11:10:16 +0000118 format = fp.read().split("\n")
Guido van Rossum47478871996-08-21 14:32:37 +0000119 fp.close()
120 try:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000121 start = format.index("#--start constants--") + 1
122 end = format.index("#--end constants--")
Guido van Rossum47478871996-08-21 14:32:37 +0000123 except ValueError:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000124 sys.stderr.write("target does not contain format markers")
125 sys.exit(3)
Guido van Rossum47478871996-08-21 14:32:37 +0000126 lines = []
127 for val in keys:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000128 lines.append("%s = %d" % (tokens[val], val))
Guido van Rossum47478871996-08-21 14:32:37 +0000129 format[start:end] = lines
130 try:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000131 fp = open(outFileName, 'w')
Guido van Rossum47478871996-08-21 14:32:37 +0000132 except IOError, err:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000133 sys.stderr.write("I/O error: %s\n" % str(err))
134 sys.exit(4)
Eric S. Raymondb08b2d32001-02-09 11:10:16 +0000135 fp.write("\n".join(format))
Guido van Rossum47478871996-08-21 14:32:37 +0000136 fp.close()
137
138
139if __name__ == "__main__":
140 main()