1"""Token constants (from "token.h").""" 2 3# This file is automatically generated; please don't muck it up! 4# 5# To update the symbols in this file, 'cd' to the top directory of 6# the python source tree after building the interpreter and run: 7# 8# ./python Lib/token.py 9 10#--start constants-- 11ENDMARKER = 0 12NAME = 1 13NUMBER = 2 14STRING = 3 15NEWLINE = 4 16INDENT = 5 17DEDENT = 6 18LPAR = 7 19RPAR = 8 20LSQB = 9 21RSQB = 10 22COLON = 11 23COMMA = 12 24SEMI = 13 25PLUS = 14 26MINUS = 15 27STAR = 16 28SLASH = 17 29VBAR = 18 30AMPER = 19 31LESS = 20 32GREATER = 21 33EQUAL = 22 34DOT = 23 35PERCENT = 24 36BACKQUOTE = 25 37LBRACE = 26 38RBRACE = 27 39EQEQUAL = 28 40NOTEQUAL = 29 41LESSEQUAL = 30 42GREATEREQUAL = 31 43TILDE = 32 44CIRCUMFLEX = 33 45LEFTSHIFT = 34 46RIGHTSHIFT = 35 47DOUBLESTAR = 36 48PLUSEQUAL = 37 49MINEQUAL = 38 50STAREQUAL = 39 51SLASHEQUAL = 40 52PERCENTEQUAL = 41 53AMPEREQUAL = 42 54VBAREQUAL = 43 55CIRCUMFLEXEQUAL = 44 56LEFTSHIFTEQUAL = 45 57RIGHTSHIFTEQUAL = 46 58DOUBLESTAREQUAL = 47 59DOUBLESLASH = 48 60DOUBLESLASHEQUAL = 49 61AT = 50 62OP = 51 63ERRORTOKEN = 52 64N_TOKENS = 53 65NT_OFFSET = 256 66#--end constants-- 67 68tok_name = {} 69for _name, _value in globals().items(): 70 if type(_value) is type(0): 71 tok_name[_value] = _name 72del _name, _value 73 74 75def ISTERMINAL(x): 76 return x < NT_OFFSET 77 78def ISNONTERMINAL(x): 79 return x >= NT_OFFSET 80 81def ISEOF(x): 82 return x == ENDMARKER 83 84 85def main(): 86 import re 87 import sys 88 args = sys.argv[1:] 89 inFileName = args and args[0] or "Include/token.h" 90 outFileName = "Lib/token.py" 91 if len(args) > 1: 92 outFileName = args[1] 93 try: 94 fp = open(inFileName) 95 except IOError, err: 96 sys.stdout.write("I/O error: %s\n" % str(err)) 97 sys.exit(1) 98 lines = fp.read().split("\n") 99 fp.close() 100 prog = re.compile( 101 "#define[ \t][ \t]*([A-Z0-9][A-Z0-9_]*)[ \t][ \t]*([0-9][0-9]*)", 102 re.IGNORECASE) 103 tokens = {} 104 for line in lines: 105 match = prog.match(line) 106 if match: 107 name, val = match.group(1, 2) 108 val = int(val) 109 tokens[val] = name # reverse so we can sort them... 110 keys = tokens.keys() 111 keys.sort() 112 # load the output skeleton from the target: 113 try: 114 fp = open(outFileName) 115 except IOError, err: 116 sys.stderr.write("I/O error: %s\n" % str(err)) 117 sys.exit(2) 118 format = fp.read().split("\n") 119 fp.close() 120 try: 121 start = format.index("#--start constants--") + 1 122 end = format.index("#--end constants--") 123 except ValueError: 124 sys.stderr.write("target does not contain format markers") 125 sys.exit(3) 126 lines = [] 127 for val in keys: 128 lines.append("%s = %d" % (tokens[val], val)) 129 format[start:end] = lines 130 try: 131 fp = open(outFileName, 'w') 132 except IOError, err: 133 sys.stderr.write("I/O error: %s\n" % str(err)) 134 sys.exit(4) 135 fp.write("\n".join(format)) 136 fp.close() 137 138 139if __name__ == "__main__": 140 main() 141