diff --git a/mercurial/parser.py b/mercurial/parser.py --- a/mercurial/parser.py +++ b/mercurial/parser.py @@ -228,3 +228,39 @@ def parseerrordetail(inst): return _('at %s: %s') % (inst.args[1], inst.args[0]) else: return inst.args[0] + +class basealiasrules(object): + """Parsing and expansion rule set of aliases + + This is a helper for fileset/revset/template aliases. A concrete rule set + should be made by sub-classing this and implementing class/static methods. + + It supports alias expansion of symbol and funciton-call styles:: + + # decl = defn + h = heads(default) + b($1) = ancestors($1) - ancestors(default) + """ + # typically a config section, which will be included in error messages + _section = None + # tags of symbol and function nodes + _symbolnode = 'symbol' + _funcnode = 'func' + + def __new__(cls): + raise TypeError("'%s' is not instantiatable" % cls.__name__) + + @staticmethod + def _parsedecl(spec): + """Parse an alias name and arguments""" + raise NotImplementedError + + @staticmethod + def _parsedefn(spec): + """Parse an alias definition""" + raise NotImplementedError + + @staticmethod + def _getlist(tree): + """Extract a list of arguments from parsed tree""" + raise NotImplementedError diff --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -2366,6 +2366,11 @@ def _parsealiasdefn(defn, args): tree = parser.simplifyinfixops(tree, ('list', 'or')) return _relabelaliasargs(tree, args) +class _aliasrules(parser.basealiasrules): + """Parsing and expansion rule set of revset aliases""" + _section = _('revset alias') + _getlist = staticmethod(getlist) + class revsetalias(object): # whether own `error` information is already shown or not. # this avoids showing same warning multiple times at each `findaliases`.