blob: 69941dc031cd0d9936b301f67a59991cf3ae36e4 [file] [log] [blame]
Guido van Rossum47478871996-08-21 14:32:37 +00001#! /usr/bin/env python
2#
3# Tokens (from "token.h")
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#
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
50OP = 37
51ERRORTOKEN = 38
Guido van Rossum47478871996-08-21 14:32:37 +000052N_TOKENS = 39
53NT_OFFSET = 256
54#--end constants--
Guido van Rossumb31c7f71993-11-11 10:31:23 +000055
Guido van Rossumb31c7f71993-11-11 10:31:23 +000056tok_name = {}
Fred Drakee3dbc7e1997-10-06 21:28:04 +000057for _name, _value in globals().items():
58 if type(_value) is type(0):
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000059 tok_name[_value] = _name
Fred Drakee3dbc7e1997-10-06 21:28:04 +000060
Guido van Rossumb31c7f71993-11-11 10:31:23 +000061
Guido van Rossum154a5391996-07-21 02:17:52 +000062def ISTERMINAL(x):
63 return x < NT_OFFSET
64
65def ISNONTERMINAL(x):
66 return x >= NT_OFFSET
67
68def ISEOF(x):
69 return x == ENDMARKER
Guido van Rossum47478871996-08-21 14:32:37 +000070
71
72def main():
Guido van Rossum9694fca1997-10-22 21:00:49 +000073 import re
Guido van Rossum47478871996-08-21 14:32:37 +000074 import string
75 import sys
76 args = sys.argv[1:]
77 inFileName = args and args[0] or "Include/token.h"
78 outFileName = "Lib/token.py"
79 if len(args) > 1:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000080 outFileName = args[1]
Guido van Rossum47478871996-08-21 14:32:37 +000081 try:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000082 fp = open(inFileName)
Guido van Rossum47478871996-08-21 14:32:37 +000083 except IOError, err:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000084 sys.stdout.write("I/O error: %s\n" % str(err))
85 sys.exit(1)
Guido van Rossum47478871996-08-21 14:32:37 +000086 lines = string.splitfields(fp.read(), "\n")
87 fp.close()
Guido van Rossum9694fca1997-10-22 21:00:49 +000088 prog = re.compile(
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000089 "#define[ \t][ \t]*([A-Z][A-Z_]*)[ \t][ \t]*([0-9][0-9]*)",
90 re.IGNORECASE)
Guido van Rossum47478871996-08-21 14:32:37 +000091 tokens = {}
92 for line in lines:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000093 match = prog.match(line)
94 if match:
95 name, val = match.group(1, 2)
96 val = string.atoi(val)
97 tokens[val] = name # reverse so we can sort them...
Guido van Rossum47478871996-08-21 14:32:37 +000098 keys = tokens.keys()
99 keys.sort()
100 # load the output skeleton from the target:
101 try:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000102 fp = open(outFileName)
Guido van Rossum47478871996-08-21 14:32:37 +0000103 except IOError, err:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000104 sys.stderr.write("I/O error: %s\n" % str(err))
105 sys.exit(2)
Guido van Rossum47478871996-08-21 14:32:37 +0000106 format = string.splitfields(fp.read(), "\n")
107 fp.close()
108 try:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000109 start = format.index("#--start constants--") + 1
110 end = format.index("#--end constants--")
Guido van Rossum47478871996-08-21 14:32:37 +0000111 except ValueError:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000112 sys.stderr.write("target does not contain format markers")
113 sys.exit(3)
Guido van Rossum47478871996-08-21 14:32:37 +0000114 lines = []
115 for val in keys:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000116 lines.append("%s = %d" % (tokens[val], val))
Guido van Rossum47478871996-08-21 14:32:37 +0000117 format[start:end] = lines
118 try:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000119 fp = open(outFileName, 'w')
Guido van Rossum47478871996-08-21 14:32:37 +0000120 except IOError, err:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000121 sys.stderr.write("I/O error: %s\n" % str(err))
122 sys.exit(4)
Guido van Rossum47478871996-08-21 14:32:37 +0000123 fp.write(string.joinfields(format, "\n"))
124 fp.close()
125
126
127if __name__ == "__main__":
128 main()