blob: eb48e76db81d224fb2273ae320b4ad17379de4c4 [file] [log] [blame]
Guido van Rossum47478871996-08-21 14:32:37 +00001#! /usr/bin/env python
Guido van Rossume7b146f2000-02-04 15:28:42 +00002
3"""Token constants (from "token.h")."""
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#
Guido van Rossum9694fca1997-10-22 21:00:49 +000010# 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
Guido van Rossumb31c7f71993-11-11 10:31:23 +000038LBRACE = 26
39RBRACE = 27
40EQEQUAL = 28
41NOTEQUAL = 29
42LESSEQUAL = 30
43GREATEREQUAL = 31
44TILDE = 32
45CIRCUMFLEX = 33
46LEFTSHIFT = 34
47RIGHTSHIFT = 35
Guido van Rossum154a5391996-07-21 02:17:52 +000048DOUBLESTAR = 36
Thomas Wouters34052622000-08-24 21:08:39 +000049PLUSEQUAL = 37
50MINEQUAL = 38
51STAREQUAL = 39
52SLASHEQUAL = 40
53PERCENTEQUAL = 41
54AMPEREQUAL = 42
55VBAREQUAL = 43
56CIRCUMFLEXEQUAL = 44
57LEFTSHIFTEQUAL = 45
58RIGHTSHIFTEQUAL = 46
59DOUBLESTAREQUAL = 47
Tim Petersa38d2602001-08-08 06:35:56 +000060DOUBLESLASH = 48
61DOUBLESLASHEQUAL = 49
Anthony Baxterc2a5a632004-08-02 06:10:11 +000062AT = 50
Neal Norwitzc1505362006-12-28 06:47:50 +000063RARROW = 51
Georg Brandldde00282007-03-18 19:01:53 +000064ELLIPSIS = 52
65OP = 53
66ERRORTOKEN = 54
67N_TOKENS = 55
Guido van Rossum47478871996-08-21 14:32:37 +000068NT_OFFSET = 256
69#--end constants--
Guido van Rossumb31c7f71993-11-11 10:31:23 +000070
Guido van Rossumb31c7f71993-11-11 10:31:23 +000071tok_name = {}
Guido van Rossumcc2b0162007-02-11 06:12:03 +000072for _name, _value in list(globals().items()):
Fred Drakee3dbc7e1997-10-06 21:28:04 +000073 if type(_value) is type(0):
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000074 tok_name[_value] = _name
Fred Drakee3dbc7e1997-10-06 21:28:04 +000075
Guido van Rossumb31c7f71993-11-11 10:31:23 +000076
Guido van Rossum154a5391996-07-21 02:17:52 +000077def ISTERMINAL(x):
78 return x < NT_OFFSET
79
80def ISNONTERMINAL(x):
81 return x >= NT_OFFSET
82
83def ISEOF(x):
84 return x == ENDMARKER
Guido van Rossum47478871996-08-21 14:32:37 +000085
86
87def main():
Guido van Rossum9694fca1997-10-22 21:00:49 +000088 import re
Guido van Rossum47478871996-08-21 14:32:37 +000089 import sys
90 args = sys.argv[1:]
91 inFileName = args and args[0] or "Include/token.h"
92 outFileName = "Lib/token.py"
93 if len(args) > 1:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000094 outFileName = args[1]
Guido van Rossum47478871996-08-21 14:32:37 +000095 try:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000096 fp = open(inFileName)
Guido van Rossumb940e112007-01-10 16:19:56 +000097 except IOError as err:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000098 sys.stdout.write("I/O error: %s\n" % str(err))
99 sys.exit(1)
Eric S. Raymondb08b2d32001-02-09 11:10:16 +0000100 lines = fp.read().split("\n")
Guido van Rossum47478871996-08-21 14:32:37 +0000101 fp.close()
Guido van Rossum9694fca1997-10-22 21:00:49 +0000102 prog = re.compile(
Michael W. Hudsonadf16062002-10-03 09:42:01 +0000103 "#define[ \t][ \t]*([A-Z0-9][A-Z0-9_]*)[ \t][ \t]*([0-9][0-9]*)",
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000104 re.IGNORECASE)
Guido van Rossum47478871996-08-21 14:32:37 +0000105 tokens = {}
106 for line in lines:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000107 match = prog.match(line)
108 if match:
109 name, val = match.group(1, 2)
Eric S. Raymond6e025bc2001-02-10 00:22:33 +0000110 val = int(val)
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000111 tokens[val] = name # reverse so we can sort them...
Guido van Rossumc145ef32007-02-26 14:08:27 +0000112 keys = sorted(tokens.keys())
Guido van Rossum47478871996-08-21 14:32:37 +0000113 # load the output skeleton from the target:
114 try:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000115 fp = open(outFileName)
Guido van Rossumb940e112007-01-10 16:19:56 +0000116 except IOError as err:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000117 sys.stderr.write("I/O error: %s\n" % str(err))
118 sys.exit(2)
Eric S. Raymondb08b2d32001-02-09 11:10:16 +0000119 format = fp.read().split("\n")
Guido van Rossum47478871996-08-21 14:32:37 +0000120 fp.close()
121 try:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000122 start = format.index("#--start constants--") + 1
123 end = format.index("#--end constants--")
Guido van Rossum47478871996-08-21 14:32:37 +0000124 except ValueError:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000125 sys.stderr.write("target does not contain format markers")
126 sys.exit(3)
Guido van Rossum47478871996-08-21 14:32:37 +0000127 lines = []
128 for val in keys:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000129 lines.append("%s = %d" % (tokens[val], val))
Guido van Rossum47478871996-08-21 14:32:37 +0000130 format[start:end] = lines
131 try:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000132 fp = open(outFileName, 'w')
Guido van Rossumb940e112007-01-10 16:19:56 +0000133 except IOError as err:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000134 sys.stderr.write("I/O error: %s\n" % str(err))
135 sys.exit(4)
Eric S. Raymondb08b2d32001-02-09 11:10:16 +0000136 fp.write("\n".join(format))
Guido van Rossum47478871996-08-21 14:32:37 +0000137 fp.close()
138
139
140if __name__ == "__main__":
141 main()