Merged revisions 85328 via svnmerge from
[python/dscho.git] / Lib / token.py
blobda4d29b3263d63cf95dc100ec22c8f788e1f7b49
1 #! /usr/bin/env python
3 """Token constants (from "token.h")."""
5 # This file is automatically generated; please don't muck it up!
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:
10 # python Lib/token.py
12 #--start constants--
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
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
48 DOUBLESTAR = 36
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
60 DOUBLESLASH = 48
61 DOUBLESLASHEQUAL = 49
62 AT = 50
63 RARROW = 51
64 ELLIPSIS = 52
65 OP = 53
66 ERRORTOKEN = 54
67 N_TOKENS = 55
68 NT_OFFSET = 256
69 #--end constants--
71 tok_name = {}
72 for _name, _value in list(globals().items()):
73 if type(_value) is type(0):
74 tok_name[_value] = _name
75 del _name, _value
78 def ISTERMINAL(x):
79 return x < NT_OFFSET
81 def ISNONTERMINAL(x):
82 return x >= NT_OFFSET
84 def ISEOF(x):
85 return x == ENDMARKER
88 def main():
89 import re
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:
95 outFileName = args[1]
96 try:
97 fp = open(inFileName)
98 except IOError as err:
99 sys.stdout.write("I/O error: %s\n" % str(err))
100 sys.exit(1)
101 lines = fp.read().split("\n")
102 fp.close()
103 prog = re.compile(
104 "#define[ \t][ \t]*([A-Z0-9][A-Z0-9_]*)[ \t][ \t]*([0-9][0-9]*)",
105 re.IGNORECASE)
106 tokens = {}
107 for line in lines:
108 match = prog.match(line)
109 if match:
110 name, val = match.group(1, 2)
111 val = int(val)
112 tokens[val] = name # reverse so we can sort them...
113 keys = sorted(tokens.keys())
114 # load the output skeleton from the target:
115 try:
116 fp = open(outFileName)
117 except IOError as err:
118 sys.stderr.write("I/O error: %s\n" % str(err))
119 sys.exit(2)
120 format = fp.read().split("\n")
121 fp.close()
122 try:
123 start = format.index("#--start constants--") + 1
124 end = format.index("#--end constants--")
125 except ValueError:
126 sys.stderr.write("target does not contain format markers")
127 sys.exit(3)
128 lines = []
129 for val in keys:
130 lines.append("%s = %d" % (tokens[val], val))
131 format[start:end] = lines
132 try:
133 fp = open(outFileName, 'w')
134 except IOError as err:
135 sys.stderr.write("I/O error: %s\n" % str(err))
136 sys.exit(4)
137 fp.write("\n".join(format))
138 fp.close()
141 if __name__ == "__main__":
142 main()