blob: 5fdb2221333e2c855461df5e33f32883e41f381d [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
Benjamin Petersond51374e2014-04-09 23:55:56 -040063ATEQUAL = 50
64RARROW = 51
65ELLIPSIS = 52
66OP = 53
Yury Selivanov75445082015-05-11 22:57:16 -040067AWAIT = 54
68ASYNC = 55
69ERRORTOKEN = 56
70N_TOKENS = 57
Guido van Rossum47478871996-08-21 14:32:37 +000071NT_OFFSET = 256
72#--end constants--
Guido van Rossumb31c7f71993-11-11 10:31:23 +000073
Alexander Belopolskyb9d10d02010-11-11 14:07:41 +000074tok_name = {value: name
75 for name, value in globals().items()
Antoine Pitrouea3eb882012-05-17 18:55:59 +020076 if isinstance(value, int) and not name.startswith('_')}
Alexander Belopolskyb9d10d02010-11-11 14:07:41 +000077__all__.extend(tok_name.values())
Guido van Rossumb31c7f71993-11-11 10:31:23 +000078
Guido van Rossum154a5391996-07-21 02:17:52 +000079def ISTERMINAL(x):
80 return x < NT_OFFSET
81
82def ISNONTERMINAL(x):
83 return x >= NT_OFFSET
84
85def ISEOF(x):
86 return x == ENDMARKER
Guido van Rossum47478871996-08-21 14:32:37 +000087
88
Alexander Belopolskyb9d10d02010-11-11 14:07:41 +000089def _main():
Guido van Rossum9694fca1997-10-22 21:00:49 +000090 import re
Guido van Rossum47478871996-08-21 14:32:37 +000091 import sys
92 args = sys.argv[1:]
93 inFileName = args and args[0] or "Include/token.h"
94 outFileName = "Lib/token.py"
95 if len(args) > 1:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000096 outFileName = args[1]
Guido van Rossum47478871996-08-21 14:32:37 +000097 try:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +000098 fp = open(inFileName)
Andrew Svetlovf7a17b42012-12-25 16:47:37 +020099 except OSError as err:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000100 sys.stdout.write("I/O error: %s\n" % str(err))
101 sys.exit(1)
Serhiy Storchaka46ba6c82015-04-04 11:01:02 +0300102 with fp:
103 lines = fp.read().split("\n")
Guido van Rossum9694fca1997-10-22 21:00:49 +0000104 prog = re.compile(
Michael W. Hudsonadf16062002-10-03 09:42:01 +0000105 "#define[ \t][ \t]*([A-Z0-9][A-Z0-9_]*)[ \t][ \t]*([0-9][0-9]*)",
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000106 re.IGNORECASE)
Guido van Rossum47478871996-08-21 14:32:37 +0000107 tokens = {}
108 for line in lines:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000109 match = prog.match(line)
110 if match:
111 name, val = match.group(1, 2)
Eric S. Raymond6e025bc2001-02-10 00:22:33 +0000112 val = int(val)
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000113 tokens[val] = name # reverse so we can sort them...
Guido van Rossumc145ef32007-02-26 14:08:27 +0000114 keys = sorted(tokens.keys())
Guido van Rossum47478871996-08-21 14:32:37 +0000115 # load the output skeleton from the target:
116 try:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000117 fp = open(outFileName)
Andrew Svetlovf7a17b42012-12-25 16:47:37 +0200118 except OSError as err:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000119 sys.stderr.write("I/O error: %s\n" % str(err))
120 sys.exit(2)
Serhiy Storchaka46ba6c82015-04-04 11:01:02 +0300121 with fp:
122 format = fp.read().split("\n")
Guido van Rossum47478871996-08-21 14:32:37 +0000123 try:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000124 start = format.index("#--start constants--") + 1
125 end = format.index("#--end constants--")
Guido van Rossum47478871996-08-21 14:32:37 +0000126 except ValueError:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000127 sys.stderr.write("target does not contain format markers")
128 sys.exit(3)
Guido van Rossum47478871996-08-21 14:32:37 +0000129 lines = []
130 for val in keys:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000131 lines.append("%s = %d" % (tokens[val], val))
Guido van Rossum47478871996-08-21 14:32:37 +0000132 format[start:end] = lines
133 try:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000134 fp = open(outFileName, 'w')
Andrew Svetlovf7a17b42012-12-25 16:47:37 +0200135 except OSError as err:
Guido van Rossum45e2fbc1998-03-26 21:13:24 +0000136 sys.stderr.write("I/O error: %s\n" % str(err))
137 sys.exit(4)
Serhiy Storchaka46ba6c82015-04-04 11:01:02 +0300138 with fp:
139 fp.write("\n".join(format))
Guido van Rossum47478871996-08-21 14:32:37 +0000140
141
142if __name__ == "__main__":
Alexander Belopolskyb9d10d02010-11-11 14:07:41 +0000143 _main()