Patchwork [6,of,7,V3,RFC] revset: unify function that parses alias declaration and definition

login
register
mail settings
Submitter Yuya Nishihara
Date April 3, 2016, 9:48 a.m.
Message ID <967861e991728f44b976.1459676900@mimosa>
Download mbox | patch
Permalink /patch/14280/
State Accepted
Delegated to: Pierre-Yves David
Headers show

Comments

Yuya Nishihara - April 3, 2016, 9:48 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1459177514 -32400
#      Tue Mar 29 00:05:14 2016 +0900
# Node ID 967861e991728f44b976587900e19037c800b28c
# Parent  d44396be9829c57957470d59177b64a4fd501b54
revset: unify function that parses alias declaration and definition

We no longer need separate parsers. Only difference between _parsealiasdecl()
and _parsealiasdefn() is whether or not to flatten 'or' tree. Since alias
declaration should have no 'or' operator, there was no practical difference.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2238,35 +2238,27 @@  def _tokenizealias(program):
     """
     return tokenize(program, syminitletters=_aliassyminitletters)
 
-def _parsealiasdecl(decl):
-    """Parse alias declaration ``decl``
-
-    >>> _parsealiasdecl('foo($1)')
+def _parsealias(spec):
+    """Parse alias declaration/definition ``spec``
+
+    >>> _parsealias('foo($1)')
     ('func', ('symbol', 'foo'), ('symbol', '$1'))
-    >>> _parsealiasdecl('foo bar')
+    >>> _parsealias('foo bar')
     Traceback (most recent call last):
       ...
     ParseError: ('invalid token', 4)
     """
     p = parser.parser(elements)
-    tree, pos = p.parse(_tokenizealias(decl))
-    if pos != len(decl):
-        raise error.ParseError(_('invalid token'), pos)
-    return parser.simplifyinfixops(tree, ('list',))
-
-def _parsealiasdefn(defn):
-    """Parse alias definition ``defn``"""
-    p = parser.parser(elements)
-    tree, pos = p.parse(_tokenizealias(defn))
-    if pos != len(defn):
+    tree, pos = p.parse(_tokenizealias(spec))
+    if pos != len(spec):
         raise error.ParseError(_('invalid token'), pos)
     return parser.simplifyinfixops(tree, ('list', 'or'))
 
 class _aliasrules(parser.basealiasrules):
     """Parsing and expansion rule set of revset aliases"""
     _section = _('revset alias')
-    _parsedecl = staticmethod(_parsealiasdecl)
-    _parsedefn = staticmethod(_parsealiasdefn)
+    _parsedecl = staticmethod(_parsealias)
+    _parsedefn = staticmethod(_parsealias)
     _getlist = staticmethod(getlist)
 
 class revsetalias(object):