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:
72 for _name
, _value
in list(globals().items()):
73 if type(_value
) is type(0):
74 tok_name
[_value
] = _name
92 inFileName
= args
and args
[0] or "Include/token.h"
93 outFileName
= "Lib/token.py"
98 except IOError as err
:
99 sys
.stdout
.write("I/O error: %s\n" % str(err
))
101 lines
= fp
.read().split("\n")
104 "#define[ \t][ \t]*([A-Z0-9][A-Z0-9_]*)[ \t][ \t]*([0-9][0-9]*)",
108 match
= prog
.match(line
)
110 name
, val
= match
.group(1, 2)
112 tokens
[val
] = name
# reverse so we can sort them...
113 keys
= sorted(tokens
.keys())
114 # load the output skeleton from the target:
116 fp
= open(outFileName
)
117 except IOError as err
:
118 sys
.stderr
.write("I/O error: %s\n" % str(err
))
120 format
= fp
.read().split("\n")
123 start
= format
.index("#--start constants--") + 1
124 end
= format
.index("#--end constants--")
126 sys
.stderr
.write("target does not contain format markers")
130 lines
.append("%s = %d" % (tokens
[val
], val
))
131 format
[start
:end
] = lines
133 fp
= open(outFileName
, 'w')
134 except IOError as err
:
135 sys
.stderr
.write("I/O error: %s\n" % str(err
))
137 fp
.write("\n".join(format
))
141 if __name__
== "__main__":