1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 from Bio.Parsers.spark import GenericScanner, GenericParser
17
22 return cmp(self.type, other)
24 return "Tokens(%r)" % (self.type,)
25
26
28 type = "integer"
32 return cmp(self.type, other)
36 return "Integer(%s)" % self.val
37
38
39
41 type = "unsigned_integer"
43 return "UnsignedInteger(%s)" % self.val
44
46 type = "symbol"
50 return cmp(self.type, other)
54 return "Symbol(%s)" % repr(self.name)
55
56
61 return "LowBound(%r)" % self.base
62
63
68 return "HighBound(%r)" % self.base
69
70
73 self.low = low
74 self.high = high
76 return "TwoBound(%r, %r)" % (self.low, self.high)
77
78
81 self.low = low
82 self.high = high
84 return "Between(%r, %r)" % (self.low, self.high)
85
86
89 self.low = low
90 self.high = high
92 return "Range(%r, %r)" % (self.low, self.high)
93
99 return "Function(%r, %r)" % (self.name, self.args)
100
102 - def __init__(self, path, local_location):
103 self.path = path
104 self.local_location = local_location
106 return "AbsoluteLocation(%r, %r)" % (self.path, self.local_location)
107
109 - def __init__(self, database, accession):
114
117 self.path = path
118 self.label = label
120 return "FeatureName(%r, %r)" % (self.path, self.label)
121
125
130
162 r" [A-Za-z0-9_'*-][A-Za-z0-9_'*.-]* "
163
164 self.rv.append(Symbol(input))
171
172
173
174
179
181 """
182 location ::= absolute_location
183 location ::= feature_name
184 location ::= function
185 """
186 return args[0]
187
189 """
190 function ::= functional_operator open_paren location_list close_paren
191 """
192 return Function(args[0].name, args[2])
193
195 """
196 absolute_location ::= local_location
197 absolute_location ::= path colon local_location
198 """
199 if len(args) == 1:
200 return AbsoluteLocation(None, args[-1])
201 return AbsoluteLocation(args[0], args[-1])
202
204 """
205 path ::= database double_colon primary_accession
206 path ::= primary_accession
207 """
208 if len(args) == 3:
209 return Path(args[0], args[2])
210 return Path(None, args[0])
211
213 """
214 feature_name ::= path colon feature_label
215 feature_name ::= feature_label
216 """
217 if len(args) == 3:
218 return FeatureName(args[0], args[2])
219 return FeatureName(None, args[0])
220
222 """
223 label ::= symbol
224 """
225 return args[0].name
226
228 """
229 local_location ::= base_position
230 local_location ::= between_position
231 local_location ::= base_range
232 """
233 return args[0]
235 """
236 location_list ::= location
237 location_list ::= location_list comma location
238 """
239 if len(args) == 1:
240 return args
241 return args[0] + [args[2]]
242
244 """
245 functional_operator ::= symbol
246 """
247 return args[0]
248
250 """
251 base_position ::= integer
252 base_position ::= low_base_bound
253 base_position ::= high_base_bound
254 base_position ::= two_base_bound
255 """
256 return args[0]
257
259 """
260 low_base_bound ::= greater_than integer
261 """
262 return LowBound(args[1])
263
265 """
266 high_base_bound ::= less_than integer
267 """
268 return HighBound(args[1])
269
271 """
272 two_base_bound ::= open_paren base_position dot base_position close_paren
273 """
274
275 return TwoBound(args[1], args[3])
276
278 """
279 two_base_bound ::= base_position dot base_position
280 """
281
282 return TwoBound(args[0], args[2])
283
285 """
286 between_position ::= base_position caret base_position
287 """
288 return Between(args[0], args[2])
289
291 """
292 base_range ::= base_position double_dot base_position
293 base_range ::= function double_dot base_position
294 base_range ::= base_position double_dot function
295 base_range ::= function double_dot function
296 """
297 return Range(args[0], args[2])
298
300 """
301 database ::= symbol
302 """
303 return args[0].name
304
306 """
307 primary_accession ::= symbol
308 """
309 return args[0].name
310
311
312 _cached_scanner = LocationScanner()
318
319 _cached_parser = LocationParser()
321 """Go from a set of tokens to an object representation"""
322
323
324
325 return _cached_parser.parse(tokens)
326