Show More
@@ -256,9 +256,8 b' class basealiasrules(object):' | |||
|
256 | 256 | """ |
|
257 | 257 | # typically a config section, which will be included in error messages |
|
258 | 258 | _section = None |
|
259 |
# tag |
|
|
259 | # tag of symbol node | |
|
260 | 260 | _symbolnode = 'symbol' |
|
261 | _funcnode = 'func' | |
|
262 | 261 | |
|
263 | 262 | def __new__(cls): |
|
264 | 263 | raise TypeError("'%s' is not instantiatable" % cls.__name__) |
@@ -269,8 +268,8 b' class basealiasrules(object):' | |||
|
269 | 268 | raise NotImplementedError |
|
270 | 269 | |
|
271 | 270 | @staticmethod |
|
272 |
def _ |
|
|
273 | """Extract a list of arguments from parsed tree""" | |
|
271 | def _trygetfunc(tree): | |
|
272 | """Return (name, args) if tree is a function; otherwise None""" | |
|
274 | 273 | raise NotImplementedError |
|
275 | 274 | |
|
276 | 275 | @classmethod |
@@ -311,15 +310,17 b' class basealiasrules(object):' | |||
|
311 | 310 | ... if isinstance(x, Exception): |
|
312 | 311 | ... raise x |
|
313 | 312 | ... return x |
|
314 |
>>> def |
|
|
315 | ... if not tree: | |
|
316 |
... return |
|
|
317 |
... if |
|
|
318 |
... return |
|
|
319 |
... |
|
|
313 | >>> def trygetfunc(tree): | |
|
314 | ... if not tree or tree[0] != 'func' or tree[1][0] != 'symbol': | |
|
315 | ... return None | |
|
316 | ... if not tree[2]: | |
|
317 | ... return tree[1][1], [] | |
|
318 | ... if tree[2][0] == 'list': | |
|
319 | ... return tree[1][1], list(tree[2][1:]) | |
|
320 | ... return tree[1][1], [tree[2]] | |
|
320 | 321 | >>> class aliasrules(basealiasrules): |
|
321 | 322 | ... _parse = staticmethod(parse) |
|
322 |
... _ |
|
|
323 | ... _trygetfunc = staticmethod(trygetfunc) | |
|
323 | 324 | >>> builddecl = aliasrules._builddecl |
|
324 | 325 | >>> builddecl('foo') |
|
325 | 326 | ('foo', None, None) |
@@ -360,19 +361,17 b' class basealiasrules(object):' | |||
|
360 | 361 | return (decl, None, _("'$' not for alias arguments")) |
|
361 | 362 | return (name, None, None) |
|
362 | 363 | |
|
363 | if tree[0] == cls._funcnode and tree[1][0] == cls._symbolnode: | |
|
364 | func = cls._trygetfunc(tree) | |
|
365 | if func: | |
|
364 | 366 | # "name(arg, ....) = ...." style |
|
365 |
name = |
|
|
367 | name, args = func | |
|
366 | 368 | if name.startswith('$'): |
|
367 | 369 | return (decl, None, _("'$' not for alias arguments")) |
|
368 | args = [] | |
|
369 | for arg in cls._getlist(tree[2]): | |
|
370 | if arg[0] != cls._symbolnode: | |
|
371 | return (decl, None, _("invalid argument list")) | |
|
372 | args.append(arg[1]) | |
|
370 | if any(t[0] != cls._symbolnode for t in args): | |
|
371 | return (decl, None, _("invalid argument list")) | |
|
373 | 372 | if len(args) != len(set(args)): |
|
374 | 373 | return (name, None, _("argument names collide with each other")) |
|
375 | return (name, args, None) | |
|
374 | return (name, [t[1] for t in args], None) | |
|
376 | 375 | |
|
377 | 376 | return (decl, None, _("invalid format")) |
|
378 | 377 | |
@@ -411,7 +410,7 b' class basealiasrules(object):' | |||
|
411 | 410 | ... } |
|
412 | 411 | >>> class aliasrules(basealiasrules): |
|
413 | 412 | ... _parse = staticmethod(parsemap.__getitem__) |
|
414 |
... _ |
|
|
413 | ... _trygetfunc = staticmethod(lambda x: None) | |
|
415 | 414 | >>> builddefn = aliasrules._builddefn |
|
416 | 415 | >>> def pprint(tree): |
|
417 | 416 | ... print prettyformat(tree, ('_aliasarg', 'string', 'symbol')) |
@@ -483,11 +482,12 b' class basealiasrules(object):' | |||
|
483 | 482 | a = aliases.get(name) |
|
484 | 483 | if a and a.args is None: |
|
485 | 484 | return a, None |
|
486 | if tree[0] == cls._funcnode and tree[1][0] == cls._symbolnode: | |
|
487 | name = tree[1][1] | |
|
485 | func = cls._trygetfunc(tree) | |
|
486 | if func: | |
|
487 | name, args = func | |
|
488 | 488 | a = aliases.get(name) |
|
489 | 489 | if a and a.args is not None: |
|
490 |
return a, |
|
|
490 | return a, args | |
|
491 | 491 | return None |
|
492 | 492 | |
|
493 | 493 | @classmethod |
@@ -2254,7 +2254,11 b' class _aliasrules(parser.basealiasrules)' | |||
|
2254 | 2254 | """Parsing and expansion rule set of revset aliases""" |
|
2255 | 2255 | _section = _('revset alias') |
|
2256 | 2256 | _parse = staticmethod(_parsealias) |
|
2257 | _getlist = staticmethod(getlist) | |
|
2257 | ||
|
2258 | @staticmethod | |
|
2259 | def _trygetfunc(tree): | |
|
2260 | if tree[0] == 'func' and tree[1][0] == 'symbol': | |
|
2261 | return tree[1][1], getlist(tree[2]) | |
|
2258 | 2262 | |
|
2259 | 2263 | def expandaliases(ui, tree, showwarning=None): |
|
2260 | 2264 | aliases = _aliasrules.buildmap(ui.configitems('revsetalias')) |
General Comments 0
You need to be logged in to leave comments.
Login now