From patchwork Sun Apr 3 09:48:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [4, of, 7, V3, RFC] parser: move _relabelaliasargs() to common rule-set class From: Yuya Nishihara X-Patchwork-Id: 14278 Message-Id: To: mercurial-devel@mercurial-scm.org Cc: pierre-yves.david@ens-lyon.org Date: Sun, 03 Apr 2016 18:48:18 +0900 # HG changeset patch # User Yuya Nishihara # Date 1456736451 -32400 # Mon Feb 29 18:00:51 2016 +0900 # Node ID cfdfa5bb37d298d47ee348f9992a9468cd40efaa # Parent aa54435b4a485541d3be7abbe5ed6fd584b43ee5 parser: move _relabelaliasargs() to common rule-set class This has no doctest because it will be covered by _builddefn() introduced by the next patch. revset._relabelaliasargs() will be removed soon. diff --git a/mercurial/parser.py b/mercurial/parser.py --- a/mercurial/parser.py +++ b/mercurial/parser.py @@ -369,3 +369,20 @@ class basealiasrules(object): return (name, tree[:2], args, None) return (decl, None, None, _("invalid format")) + + @classmethod + def _relabelargs(cls, tree, args): + """Mark alias arguments as ``_aliasarg``""" + if not isinstance(tree, tuple): + return tree + op = tree[0] + if op != cls._symbolnode: + return (op,) + tuple(cls._relabelargs(x, args) for x in tree[1:]) + + assert len(tree) == 2 + sym = tree[1] + if sym in args: + op = '_aliasarg' + elif sym.startswith('$'): + raise error.ParseError(_("'$' not for alias arguments")) + return (op, sym) diff --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -2255,19 +2255,7 @@ def _parsealiasdecl(decl): return parser.simplifyinfixops(tree, ('list',)) def _relabelaliasargs(tree, args): - if not isinstance(tree, tuple): - return tree - op = tree[0] - if op != 'symbol': - return (op,) + tuple(_relabelaliasargs(x, args) for x in tree[1:]) - - assert len(tree) == 2 - sym = tree[1] - if sym in args: - op = '_aliasarg' - elif sym.startswith('$'): - raise error.ParseError(_("'$' not for alias arguments")) - return (op, sym) + return _aliasrules._relabelargs(tree, args) def _parsealiasdefn(defn, args): """Parse alias definition ``defn``