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

login
register
mail settings
Submitter Yuya Nishihara
Date April 2, 2016, 8:30 a.m.
Message ID <57f4e13ef151c728a9c7.1459585821@mimosa>
Download mbox | patch
Permalink /patch/14253/
State Superseded
Headers show

Comments

Yuya Nishihara - April 2, 2016, 8:30 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1459177514 -32400
#      Tue Mar 29 00:05:14 2016 +0900
# Node ID 57f4e13ef151c728a9c7245b0918fdc096cfd4c8
# Parent  e3157edf28c3a6520c592e704259d388cca52d46
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,27 +2238,19 @@  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'))
 
@@ -2274,7 +2266,7 @@  class revsetalias(object):
         b($1) = ancestors($1) - ancestors(default)
         '''
         rules = parser.aliasrules(_('revset alias'),
-                                  _parsealiasdecl, _parsealiasdefn, getlist)
+                                  _parsealias, _parsealias, getlist)
         self.name, self.tree, self.args, self.error = rules._builddecl(name)
         if self.error:
             self.error = _('failed to parse the declaration of revset alias'