1
2
3
4
5
6
7
8
9
10
11
12
13 from Bio.Parsers.spark import GenericScanner, GenericParser
14
19 return cmp(self.type, other)
21 return "Tokens(%r)" % (self.type,)
22
23
25 type = "integer"
29 return cmp(self.type, other)
33 return "Integer(%s)" % self.val
34
35
36
38 type = "unsigned_integer"
40 return "UnsignedInteger(%s)" % self.val
41
43 type = "symbol"
47 return cmp(self.type, other)
51 return "Symbol(%s)" % repr(self.name)
52
53
58 return "LowBound(%r)" % self.base
59
60
65 return "HighBound(%r)" % self.base
66
67
70 self.low = low
71 self.high = high
73 return "TwoBound(%r, %r)" % (self.low, self.high)
74
75
78 self.low = low
79 self.high = high
81 return "Between(%r, %r)" % (self.low, self.high)
82
83
86 self.low = low
87 self.high = high
89 return "Range(%r, %r)" % (self.low, self.high)
90
96 return "Function(%r, %r)" % (self.name, self.args)
97
99 - def __init__(self, path, local_location):
100 self.path = path
101 self.local_location = local_location
103 return "AbsoluteLocation(%r, %r)" % (self.path, self.local_location)
104
106 - def __init__(self, database, accession):
111
114 self.path = path
115 self.label = label
117 return "FeatureName(%r, %r)" % (self.path, self.label)
118
122
127
159 r" [A-Za-z0-9_'*-][A-Za-z0-9_'*.-]* "
160
161 self.rv.append(Symbol(input))
168
169
170
171
176
178 """
179 location ::= absolute_location
180 location ::= feature_name
181 location ::= function
182 """
183 return args[0]
184
186 """
187 function ::= functional_operator open_paren location_list close_paren
188 """
189 return Function(args[0].name, args[2])
190
192 """
193 absolute_location ::= local_location
194 absolute_location ::= path colon local_location
195 """
196 if len(args) == 1:
197 return AbsoluteLocation(None, args[-1])
198 return AbsoluteLocation(args[0], args[-1])
199
201 """
202 path ::= database double_colon primary_accession
203 path ::= primary_accession
204 """
205 if len(args) == 3:
206 return Path(args[0], args[2])
207 return Path(None, args[0])
208
210 """
211 feature_name ::= path colon feature_label
212 feature_name ::= feature_label
213 """
214 if len(args) == 3:
215 return FeatureName(args[0], args[2])
216 return FeatureName(None, args[0])
217
219 """
220 label ::= symbol
221 """
222 return args[0].name
223
225 """
226 local_location ::= base_position
227 local_location ::= between_position
228 local_location ::= base_range
229 """
230 return args[0]
232 """
233 location_list ::= location
234 location_list ::= location_list comma location
235 """
236 if len(args) == 1:
237 return args
238 return args[0] + [args[2]]
239
241 """
242 functional_operator ::= symbol
243 """
244 return args[0]
245
247 """
248 base_position ::= integer
249 base_position ::= low_base_bound
250 base_position ::= high_base_bound
251 base_position ::= two_base_bound
252 """
253 return args[0]
254
256 """
257 low_base_bound ::= greater_than integer
258 """
259 return LowBound(args[1])
260
262 """
263 high_base_bound ::= less_than integer
264 """
265 return HighBound(args[1])
266
268 """
269 two_base_bound ::= open_paren base_position dot base_position close_paren
270 """
271
272 return TwoBound(args[1], args[3])
273
275 """
276 two_base_bound ::= base_position dot base_position
277 """
278
279 return TwoBound(args[0], args[2])
280
282 """
283 between_position ::= base_position caret base_position
284 """
285 return Between(args[0], args[2])
286
288 """
289 base_range ::= base_position double_dot base_position
290 base_range ::= function double_dot base_position
291 base_range ::= base_position double_dot function
292 base_range ::= function double_dot function
293 """
294 return Range(args[0], args[2])
295
297 """
298 database ::= symbol
299 """
300 return args[0].name
301
303 """
304 primary_accession ::= symbol
305 """
306 return args[0].name
307
308
309 _cached_scanner = LocationScanner()
315
316 _cached_parser = LocationParser()
318 """Go from a set of tokens to an object representation"""
319
320
321
322 return _cached_parser.parse(tokens)
323