changeset 28874:552eabef663b

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.
author Yuya Nishihara <yuya@tcha.org>
date Tue, 29 Mar 2016 00:05:14 +0900
parents 2ca3b7c563f3
children 2e9f5453ab5a
files mercurial/revset.py
diffstat 1 files changed, 9 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Mon Feb 29 18:10:07 2016 +0900
+++ b/mercurial/revset.py	Tue Mar 29 00:05:14 2016 +0900
@@ -2234,35 +2234,27 @@
     return tokenize(program, lookup=lookup,
                     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):