annotate Lib/token.py @ 5817:48b94de85bf3 legacy-trunk

Extensive changes by AMK.
author Guido van Rossum <guido@python.org>
date Thu, 17 Jul 1997 16:29:42 +0000
parents 7f83e24d1d86
children 81154a51c16e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4084
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
1 #! /usr/bin/env python
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
2 #
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
3 # Tokens (from "token.h")
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
4 #
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
5 # This file is automatically generated; please don't muck it up!
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
6 #
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
7 # To update the symbols in this file, 'cd' to the top directory of
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
8 # the python source tree after building the interpreter and run:
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
9 #
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
10 # PYTHONPATH=./Lib ./python Lib/token.py
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
11 #
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
12 # (this path allows the import of string.py and regexmodule.so
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
13 # for a site with no installation in place)
1407
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
14
4084
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
15 #--start constants--
1407
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 ENDMARKER = 0
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 NAME = 1
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 NUMBER = 2
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 STRING = 3
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 NEWLINE = 4
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 INDENT = 5
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 DEDENT = 6
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 LPAR = 7
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 RPAR = 8
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 LSQB = 9
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 RSQB = 10
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 COLON = 11
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 COMMA = 12
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 SEMI = 13
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 PLUS = 14
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 MINUS = 15
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 STAR = 16
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 SLASH = 17
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 VBAR = 18
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 AMPER = 19
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 LESS = 20
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 GREATER = 21
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 EQUAL = 22
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 DOT = 23
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 PERCENT = 24
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 BACKQUOTE = 25
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 LBRACE = 26
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 RBRACE = 27
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 EQEQUAL = 28
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 NOTEQUAL = 29
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 LESSEQUAL = 30
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 GREATEREQUAL = 31
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 TILDE = 32
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 CIRCUMFLEX = 33
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 LEFTSHIFT = 34
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 RIGHTSHIFT = 35
3754
d23fea248a1e Changes for new parser module (Fred Drake)
Guido van Rossum <guido@python.org>
parents: 1407
diff changeset
52 DOUBLESTAR = 36
d23fea248a1e Changes for new parser module (Fred Drake)
Guido van Rossum <guido@python.org>
parents: 1407
diff changeset
53 OP = 37
d23fea248a1e Changes for new parser module (Fred Drake)
Guido van Rossum <guido@python.org>
parents: 1407
diff changeset
54 ERRORTOKEN = 38
4084
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
55 N_TOKENS = 39
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
56 NT_OFFSET = 256
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
57 #--end constants--
1407
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
58
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 names = dir()
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 tok_name = {}
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 for name in names:
3754
d23fea248a1e Changes for new parser module (Fred Drake)
Guido van Rossum <guido@python.org>
parents: 1407
diff changeset
62 number = eval(name)
d23fea248a1e Changes for new parser module (Fred Drake)
Guido van Rossum <guido@python.org>
parents: 1407
diff changeset
63 if type(number) is type(0):
1407
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 tok_name[number] = name
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
65
3754
d23fea248a1e Changes for new parser module (Fred Drake)
Guido van Rossum <guido@python.org>
parents: 1407
diff changeset
66 def ISTERMINAL(x):
d23fea248a1e Changes for new parser module (Fred Drake)
Guido van Rossum <guido@python.org>
parents: 1407
diff changeset
67 return x < NT_OFFSET
1407
b9fcfb99a3e5 * test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff changeset
68
3754
d23fea248a1e Changes for new parser module (Fred Drake)
Guido van Rossum <guido@python.org>
parents: 1407
diff changeset
69 def ISNONTERMINAL(x):
d23fea248a1e Changes for new parser module (Fred Drake)
Guido van Rossum <guido@python.org>
parents: 1407
diff changeset
70 return x >= NT_OFFSET
d23fea248a1e Changes for new parser module (Fred Drake)
Guido van Rossum <guido@python.org>
parents: 1407
diff changeset
71
d23fea248a1e Changes for new parser module (Fred Drake)
Guido van Rossum <guido@python.org>
parents: 1407
diff changeset
72 def ISEOF(x):
d23fea248a1e Changes for new parser module (Fred Drake)
Guido van Rossum <guido@python.org>
parents: 1407
diff changeset
73 return x == ENDMARKER
4084
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
74
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
75
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
76 def main():
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
77 import regex
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
78 import string
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
79 import sys
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
80 args = sys.argv[1:]
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
81 inFileName = args and args[0] or "Include/token.h"
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
82 outFileName = "Lib/token.py"
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
83 if len(args) > 1:
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
84 outFileName = args[1]
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
85 try:
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
86 fp = open(inFileName)
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
87 except IOError, err:
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
88 sys.stdout.write("I/O error: %s\n" % str(err))
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
89 sys.exit(1)
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
90 lines = string.splitfields(fp.read(), "\n")
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
91 fp.close()
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
92 re = regex.compile(
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
93 "#define[ \t][ \t]*\([A-Z][A-Z_]*\)[ \t][ \t]*\([0-9][0-9]*\)",
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
94 regex.casefold)
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
95 tokens = {}
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
96 for line in lines:
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
97 if re.match(line) > -1:
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
98 name, val = re.group(1, 2)
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
99 val = string.atoi(val)
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
100 tokens[val] = name # reverse so we can sort them...
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
101 keys = tokens.keys()
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
102 keys.sort()
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
103 # load the output skeleton from the target:
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
104 try:
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
105 fp = open(outFileName)
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
106 except IOError, err:
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
107 sys.stderr.write("I/O error: %s\n" % str(err))
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
108 sys.exit(2)
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
109 format = string.splitfields(fp.read(), "\n")
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
110 fp.close()
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
111 try:
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
112 start = format.index("#--start constants--") + 1
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
113 end = format.index("#--end constants--")
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
114 except ValueError:
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
115 sys.stderr.write("target does not contain format markers")
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
116 sys.exit(3)
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
117 lines = []
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
118 for val in keys:
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
119 lines.append("%s = %d" % (tokens[val], val))
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
120 format[start:end] = lines
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
121 try:
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
122 fp = open(outFileName, 'w')
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
123 except IOError, err:
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
124 sys.stderr.write("I/O error: %s\n" % str(err))
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
125 sys.exit(4)
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
126 fp.write(string.joinfields(format, "\n"))
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
127 fp.close()
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
128
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
129
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
130 if __name__ == "__main__":
7f83e24d1d86 New batch from Fred
Guido van Rossum <guido@python.org>
parents: 3754
diff changeset
131 main()