svn-gvsig-desktop / tags / v1_1_Build_1000 / extensions / extScripting / scripts / jython / Lib / sre_constants.py @ 11885
History | View | Annotate | Download (6.82 KB)
1 |
#
|
---|---|
2 |
# Secret Labs' Regular Expression Engine
|
3 |
#
|
4 |
# various symbols used by the regular expression engine.
|
5 |
# run this script to update the _sre include files!
|
6 |
#
|
7 |
# Copyright (c) 1998-2001 by Secret Labs AB. All rights reserved.
|
8 |
#
|
9 |
# See the sre.py file for information on usage and redistribution.
|
10 |
#
|
11 |
|
12 |
# update when constants are added or removed
|
13 |
|
14 |
MAGIC = 20010320
|
15 |
|
16 |
# max code word in this release
|
17 |
|
18 |
MAXREPEAT = 65535
|
19 |
|
20 |
# SRE standard exception (access as sre.error)
|
21 |
# should this really be here?
|
22 |
|
23 |
class error(Exception): |
24 |
pass
|
25 |
|
26 |
# operators
|
27 |
|
28 |
FAILURE = "failure"
|
29 |
SUCCESS = "success"
|
30 |
|
31 |
ANY = "any"
|
32 |
ANY_ALL = "any_all"
|
33 |
ASSERT = "assert"
|
34 |
ASSERT_NOT = "assert_not"
|
35 |
AT = "at"
|
36 |
BRANCH = "branch"
|
37 |
CALL = "call"
|
38 |
CATEGORY = "category"
|
39 |
CHARSET = "charset"
|
40 |
GROUPREF = "groupref"
|
41 |
GROUPREF_IGNORE = "groupref_ignore"
|
42 |
IN = "in"
|
43 |
IN_IGNORE = "in_ignore"
|
44 |
INFO = "info"
|
45 |
JUMP = "jump"
|
46 |
LITERAL = "literal"
|
47 |
LITERAL_IGNORE = "literal_ignore"
|
48 |
MARK = "mark"
|
49 |
MAX_REPEAT = "max_repeat"
|
50 |
MAX_UNTIL = "max_until"
|
51 |
MIN_REPEAT = "min_repeat"
|
52 |
MIN_UNTIL = "min_until"
|
53 |
NEGATE = "negate"
|
54 |
NOT_LITERAL = "not_literal"
|
55 |
NOT_LITERAL_IGNORE = "not_literal_ignore"
|
56 |
RANGE = "range"
|
57 |
REPEAT = "repeat"
|
58 |
REPEAT_ONE = "repeat_one"
|
59 |
SUBPATTERN = "subpattern"
|
60 |
|
61 |
# positions
|
62 |
AT_BEGINNING = "at_beginning"
|
63 |
AT_BEGINNING_LINE = "at_beginning_line"
|
64 |
AT_BEGINNING_STRING = "at_beginning_string"
|
65 |
AT_BOUNDARY = "at_boundary"
|
66 |
AT_NON_BOUNDARY = "at_non_boundary"
|
67 |
AT_END = "at_end"
|
68 |
AT_END_LINE = "at_end_line"
|
69 |
AT_END_STRING = "at_end_string"
|
70 |
AT_LOC_BOUNDARY = "at_loc_boundary"
|
71 |
AT_LOC_NON_BOUNDARY = "at_loc_non_boundary"
|
72 |
AT_UNI_BOUNDARY = "at_uni_boundary"
|
73 |
AT_UNI_NON_BOUNDARY = "at_uni_non_boundary"
|
74 |
|
75 |
# categories
|
76 |
CATEGORY_DIGIT = "category_digit"
|
77 |
CATEGORY_NOT_DIGIT = "category_not_digit"
|
78 |
CATEGORY_SPACE = "category_space"
|
79 |
CATEGORY_NOT_SPACE = "category_not_space"
|
80 |
CATEGORY_WORD = "category_word"
|
81 |
CATEGORY_NOT_WORD = "category_not_word"
|
82 |
CATEGORY_LINEBREAK = "category_linebreak"
|
83 |
CATEGORY_NOT_LINEBREAK = "category_not_linebreak"
|
84 |
CATEGORY_LOC_WORD = "category_loc_word"
|
85 |
CATEGORY_LOC_NOT_WORD = "category_loc_not_word"
|
86 |
CATEGORY_UNI_DIGIT = "category_uni_digit"
|
87 |
CATEGORY_UNI_NOT_DIGIT = "category_uni_not_digit"
|
88 |
CATEGORY_UNI_SPACE = "category_uni_space"
|
89 |
CATEGORY_UNI_NOT_SPACE = "category_uni_not_space"
|
90 |
CATEGORY_UNI_WORD = "category_uni_word"
|
91 |
CATEGORY_UNI_NOT_WORD = "category_uni_not_word"
|
92 |
CATEGORY_UNI_LINEBREAK = "category_uni_linebreak"
|
93 |
CATEGORY_UNI_NOT_LINEBREAK = "category_uni_not_linebreak"
|
94 |
|
95 |
OPCODES = [ |
96 |
|
97 |
# failure=0 success=1 (just because it looks better that way :-)
|
98 |
FAILURE, SUCCESS, |
99 |
|
100 |
ANY, ANY_ALL, |
101 |
ASSERT, ASSERT_NOT, |
102 |
AT, |
103 |
BRANCH, |
104 |
CALL, |
105 |
CATEGORY, |
106 |
CHARSET, |
107 |
GROUPREF, GROUPREF_IGNORE, |
108 |
IN, IN_IGNORE, |
109 |
INFO, |
110 |
JUMP, |
111 |
LITERAL, LITERAL_IGNORE, |
112 |
MARK, |
113 |
MAX_UNTIL, |
114 |
MIN_UNTIL, |
115 |
NOT_LITERAL, NOT_LITERAL_IGNORE, |
116 |
NEGATE, |
117 |
RANGE, |
118 |
REPEAT, |
119 |
REPEAT_ONE, |
120 |
SUBPATTERN |
121 |
|
122 |
] |
123 |
|
124 |
ATCODES = [ |
125 |
AT_BEGINNING, AT_BEGINNING_LINE, AT_BEGINNING_STRING, AT_BOUNDARY, |
126 |
AT_NON_BOUNDARY, AT_END, AT_END_LINE, AT_END_STRING, |
127 |
AT_LOC_BOUNDARY, AT_LOC_NON_BOUNDARY, AT_UNI_BOUNDARY, |
128 |
AT_UNI_NON_BOUNDARY |
129 |
] |
130 |
|
131 |
CHCODES = [ |
132 |
CATEGORY_DIGIT, CATEGORY_NOT_DIGIT, CATEGORY_SPACE, |
133 |
CATEGORY_NOT_SPACE, CATEGORY_WORD, CATEGORY_NOT_WORD, |
134 |
CATEGORY_LINEBREAK, CATEGORY_NOT_LINEBREAK, CATEGORY_LOC_WORD, |
135 |
CATEGORY_LOC_NOT_WORD, CATEGORY_UNI_DIGIT, CATEGORY_UNI_NOT_DIGIT, |
136 |
CATEGORY_UNI_SPACE, CATEGORY_UNI_NOT_SPACE, CATEGORY_UNI_WORD, |
137 |
CATEGORY_UNI_NOT_WORD, CATEGORY_UNI_LINEBREAK, |
138 |
CATEGORY_UNI_NOT_LINEBREAK |
139 |
] |
140 |
|
141 |
def makedict(list): |
142 |
d = {} |
143 |
i = 0
|
144 |
for item in list: |
145 |
d[item] = i |
146 |
i = i + 1
|
147 |
return d
|
148 |
|
149 |
OPCODES = makedict(OPCODES) |
150 |
ATCODES = makedict(ATCODES) |
151 |
CHCODES = makedict(CHCODES) |
152 |
|
153 |
# replacement operations for "ignore case" mode
|
154 |
OP_IGNORE = { |
155 |
GROUPREF: GROUPREF_IGNORE, |
156 |
IN: IN_IGNORE, |
157 |
LITERAL: LITERAL_IGNORE, |
158 |
NOT_LITERAL: NOT_LITERAL_IGNORE |
159 |
} |
160 |
|
161 |
AT_MULTILINE = { |
162 |
AT_BEGINNING: AT_BEGINNING_LINE, |
163 |
AT_END: AT_END_LINE |
164 |
} |
165 |
|
166 |
AT_LOCALE = { |
167 |
AT_BOUNDARY: AT_LOC_BOUNDARY, |
168 |
AT_NON_BOUNDARY: AT_LOC_NON_BOUNDARY |
169 |
} |
170 |
|
171 |
AT_UNICODE = { |
172 |
AT_BOUNDARY: AT_UNI_BOUNDARY, |
173 |
AT_NON_BOUNDARY: AT_UNI_NON_BOUNDARY |
174 |
} |
175 |
|
176 |
CH_LOCALE = { |
177 |
CATEGORY_DIGIT: CATEGORY_DIGIT, |
178 |
CATEGORY_NOT_DIGIT: CATEGORY_NOT_DIGIT, |
179 |
CATEGORY_SPACE: CATEGORY_SPACE, |
180 |
CATEGORY_NOT_SPACE: CATEGORY_NOT_SPACE, |
181 |
CATEGORY_WORD: CATEGORY_LOC_WORD, |
182 |
CATEGORY_NOT_WORD: CATEGORY_LOC_NOT_WORD, |
183 |
CATEGORY_LINEBREAK: CATEGORY_LINEBREAK, |
184 |
CATEGORY_NOT_LINEBREAK: CATEGORY_NOT_LINEBREAK |
185 |
} |
186 |
|
187 |
CH_UNICODE = { |
188 |
CATEGORY_DIGIT: CATEGORY_UNI_DIGIT, |
189 |
CATEGORY_NOT_DIGIT: CATEGORY_UNI_NOT_DIGIT, |
190 |
CATEGORY_SPACE: CATEGORY_UNI_SPACE, |
191 |
CATEGORY_NOT_SPACE: CATEGORY_UNI_NOT_SPACE, |
192 |
CATEGORY_WORD: CATEGORY_UNI_WORD, |
193 |
CATEGORY_NOT_WORD: CATEGORY_UNI_NOT_WORD, |
194 |
CATEGORY_LINEBREAK: CATEGORY_UNI_LINEBREAK, |
195 |
CATEGORY_NOT_LINEBREAK: CATEGORY_UNI_NOT_LINEBREAK |
196 |
} |
197 |
|
198 |
# flags
|
199 |
SRE_FLAG_TEMPLATE = 1 # template mode (disable backtracking) |
200 |
SRE_FLAG_IGNORECASE = 2 # case insensitive |
201 |
SRE_FLAG_LOCALE = 4 # honour system locale |
202 |
SRE_FLAG_MULTILINE = 8 # treat target as multiline string |
203 |
SRE_FLAG_DOTALL = 16 # treat target as a single string |
204 |
SRE_FLAG_UNICODE = 32 # use unicode locale |
205 |
SRE_FLAG_VERBOSE = 64 # ignore whitespace and comments |
206 |
SRE_FLAG_DEBUG = 128 # debugging |
207 |
|
208 |
# flags for INFO primitive
|
209 |
SRE_INFO_PREFIX = 1 # has prefix |
210 |
SRE_INFO_LITERAL = 2 # entire pattern is literal (given by prefix) |
211 |
SRE_INFO_CHARSET = 4 # pattern starts with character from given set |
212 |
|
213 |
if __name__ == "__main__": |
214 |
import string |
215 |
def dump(f, d, prefix): |
216 |
items = d.items() |
217 |
items.sort(lambda a, b: cmp(a[1], b[1])) |
218 |
for k, v in items: |
219 |
f.write("#define %s_%s %s\n" % (prefix, string.upper(k), v))
|
220 |
f = open("sre_constants.h", "w") |
221 |
f.write("""\
|
222 |
/*
|
223 |
* Secret Labs' Regular Expression Engine
|
224 |
*
|
225 |
* regular expression matching engine
|
226 |
*
|
227 |
* NOTE: This file is generated by sre_constants.py. If you need
|
228 |
* to change anything in here, edit sre_constants.py and run it.
|
229 |
*
|
230 |
* Copyright (c) 1997-2001 by Secret Labs AB. All rights reserved.
|
231 |
*
|
232 |
* See the _sre.c file for information on usage and redistribution.
|
233 |
*/
|
234 |
|
235 |
""")
|
236 |
|
237 |
f.write("#define SRE_MAGIC %d\n" % MAGIC)
|
238 |
|
239 |
dump(f, OPCODES, "SRE_OP")
|
240 |
dump(f, ATCODES, "SRE")
|
241 |
dump(f, CHCODES, "SRE")
|
242 |
|
243 |
f.write("#define SRE_FLAG_TEMPLATE %d\n" % SRE_FLAG_TEMPLATE)
|
244 |
f.write("#define SRE_FLAG_IGNORECASE %d\n" % SRE_FLAG_IGNORECASE)
|
245 |
f.write("#define SRE_FLAG_LOCALE %d\n" % SRE_FLAG_LOCALE)
|
246 |
f.write("#define SRE_FLAG_MULTILINE %d\n" % SRE_FLAG_MULTILINE)
|
247 |
f.write("#define SRE_FLAG_DOTALL %d\n" % SRE_FLAG_DOTALL)
|
248 |
f.write("#define SRE_FLAG_UNICODE %d\n" % SRE_FLAG_UNICODE)
|
249 |
f.write("#define SRE_FLAG_VERBOSE %d\n" % SRE_FLAG_VERBOSE)
|
250 |
|
251 |
f.write("#define SRE_INFO_PREFIX %d\n" % SRE_INFO_PREFIX)
|
252 |
f.write("#define SRE_INFO_LITERAL %d\n" % SRE_INFO_LITERAL)
|
253 |
f.write("#define SRE_INFO_CHARSET %d\n" % SRE_INFO_CHARSET)
|
254 |
|
255 |
f.close() |
256 |
print "done" |