blob: 6b5320db8c34022ab6143bdbb2d192f2d4d2f5a4 [file] [log] [blame]
Guido van Rossume7b146f2000-02-04 15:28:42 +00001"""Token constants (from "token.h")."""
2
Alexander Belopolskyb9d10d02010-11-11 14:07:41 +00003__all__ = ['tok_name', 'ISTERMINAL', 'ISNONTERMINAL', 'ISEOF']
4
Guido van Rossum47478871996-08-21 14:32:37 +00005# This file is automatically generated; please don't muck it up!
6#
7# To update the symbols in this file, 'cd' to the top directory of
8# the python source tree after building the interpreter and run:
9#
Éric Araujoe1886bf2011-11-29 16:45:34 +010010# ./python Lib/token.py
Guido van Rossumb31c7f71993-11-11 10:31:23 +000011
Guido van Rossum47478871996-08-21 14:32:37 +000012#--start constants--
Guido van Rossumb31c7f71993-11-11 10:31:23 +000013ENDMARKER = 0
14NAME = 1
15NUMBER = 2
16STRING = 3
17NEWLINE = 4
18INDENT = 5
19DEDENT = 6
20LPAR = 7
21RPAR = 8
22LSQB = 9
23RSQB = 10
24COLON = 11
25COMMA = 12
26SEMI = 13
27PLUS = 14
28MINUS = 15
29STAR = 16
30SLASH = 17
31VBAR = 18
32AMPER = 19
33LESS = 20
34GREATER = 21
35EQUAL = 22
36DOT = 23
37PERCENT = 24
Meador Inge33880602012-01-15 19:15:36 -060038LBRACE = 25
39RBRACE = 26
40EQEQUAL = 27
41NOTEQUAL = 28
42LESSEQUAL = 29
43GREATEREQUAL = 30
44TILDE = 31
45CIRCUMFLEX = 32
46LEFTSHIFT = 33
47RIGHTSHIFT = 34
48DOUBLESTAR = 35
49PLUSEQUAL = 36
50MINEQUAL = 37
51STAREQUAL = 38
52SLASHEQUAL = 39
53PERCENTEQUAL = 40
54AMPEREQUAL = 41
55VBAREQUAL = 42
56CIRCUMFLEXEQUAL = 43
57LEFTSHIFTEQUAL = 44
58RIGHTSHIFTEQUAL = 45
59DOUBLESTAREQUAL = 46
60DOUBLESLASH = 47
61DOUBLESLASHEQUAL = 48
62AT = 49
63RARROW = 50
64ELLIPSIS = 51
65OP = 52
66ERRORTOKEN = 53
67N_TOKENS = 54
Guido van Rossum47478871996-08-21 14:32:37 +000068NT_OFFSET = 256
69#--end constants--
Guido van Rossumb31c7f71993-11-11 10:31:23 +000070
Alexander Belopolskyb9d10d02010-11-11 14:07:41 +000071tok_name = {value: name
72 for name, value in globals().items()
73 if isinstance(value, int)}
74__all__.extend(tok_name.values())
Guido van Rossumb31c7f71993-11-11 10:31:23 +000075
Guido van Rossum154a5391996-07-21 02:17:52 +000076def ISTERMINAL(x):
77 return x < NT_OFFSET
78
79def ISNONTERMINAL(x):
80 return x >= NT_OFFSET
81
82def ISEOF(x):
83 return x == ENDMARKER
Guido van Rossum47478871996-08-21 14:32:37 +000084
85
Alexander Belopolskyb9d10d02010-11-11 14:07:41 +000086def _main():
Guido van Rossum9694fca1997-10-22 21:00:49 +000087 import re
Guido van Rossum47478871996-08-21 14:32:37 +000088 import sys
89 args = sys.argv[1:]
90 inFileName = args and args[0] or "Include/token.h"
91 outFileName = "Lib/token.py"
92 if len(args) > 1:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000093 outFileName = args[1]
Guido van Rossum47478871996-08-21 14:32:37 +000094 try:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000095 fp = open(inFileName)
Guido van Rossumb940e112007-01-10 16:19:56 +000096 except IOError as err:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000097 sys.stdout.write("I/O error: %s\n" % str(err))
98 sys.exit(1)
Eric S. Raymondb08b2d32001-02-09 11:10:16 +000099 lines = fp.read().split("\n")
Guido van Rossum47478871996-08-21 14:32:37 +0000100 fp.close()
Guido van Rossum9694fca1997-10-22 21:00:49 +0000101 prog = re.compile(
Michael W. Hudsonadf16062002-10-03 09:42:01 +0000102 "#define[ \t][ \t]*([A-Z0-9][A-Z0-9_]*)[ \t][ \t]*([0-9][0-9]*)",
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000103 re.IGNORECASE)
Guido van Rossum47478871996-08-21 14:32:37 +0000104 tokens = {}
105 for line in lines:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000106 match = prog.match(line)
107 if match:
108 name, val = match.group(1, 2)
Eric S. Raymond6e025bc2001-02-10 00:22:33 +0000109 val = int(val)
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000110 tokens[val] = name # reverse so we can sort them...
Guido van Rossumc145ef32007-02-26 14:08:27 +0000111 keys = sorted(tokens.keys())
Guido van Rossum47478871996-08-21 14:32:37 +0000112 # load the output skeleton from the target:
113 try:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000114 fp = open(outFileName)
Guido van Rossumb940e112007-01-10 16:19:56 +0000115 except IOError as err:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000116 sys.stderr.write("I/O error: %s\n" % str(err))
117 sys.exit(2)
Eric S. Raymondb08b2d32001-02-09 11:10:16 +0000118 format = fp.read().split("\n")
Guido van Rossum47478871996-08-21 14:32:37 +0000119 fp.close()
120 try:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000121 start = format.index("#--start constants--") + 1
122 end = format.index("#--end constants--")
Guido van Rossum47478871996-08-21 14:32:37 +0000123 except ValueError:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000124 sys.stderr.write("target does not contain format markers")
125 sys.exit(3)
Guido van Rossum47478871996-08-21 14:32:37 +0000126 lines = []
127 for val in keys:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000128 lines.append("%s = %d" % (tokens[val], val))
Guido van Rossum47478871996-08-21 14:32:37 +0000129 format[start:end] = lines
130 try:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000131 fp = open(outFileName, 'w')
Guido van Rossumb940e112007-01-10 16:19:56 +0000132 except IOError as err:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000133 sys.stderr.write("I/O error: %s\n" % str(err))
134 sys.exit(4)
Eric S. Raymondb08b2d32001-02-09 11:10:16 +0000135 fp.write("\n".join(format))
Guido van Rossum47478871996-08-21 14:32:37 +0000136 fp.close()
137
138
139if __name__ == "__main__":
Alexander Belopolskyb9d10d02010-11-11 14:07:41 +0000140 _main()