blob: da4d29b3263d63cf95dc100ec22c8f788e1f7b49 [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
Christian Heimes836baa52008-02-26 08:18:30 +000075del _name, _value
Fred Drakee3dbc7e1997-10-06 21:28:04 +000076
Guido van Rossumb31c7f71993-11-11 10:31:23 +000077
Guido van Rossum154a5391996-07-21 02:17:52 +000078def ISTERMINAL(x):
79 return x < NT_OFFSET
80
81def ISNONTERMINAL(x):
82 return x >= NT_OFFSET
83
84def ISEOF(x):
85 return x == ENDMARKER
Guido van Rossum47478871996-08-21 14:32:37 +000086
87
88def main():
Guido van Rossum9694fca1997-10-22 21:00:49 +000089 import re
Guido van Rossum47478871996-08-21 14:32:37 +000090 import sys
91 args = sys.argv[1:]
92 inFileName = args and args[0] or "Include/token.h"
93 outFileName = "Lib/token.py"
94 if len(args) > 1:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000095 outFileName = args[1]
Guido van Rossum47478871996-08-21 14:32:37 +000096 try:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000097 fp = open(inFileName)
Guido van Rossumb940e112007-01-10 16:19:56 +000098 except IOError as err:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000099 sys.stdout.write("I/O error: %s\n" % str(err))
100 sys.exit(1)
Eric S. Raymondb08b2d32001-02-09 11:10:16 +0000101 lines = fp.read().split("\n")
Guido van Rossum47478871996-08-21 14:32:37 +0000102 fp.close()
Guido van Rossum9694fca1997-10-22 21:00:49 +0000103 prog = re.compile(
Michael W. Hudsonadf16062002-10-03 09:42:01 +0000104 "#define[ \t][ \t]*([A-Z0-9][A-Z0-9_]*)[ \t][ \t]*([0-9][0-9]*)",
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000105 re.IGNORECASE)
Guido van Rossum47478871996-08-21 14:32:37 +0000106 tokens = {}
107 for line in lines:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000108 match = prog.match(line)
109 if match:
110 name, val = match.group(1, 2)
Eric S. Raymond6e025bc2001-02-10 00:22:33 +0000111 val = int(val)
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000112 tokens[val] = name # reverse so we can sort them...
Guido van Rossumc145ef32007-02-26 14:08:27 +0000113 keys = sorted(tokens.keys())
Guido van Rossum47478871996-08-21 14:32:37 +0000114 # load the output skeleton from the target:
115 try:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000116 fp = open(outFileName)
Guido van Rossumb940e112007-01-10 16:19:56 +0000117 except IOError as err:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000118 sys.stderr.write("I/O error: %s\n" % str(err))
119 sys.exit(2)
Eric S. Raymondb08b2d32001-02-09 11:10:16 +0000120 format = fp.read().split("\n")
Guido van Rossum47478871996-08-21 14:32:37 +0000121 fp.close()
122 try:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000123 start = format.index("#--start constants--") + 1
124 end = format.index("#--end constants--")
Guido van Rossum47478871996-08-21 14:32:37 +0000125 except ValueError:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000126 sys.stderr.write("target does not contain format markers")
127 sys.exit(3)
Guido van Rossum47478871996-08-21 14:32:37 +0000128 lines = []
129 for val in keys:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000130 lines.append("%s = %d" % (tokens[val], val))
Guido van Rossum47478871996-08-21 14:32:37 +0000131 format[start:end] = lines
132 try:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000133 fp = open(outFileName, 'w')
Guido van Rossumb940e112007-01-10 16:19:56 +0000134 except IOError as err:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000135 sys.stderr.write("I/O error: %s\n" % str(err))
136 sys.exit(4)
Eric S. Raymondb08b2d32001-02-09 11:10:16 +0000137 fp.write("\n".join(format))
Guido van Rossum47478871996-08-21 14:32:37 +0000138 fp.close()
139
140
141if __name__ == "__main__":
142 main()