|
|
"""Token constants (from "token.h")."""
__all__ = ['tok_name', 'ISTERMINAL', 'ISNONTERMINAL', 'ISEOF']
# This file is automatically generated; please don't muck it up!## To update the symbols in this file, 'cd' to the top directory of# the python source tree after building the interpreter and run:## python Lib/token.py
#--start constants--ENDMARKER = 0NAME = 1NUMBER = 2STRING = 3NEWLINE = 4INDENT = 5DEDENT = 6LPAR = 7RPAR = 8LSQB = 9RSQB = 10COLON = 11COMMA = 12SEMI = 13PLUS = 14MINUS = 15STAR = 16SLASH = 17VBAR = 18AMPER = 19LESS = 20GREATER = 21EQUAL = 22DOT = 23PERCENT = 24LBRACE = 26RBRACE = 27EQEQUAL = 28NOTEQUAL = 29LESSEQUAL = 30GREATEREQUAL = 31TILDE = 32CIRCUMFLEX = 33LEFTSHIFT = 34RIGHTSHIFT = 35DOUBLESTAR = 36PLUSEQUAL = 37MINEQUAL = 38STAREQUAL = 39SLASHEQUAL = 40PERCENTEQUAL = 41AMPEREQUAL = 42VBAREQUAL = 43CIRCUMFLEXEQUAL = 44LEFTSHIFTEQUAL = 45RIGHTSHIFTEQUAL = 46DOUBLESTAREQUAL = 47DOUBLESLASH = 48DOUBLESLASHEQUAL = 49AT = 50RARROW = 51ELLIPSIS = 52OP = 53ERRORTOKEN = 54N_TOKENS = 55NT_OFFSET = 256#--end constants--
tok_name = {value: name for name, value in globals().items() if isinstance(value, int)}__all__.extend(tok_name.values())
def ISTERMINAL(x): return x < NT_OFFSET
def ISNONTERMINAL(x): return x >= NT_OFFSET
def ISEOF(x): return x == ENDMARKER
def _main(): import re import sys args = sys.argv[1:] inFileName = args and args[0] or "Include/token.h" outFileName = "Lib/token.py" if len(args) > 1: outFileName = args[1] try: fp = open(inFileName) except IOError as err: sys.stdout.write("I/O error: %s\n" % str(err)) sys.exit(1) lines = fp.read().split("\n") fp.close() prog = re.compile( "#define[ \t][ \t]*([A-Z0-9][A-Z0-9_]*)[ \t][ \t]*([0-9][0-9]*)", re.IGNORECASE) tokens = {} for line in lines: match = prog.match(line) if match: name, val = match.group(1, 2) val = int(val) tokens[val] = name # reverse so we can sort them... keys = sorted(tokens.keys()) # load the output skeleton from the target: try: fp = open(outFileName) except IOError as err: sys.stderr.write("I/O error: %s\n" % str(err)) sys.exit(2) format = fp.read().split("\n") fp.close() try: start = format.index("#--start constants--") + 1 end = format.index("#--end constants--") except ValueError: sys.stderr.write("target does not contain format markers") sys.exit(3) lines = [] for val in keys: lines.append("%s = %d" % (tokens[val], val)) format[start:end] = lines try: fp = open(outFileName, 'w') except IOError as err: sys.stderr.write("I/O error: %s\n" % str(err)) sys.exit(4) fp.write("\n".join(format)) fp.close()
if __name__ == "__main__": _main()
|