1
2
3
4
5
6
7
8
9
10 from Bio.Parsers.spark import GenericScanner, GenericParser
11
16 return cmp(self.type, other)
18 return "Tokens(%r)" % (self.type,)
19
20
22 type = "integer"
26 return cmp(self.type, other)
30 return "Integer(%s)" % self.val
31
32
33
35 type = "unsigned_integer"
37 return "UnsignedInteger(%s)" % self.val
38
40 type = "symbol"
44 return cmp(self.type, other)
48 return "Symbol(%s)" % repr(self.name)
49
50
55 return "LowBound(%r)" % self.base
56
57
62 return "HighBound(%r)" % self.base
63
64
67 self.low = low
68 self.high = high
70 return "TwoBound(%r, %r)" % (self.low, self.high)
71
72
75 self.low = low
76 self.high = high
78 return "Between(%r, %r)" % (self.low, self.high)
79
80
83 self.low = low
84 self.high = high
86 return "Range(%r, %r)" % (self.low, self.high)
87
93 return "Function(%r, %r)" % (self.name, self.args)
94
96 - def __init__(self, path, local_location):
97 self.path = path
98 self.local_location = local_location
100 return "AbsoluteLocation(%r, %r)" % (self.path, self.local_location)
101
103 - def __init__(self, database, accession):
108
111 self.path = path
112 self.label = label
114 return "FeatureName(%r, %r)" % (self.path, self.label)
115
119
124
156 r" [A-Za-z0-9_'*-][A-Za-z0-9_'*.-]* "
157
158 self.rv.append(Symbol(input))
165
166
167
168
173
175 """
176 location ::= absolute_location
177 location ::= feature_name
178 location ::= function
179 """
180 return args[0]
181
183 """
184 function ::= functional_operator open_paren location_list close_paren
185 """
186 return Function(args[0].name, args[2])
187
189 """
190 absolute_location ::= local_location
191 absolute_location ::= path colon local_location
192 """
193 if len(args) == 1:
194 return AbsoluteLocation(None, args[-1])
195 return AbsoluteLocation(args[0], args[-1])
196
198 """
199 path ::= database double_colon primary_accession
200 path ::= primary_accession
201 """
202 if len(args) == 3:
203 return Path(args[0], args[2])
204 return Path(None, args[0])
205
207 """
208 feature_name ::= path colon feature_label
209 feature_name ::= feature_label
210 """
211 if len(args) == 3:
212 return FeatureName(args[0], args[2])
213 return FeatureName(None, args[0])
214
216 """
217 label ::= symbol
218 """
219 return args[0].name
220
222 """
223 local_location ::= base_position
224 local_location ::= between_position
225 local_location ::= base_range
226 """
227 return args[0]
229 """
230 location_list ::= location
231 location_list ::= location_list comma location
232 """
233 if len(args) == 1:
234 return args
235 return args[0] + [args[2]]
236
238 """
239 functional_operator ::= symbol
240 """
241 return args[0]
242
244 """
245 base_position ::= integer
246 base_position ::= low_base_bound
247 base_position ::= high_base_bound
248 base_position ::= two_base_bound
249 """
250 return args[0]
251
253 """
254 low_base_bound ::= greater_than integer
255 """
256 return LowBound(args[1])
257
259 """
260 high_base_bound ::= less_than integer
261 """
262 return HighBound(args[1])
263
265 """
266 two_base_bound ::= open_paren base_position dot base_position close_paren
267 """
268
269 return TwoBound(args[1], args[3])
270
272 """
273 two_base_bound ::= base_position dot base_position
274 """
275
276 return TwoBound(args[0], args[2])
277
279 """
280 between_position ::= base_position caret base_position
281 """
282 return Between(args[0], args[2])
283
285 """
286 base_range ::= base_position double_dot base_position
287 base_range ::= function double_dot base_position
288 base_range ::= base_position double_dot function
289 base_range ::= function double_dot function
290 """
291 return Range(args[0], args[2])
292
294 """
295 database ::= symbol
296 """
297 return args[0].name
298
300 """
301 primary_accession ::= symbol
302 """
303 return args[0].name
304
305
306 _cached_scanner = LocationScanner()
312
313 _cached_parser = LocationParser()
315 """Go from a set of tokens to an object representation"""
316
317
318
319 return _cached_parser.parse(tokens)
320