Mercurial > cpython-lru_cache-weakref
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 |
| rev | line source |
|---|---|
| 4084 | 1 #! /usr/bin/env python |
| 2 # | |
| 3 # Tokens (from "token.h") | |
| 4 # | |
| 5 # 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 # | |
| 10 # PYTHONPATH=./Lib ./python Lib/token.py | |
| 11 # | |
| 12 # (this path allows the import of string.py and regexmodule.so | |
| 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 | 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 | 55 N_TOKENS = 39 |
| 56 NT_OFFSET = 256 | |
| 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 | 74 |
| 75 | |
| 76 def main(): | |
| 77 import regex | |
| 78 import string | |
| 79 import sys | |
| 80 args = sys.argv[1:] | |
| 81 inFileName = args and args[0] or "Include/token.h" | |
| 82 outFileName = "Lib/token.py" | |
| 83 if len(args) > 1: | |
| 84 outFileName = args[1] | |
| 85 try: | |
| 86 fp = open(inFileName) | |
| 87 except IOError, err: | |
| 88 sys.stdout.write("I/O error: %s\n" % str(err)) | |
| 89 sys.exit(1) | |
| 90 lines = string.splitfields(fp.read(), "\n") | |
| 91 fp.close() | |
| 92 re = regex.compile( | |
| 93 "#define[ \t][ \t]*\([A-Z][A-Z_]*\)[ \t][ \t]*\([0-9][0-9]*\)", | |
| 94 regex.casefold) | |
| 95 tokens = {} | |
| 96 for line in lines: | |
| 97 if re.match(line) > -1: | |
| 98 name, val = re.group(1, 2) | |
| 99 val = string.atoi(val) | |
| 100 tokens[val] = name # reverse so we can sort them... | |
| 101 keys = tokens.keys() | |
| 102 keys.sort() | |
| 103 # load the output skeleton from the target: | |
| 104 try: | |
| 105 fp = open(outFileName) | |
| 106 except IOError, err: | |
| 107 sys.stderr.write("I/O error: %s\n" % str(err)) | |
| 108 sys.exit(2) | |
| 109 format = string.splitfields(fp.read(), "\n") | |
| 110 fp.close() | |
| 111 try: | |
| 112 start = format.index("#--start constants--") + 1 | |
| 113 end = format.index("#--end constants--") | |
| 114 except ValueError: | |
| 115 sys.stderr.write("target does not contain format markers") | |
| 116 sys.exit(3) | |
| 117 lines = [] | |
| 118 for val in keys: | |
| 119 lines.append("%s = %d" % (tokens[val], val)) | |
| 120 format[start:end] = lines | |
| 121 try: | |
| 122 fp = open(outFileName, 'w') | |
| 123 except IOError, err: | |
| 124 sys.stderr.write("I/O error: %s\n" % str(err)) | |
| 125 sys.exit(4) | |
| 126 fp.write(string.joinfields(format, "\n")) | |
| 127 fp.close() | |
| 128 | |
| 129 | |
| 130 if __name__ == "__main__": | |
| 131 main() |
