0001 #! /usr/bin/env python 0002 0003 """Token constants (from "token.h").""" 0004 0005 # This file is automatically generated; please don't muck it up! 0006 # 0007 # To update the symbols in this file, 'cd' to the top directory of 0008 # the python source tree after building the interpreter and run: 0009 # 0010 # python Lib/token.py 0011 0012 #--start constants-- 0013 ENDMARKER = 0 0014 NAME = 1 0015 NUMBER = 2 0016 STRING = 3 0017 NEWLINE = 4 0018 INDENT = 5 0019 DEDENT = 6 0020 LPAR = 7 0021 RPAR = 8 0022 LSQB = 9 0023 RSQB = 10 0024 COLON = 11 0025 COMMA = 12 0026 SEMI = 13 0027 PLUS = 14 0028 MINUS = 15 0029 STAR = 16 0030 SLASH = 17 0031 VBAR = 18 0032 AMPER = 19 0033 LESS = 20 0034 GREATER = 21 0035 EQUAL = 22 0036 DOT = 23 0037 PERCENT = 24 0038 BACKQUOTE = 25 0039 LBRACE = 26 0040 RBRACE = 27 0041 EQEQUAL = 28 0042 NOTEQUAL = 29 0043 LESSEQUAL = 30 0044 GREATEREQUAL = 31 0045 TILDE = 32 0046 CIRCUMFLEX = 33 0047 LEFTSHIFT = 34 0048 RIGHTSHIFT = 35 0049 DOUBLESTAR = 36 0050 PLUSEQUAL = 37 0051 MINEQUAL = 38 0052 STAREQUAL = 39 0053 SLASHEQUAL = 40 0054 PERCENTEQUAL = 41 0055 AMPEREQUAL = 42 0056 VBAREQUAL = 43 0057 CIRCUMFLEXEQUAL = 44 0058 LEFTSHIFTEQUAL = 45 0059 RIGHTSHIFTEQUAL = 46 0060 DOUBLESTAREQUAL = 47 0061 DOUBLESLASH = 48 0062 DOUBLESLASHEQUAL = 49 0063 AT = 50 0064 OP = 51 0065 ERRORTOKEN = 52 0066 N_TOKENS = 53 0067 NT_OFFSET = 256 0068 #--end constants-- 0069 0070 tok_name = {} 0071 for _name, _value in globals().items(): 0072 if type(_value) is type(0): 0073 tok_name[_value] = _name 0074 0075 0076 def ISTERMINAL(x): 0077 return x < NT_OFFSET 0078 0079 def ISNONTERMINAL(x): 0080 return x >= NT_OFFSET 0081 0082 def ISEOF(x): 0083 return x == ENDMARKER 0084 0085 0086 def main(): 0087 import re 0088 import sys 0089 args = sys.argv[1:] 0090 inFileName = args and args[0] or "Include/token.h" 0091 outFileName = "Lib/token.py" 0092 if len(args) > 1: 0093 outFileName = args[1] 0094 try: 0095 fp = open(inFileName) 0096 except IOError, err: 0097 sys.stdout.write("I/O error: %s\n" % str(err)) 0098 sys.exit(1) 0099 lines = fp.read().split("\n") 0100 fp.close() 0101 prog = re.compile( 0102 "#define[ \t][ \t]*([A-Z0-9][A-Z0-9_]*)[ \t][ \t]*([0-9][0-9]*)", 0103 re.IGNORECASE) 0104 tokens = {} 0105 for line in lines: 0106 match = prog.match(line) 0107 if match: 0108 name, val = match.group(1, 2) 0109 val = int(val) 0110 tokens[val] = name # reverse so we can sort them... 0111 keys = tokens.keys() 0112 keys.sort() 0113 # load the output skeleton from the target: 0114 try: 0115 fp = open(outFileName) 0116 except IOError, err: 0117 sys.stderr.write("I/O error: %s\n" % str(err)) 0118 sys.exit(2) 0119 format = fp.read().split("\n") 0120 fp.close() 0121 try: 0122 start = format.index("#--start constants--") + 1 0123 end = format.index("#--end constants--") 0124 except ValueError: 0125 sys.stderr.write("target does not contain format markers") 0126 sys.exit(3) 0127 lines = [] 0128 for val in keys: 0129 lines.append("%s = %d" % (tokens[val], val)) 0130 format[start:end] = lines 0131 try: 0132 fp = open(outFileName, 'w') 0133 except IOError, err: 0134 sys.stderr.write("I/O error: %s\n" % str(err)) 0135 sys.exit(4) 0136 fp.write("\n".join(format)) 0137 fp.close() 0138 0139 0140 if __name__ == "__main__": 0141 main() 0142
Generated by PyXR 0.9.4