Fixed issue-number mistake in NEWS update.
[python.git] / Lib / token.py
blob8d5cdaa1754afdfd87639e575cb0d168f41a8c88
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 BACKQUOTE = 25
39 LBRACE = 26
40 RBRACE = 27
41 EQEQUAL = 28
42 NOTEQUAL = 29
43 LESSEQUAL = 30
44 GREATEREQUAL = 31
45 TILDE = 32
46 CIRCUMFLEX = 33
47 LEFTSHIFT = 34
48 RIGHTSHIFT = 35
49 DOUBLESTAR = 36
50 PLUSEQUAL = 37
51 MINEQUAL = 38
52 STAREQUAL = 39
53 SLASHEQUAL = 40
54 PERCENTEQUAL = 41
55 AMPEREQUAL = 42
56 VBAREQUAL = 43
57 CIRCUMFLEXEQUAL = 44
58 LEFTSHIFTEQUAL = 45
59 RIGHTSHIFTEQUAL = 46
60 DOUBLESTAREQUAL = 47
61 DOUBLESLASH = 48
62 DOUBLESLASHEQUAL = 49
63 AT = 50
64 OP = 51
65 ERRORTOKEN = 52
66 N_TOKENS = 53
67 NT_OFFSET = 256
68 #--end constants--
70 tok_name = {}
71 for _name, _value in globals().items():
72 if type(_value) is type(0):
73 tok_name[_value] = _name
74 del _name, _value
77 def ISTERMINAL(x):
78 return x < NT_OFFSET
80 def ISNONTERMINAL(x):
81 return x >= NT_OFFSET
83 def ISEOF(x):
84 return x == ENDMARKER
87 def main():
88 import re
89 import sys
90 args = sys.argv[1:]
91 inFileName = args and args[0] or "Include/token.h"
92 outFileName = "Lib/token.py"
93 if len(args) > 1:
94 outFileName = args[1]
95 try:
96 fp = open(inFileName)
97 except IOError, err:
98 sys.stdout.write("I/O error: %s\n" % str(err))
99 sys.exit(1)
100 lines = fp.read().split("\n")
101 fp.close()
102 prog = re.compile(
103 "#define[ \t][ \t]*([A-Z0-9][A-Z0-9_]*)[ \t][ \t]*([0-9][0-9]*)",
104 re.IGNORECASE)
105 tokens = {}
106 for line in lines:
107 match = prog.match(line)
108 if match:
109 name, val = match.group(1, 2)
110 val = int(val)
111 tokens[val] = name # reverse so we can sort them...
112 keys = tokens.keys()
113 keys.sort()
114 # load the output skeleton from the target:
115 try:
116 fp = open(outFileName)
117 except IOError, 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, 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()