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-- 11 ENDMARKER = 0 12 NAME = 1 13 NUMBER = 2 14 STRING = 3 15 NEWLINE = 4 16 INDENT = 5 17 DEDENT = 6 18 LPAR = 7 19 RPAR = 8 20 LSQB = 9 21 RSQB = 10 22 COLON = 11 23 COMMA = 12 24 SEMI = 13 25 PLUS = 14 26 MINUS = 15 27 STAR = 16 28 SLASH = 17 29 VBAR = 18 30 AMPER = 19 31 LESS = 20 32 GREATER = 21 33 EQUAL = 22 34 DOT = 23 35 PERCENT = 24 36 BACKQUOTE = 25 37 LBRACE = 26 38 RBRACE = 27 39 EQEQUAL = 28 40 NOTEQUAL = 29 41 LESSEQUAL = 30 42 GREATEREQUAL = 31 43 TILDE = 32 44 CIRCUMFLEX = 33 45 LEFTSHIFT = 34 46 RIGHTSHIFT = 35 47 DOUBLESTAR = 36 48 PLUSEQUAL = 37 49 MINEQUAL = 38 50 STAREQUAL = 39 51 SLASHEQUAL = 40 52 PERCENTEQUAL = 41 53 AMPEREQUAL = 42 54 VBAREQUAL = 43 55 CIRCUMFLEXEQUAL = 44 56 LEFTSHIFTEQUAL = 45 57 RIGHTSHIFTEQUAL = 46 58 DOUBLESTAREQUAL = 47 59 DOUBLESLASH = 48 60 DOUBLESLASHEQUAL = 49 61 AT = 50 62 OP = 51 63 ERRORTOKEN = 52 64 N_TOKENS = 53 65 NT_OFFSET = 256 66 #--end constants-- 67 68 tok_name = {} 69 for _name, _value in globals().items(): 70 if type(_value) is type(0): 71 tok_name[_value] = _name 72 del _name, _value 73 74 75 def ISTERMINAL(x): 76 return x < NT_OFFSET 77 78 def ISNONTERMINAL(x): 79 return x >= NT_OFFSET 80 81 def ISEOF(x): 82 return x == ENDMARKER 83 84 85 def 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 139 if __name__ == "__main__": 140 main() 141