267 >>> _match('f(_)', parse('f(1, 2)')) |
267 >>> _match('f(_)', parse('f(1, 2)')) |
268 """ |
268 """ |
269 pattern = _cachedtree(patspec) |
269 pattern = _cachedtree(patspec) |
270 return parser.matchtree(pattern, tree, ('symbol', '_'), |
270 return parser.matchtree(pattern, tree, ('symbol', '_'), |
271 {'keyvalue', 'list'}) |
271 {'keyvalue', 'list'}) |
272 |
|
273 def _isnamedfunc(x, funcname): |
|
274 """Check if given tree matches named function""" |
|
275 return x and x[0] == 'func' and getsymbol(x[1]) == funcname |
|
276 |
|
277 def _isposargs(x, n): |
|
278 """Check if given tree is n-length list of positional arguments""" |
|
279 l = getlist(x) |
|
280 return len(l) == n and all(y and y[0] != 'keyvalue' for y in l) |
|
281 |
|
282 def _matchnamedfunc(x, funcname): |
|
283 """Return args tree if given tree matches named function; otherwise None |
|
284 |
|
285 This can't be used for testing a nullary function since its args tree |
|
286 is also None. Use _isnamedfunc() instead. |
|
287 """ |
|
288 if not _isnamedfunc(x, funcname): |
|
289 return |
|
290 return x[2] |
|
291 |
272 |
292 def _matchonly(revs, bases): |
273 def _matchonly(revs, bases): |
293 return _match('ancestors(_) and not ancestors(_)', ('and', revs, bases)) |
274 return _match('ancestors(_) and not ancestors(_)', ('and', revs, bases)) |
294 |
275 |
295 def _fixops(x): |
276 def _fixops(x): |