svn-gvsig-desktop / tags / v1_0_2_Build_905 / extensions / extScripting / scripts / jython / Lib / token.py @ 10767
History | View | Annotate | Download (2.82 KB)
1 | 5782 | jmvivo | #! /usr/bin/env python
|
---|---|---|---|
2 | |||
3 | """Token constants (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 | # python Lib/token.py
|
||
11 | |||
12 | #--start constants--
|
||
13 | ENDMARKER = 0
|
||
14 | NAME = 1
|
||
15 | NUMBER = 2
|
||
16 | STRING = 3
|
||
17 | NEWLINE = 4
|
||
18 | INDENT = 5
|
||
19 | DEDENT = 6
|
||
20 | LPAR = 7
|
||
21 | RPAR = 8
|
||
22 | LSQB = 9
|
||
23 | RSQB = 10
|
||
24 | COLON = 11
|
||
25 | COMMA = 12
|
||
26 | SEMI = 13
|
||
27 | PLUS = 14
|
||
28 | MINUS = 15
|
||
29 | STAR = 16
|
||
30 | SLASH = 17
|
||
31 | VBAR = 18
|
||
32 | AMPER = 19
|
||
33 | LESS = 20
|
||
34 | GREATER = 21
|
||
35 | EQUAL = 22
|
||
36 | DOT = 23
|
||
37 | PERCENT = 24
|
||
38 | BACKQUOTE = 25
|
||
39 | LBRACE = 26
|
||
40 | RBRACE = 27
|
||
41 | EQEQUAL = 28
|
||
42 | NOTEQUAL = 29
|
||
43 | LESSEQUAL = 30
|
||
44 | GREATEREQUAL = 31
|
||
45 | TILDE = 32
|
||
46 | CIRCUMFLEX = 33
|
||
47 | LEFTSHIFT = 34
|
||
48 | RIGHTSHIFT = 35
|
||
49 | DOUBLESTAR = 36
|
||
50 | PLUSEQUAL = 37
|
||
51 | MINEQUAL = 38
|
||
52 | STAREQUAL = 39
|
||
53 | SLASHEQUAL = 40
|
||
54 | PERCENTEQUAL = 41
|
||
55 | AMPEREQUAL = 42
|
||
56 | VBAREQUAL = 43
|
||
57 | CIRCUMFLEXEQUAL = 44
|
||
58 | LEFTSHIFTEQUAL = 45
|
||
59 | RIGHTSHIFTEQUAL = 46
|
||
60 | DOUBLESTAREQUAL = 47
|
||
61 | OP = 48
|
||
62 | ERRORTOKEN = 49
|
||
63 | N_TOKENS = 50
|
||
64 | NT_OFFSET = 256
|
||
65 | #--end constants--
|
||
66 | |||
67 | tok_name = {} |
||
68 | for _name, _value in globals().items(): |
||
69 | if type(_value) is type(0): |
||
70 | tok_name[_value] = _name |
||
71 | |||
72 | |||
73 | def ISTERMINAL(x): |
||
74 | return x < NT_OFFSET
|
||
75 | |||
76 | def ISNONTERMINAL(x): |
||
77 | return x >= NT_OFFSET
|
||
78 | |||
79 | def ISEOF(x): |
||
80 | return x == ENDMARKER
|
||
81 | |||
82 | |||
83 | def main(): |
||
84 | import re |
||
85 | import string |
||
86 | import sys |
||
87 | args = sys.argv[1:]
|
||
88 | inFileName = args and args[0] or "Include/token.h" |
||
89 | outFileName = "Lib/token.py"
|
||
90 | if len(args) > 1: |
||
91 | outFileName = args[1]
|
||
92 | try:
|
||
93 | fp = open(inFileName)
|
||
94 | except IOError, err: |
||
95 | sys.stdout.write("I/O error: %s\n" % str(err)) |
||
96 | sys.exit(1)
|
||
97 | lines = fp.read().split("\n")
|
||
98 | fp.close() |
||
99 | prog = re.compile( |
||
100 | "#define[ \t][ \t]*([A-Z][A-Z_]*)[ \t][ \t]*([0-9][0-9]*)",
|
||
101 | re.IGNORECASE) |
||
102 | tokens = {} |
||
103 | for line in lines: |
||
104 | match = prog.match(line) |
||
105 | if match:
|
||
106 | name, val = match.group(1, 2) |
||
107 | val = int(val)
|
||
108 | tokens[val] = name # reverse so we can sort them...
|
||
109 | keys = tokens.keys() |
||
110 | keys.sort() |
||
111 | # load the output skeleton from the target:
|
||
112 | try:
|
||
113 | fp = open(outFileName)
|
||
114 | except IOError, err: |
||
115 | sys.stderr.write("I/O error: %s\n" % str(err)) |
||
116 | sys.exit(2)
|
||
117 | format = fp.read().split("\n")
|
||
118 | fp.close() |
||
119 | try:
|
||
120 | start = format.index("#--start constants--") + 1 |
||
121 | end = format.index("#--end constants--")
|
||
122 | except ValueError: |
||
123 | sys.stderr.write("target does not contain format markers")
|
||
124 | sys.exit(3)
|
||
125 | lines = [] |
||
126 | for val in keys: |
||
127 | lines.append("%s = %d" % (tokens[val], val))
|
||
128 | format[start:end] = lines |
||
129 | try:
|
||
130 | fp = open(outFileName, 'w') |
||
131 | except IOError, err: |
||
132 | sys.stderr.write("I/O error: %s\n" % str(err)) |
||
133 | sys.exit(4)
|
||
134 | fp.write("\n".join(format))
|
||
135 | fp.close() |
||
136 | |||
137 | |||
138 | if __name__ == "__main__": |
||
139 | main() |