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