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