ยปCore Development>Code coverage>Lib/token.py

Python code coverage for Lib/token.py

#countcontent
1n/a"""Token constants (from "token.h")."""
2n/a
3n/a__all__ = ['tok_name', 'ISTERMINAL', 'ISNONTERMINAL', 'ISEOF']
4n/a
5n/a# This file is automatically generated; please don't muck it up!
6n/a#
7n/a# To update the symbols in this file, 'cd' to the top directory of
8n/a# the python source tree after building the interpreter and run:
9n/a#
10n/a# ./python Lib/token.py
11n/a
12n/a#--start constants--
13n/aENDMARKER = 0
14n/aNAME = 1
15n/aNUMBER = 2
16n/aSTRING = 3
17n/aNEWLINE = 4
18n/aINDENT = 5
19n/aDEDENT = 6
20n/aLPAR = 7
21n/aRPAR = 8
22n/aLSQB = 9
23n/aRSQB = 10
24n/aCOLON = 11
25n/aCOMMA = 12
26n/aSEMI = 13
27n/aPLUS = 14
28n/aMINUS = 15
29n/aSTAR = 16
30n/aSLASH = 17
31n/aVBAR = 18
32n/aAMPER = 19
33n/aLESS = 20
34n/aGREATER = 21
35n/aEQUAL = 22
36n/aDOT = 23
37n/aPERCENT = 24
38n/aLBRACE = 25
39n/aRBRACE = 26
40n/aEQEQUAL = 27
41n/aNOTEQUAL = 28
42n/aLESSEQUAL = 29
43n/aGREATEREQUAL = 30
44n/aTILDE = 31
45n/aCIRCUMFLEX = 32
46n/aLEFTSHIFT = 33
47n/aRIGHTSHIFT = 34
48n/aDOUBLESTAR = 35
49n/aPLUSEQUAL = 36
50n/aMINEQUAL = 37
51n/aSTAREQUAL = 38
52n/aSLASHEQUAL = 39
53n/aPERCENTEQUAL = 40
54n/aAMPEREQUAL = 41
55n/aVBAREQUAL = 42
56n/aCIRCUMFLEXEQUAL = 43
57n/aLEFTSHIFTEQUAL = 44
58n/aRIGHTSHIFTEQUAL = 45
59n/aDOUBLESTAREQUAL = 46
60n/aDOUBLESLASH = 47
61n/aDOUBLESLASHEQUAL = 48
62n/aAT = 49
63n/aATEQUAL = 50
64n/aRARROW = 51
65n/aELLIPSIS = 52
66n/aOP = 53
67n/aAWAIT = 54
68n/aASYNC = 55
69n/aERRORTOKEN = 56
70n/aN_TOKENS = 57
71n/aNT_OFFSET = 256
72n/a#--end constants--
73n/a
74n/atok_name = {value: name
75n/a for name, value in globals().items()
76n/a if isinstance(value, int) and not name.startswith('_')}
77n/a__all__.extend(tok_name.values())
78n/a
79n/adef ISTERMINAL(x):
80n/a return x < NT_OFFSET
81n/a
82n/adef ISNONTERMINAL(x):
83n/a return x >= NT_OFFSET
84n/a
85n/adef ISEOF(x):
86n/a return x == ENDMARKER
87n/a
88n/a
89n/adef _main():
90n/a import re
91n/a import sys
92n/a args = sys.argv[1:]
93n/a inFileName = args and args[0] or "Include/token.h"
94n/a outFileName = "Lib/token.py"
95n/a if len(args) > 1:
96n/a outFileName = args[1]
97n/a try:
98n/a fp = open(inFileName)
99n/a except OSError as err:
100n/a sys.stdout.write("I/O error: %s\n" % str(err))
101n/a sys.exit(1)
102n/a with fp:
103n/a lines = fp.read().split("\n")
104n/a prog = re.compile(
105n/a "#define[ \t][ \t]*([A-Z0-9][A-Z0-9_]*)[ \t][ \t]*([0-9][0-9]*)",
106n/a re.IGNORECASE)
107n/a tokens = {}
108n/a for line in lines:
109n/a match = prog.match(line)
110n/a if match:
111n/a name, val = match.group(1, 2)
112n/a val = int(val)
113n/a tokens[val] = name # reverse so we can sort them...
114n/a keys = sorted(tokens.keys())
115n/a # load the output skeleton from the target:
116n/a try:
117n/a fp = open(outFileName)
118n/a except OSError as err:
119n/a sys.stderr.write("I/O error: %s\n" % str(err))
120n/a sys.exit(2)
121n/a with fp:
122n/a format = fp.read().split("\n")
123n/a try:
124n/a start = format.index("#--start constants--") + 1
125n/a end = format.index("#--end constants--")
126n/a except ValueError:
127n/a sys.stderr.write("target does not contain format markers")
128n/a sys.exit(3)
129n/a lines = []
130n/a for val in keys:
131n/a lines.append("%s = %d" % (tokens[val], val))
132n/a format[start:end] = lines
133n/a try:
134n/a fp = open(outFileName, 'w')
135n/a except OSError as err:
136n/a sys.stderr.write("I/O error: %s\n" % str(err))
137n/a sys.exit(4)
138n/a with fp:
139n/a fp.write("\n".join(format))
140n/a
141n/a
142n/aif __name__ == "__main__":
143n/a _main()