Patchwork [5,of,6] parser: move _relabelaliasargs() to common rule-set class

login
register
mail settings
Submitter Yuya Nishihara
Date April 1, 2016, 3:37 p.m.
Message ID <d5414d3c08bbffc3ef6a.1459525031@mimosa>
Download mbox | patch
Permalink /patch/14226/
State Superseded
Commit 5f31d2248745a4e226ea518e733b1f18f92a35bd
Headers show

Comments

Yuya Nishihara - April 1, 2016, 3:37 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1456736451 -32400
#      Mon Feb 29 18:00:51 2016 +0900
# Node ID d5414d3c08bbffc3ef6ad3fa3268d3d43b25afad
# Parent  2a3e01c30ddc08a5ff331b8d9b30ac8c014090d6
parser: move _relabelaliasargs() to common rule-set class

revset._relabelaliasargs() will be removed soon.
Pierre-Yves David - April 1, 2016, 9:35 p.m.
On 04/01/2016 08:37 AM, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1456736451 -32400
> #      Mon Feb 29 18:00:51 2016 +0900
> # Node ID d5414d3c08bbffc3ef6ad3fa3268d3d43b25afad
> # Parent  2a3e01c30ddc08a5ff331b8d9b30ac8c014090d6
> parser: move _relabelaliasargs() to common rule-set class
>
> revset._relabelaliasargs() will be removed soon.
>
> diff --git a/mercurial/parser.py b/mercurial/parser.py
> --- a/mercurial/parser.py
> +++ b/mercurial/parser.py
> @@ -290,3 +290,18 @@ class aliasrules(object):
>               return (name, tree[:2], args, None)
>
>           return (decl, None, None, _("invalid format"))
> +
> +    def _relabelargs(self, tree, args):

Can we get some details about what this function is about, that would 
help me following what is going on here.


> +        if not isinstance(tree, tuple):
> +            return tree
> +        op = tree[0]
> +        if op != self._symbolnode:
> +            return (op,) + tuple(self._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
> @@ -2278,19 +2278,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 parser.aliasrules('', None, None, None)._relabelargs(tree, args)

Urg, that's not a very pretty call, I assume this is temporary. What 
would this looks like eventually?

Cheers,
Yuya Nishihara - April 2, 2016, 2:54 a.m.
On Fri, 1 Apr 2016 14:35:16 -0700, Pierre-Yves David wrote:
> On 04/01/2016 08:37 AM, Yuya Nishihara wrote:
> > # HG changeset patch
> > # User Yuya Nishihara <yuya@tcha.org>
> > # Date 1456736451 -32400
> > #      Mon Feb 29 18:00:51 2016 +0900
> > # Node ID d5414d3c08bbffc3ef6ad3fa3268d3d43b25afad
> > # Parent  2a3e01c30ddc08a5ff331b8d9b30ac8c014090d6
> > parser: move _relabelaliasargs() to common rule-set class
> >
> > revset._relabelaliasargs() will be removed soon.
> >
> > diff --git a/mercurial/parser.py b/mercurial/parser.py
> > --- a/mercurial/parser.py
> > +++ b/mercurial/parser.py
> > @@ -290,3 +290,18 @@ class aliasrules(object):
> >               return (name, tree[:2], args, None)
> >
> >           return (decl, None, None, _("invalid format"))
> > +
> > +    def _relabelargs(self, tree, args):  
> 
> Can we get some details about what this function is about, that would 
> help me following what is going on here.

will do.

> >   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 parser.aliasrules('', None, None, None)._relabelargs(tree, args)  
> 
> Urg, that's not a very pretty call, I assume this is temporary. What 
> would this looks like eventually?

This line is removed by the next patch.

Patch

diff --git a/mercurial/parser.py b/mercurial/parser.py
--- a/mercurial/parser.py
+++ b/mercurial/parser.py
@@ -290,3 +290,18 @@  class aliasrules(object):
             return (name, tree[:2], args, None)
 
         return (decl, None, None, _("invalid format"))
+
+    def _relabelargs(self, tree, args):
+        if not isinstance(tree, tuple):
+            return tree
+        op = tree[0]
+        if op != self._symbolnode:
+            return (op,) + tuple(self._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
@@ -2278,19 +2278,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 parser.aliasrules('', None, None, None)._relabelargs(tree, args)
 
 def _parsealiasdefn(defn, args):
     """Parse alias definition ``defn``