Patchwork [7,of,7,V3,RFC] parser: unify parser function of alias declaration and definition

login
register
mail settings
Submitter Yuya Nishihara
Date April 3, 2016, 9:48 a.m.
Message ID <f95fa7e72a8d6caf7b28.1459676901@mimosa>
Download mbox | patch
Permalink /patch/14281/
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 1459177705 -32400
#      Tue Mar 29 00:08:25 2016 +0900
# Node ID f95fa7e72a8d6caf7b28180549fe0cbf14794021
# Parent  967861e991728f44b976587900e19037c800b28c
parser: unify parser function of alias declaration and definition

We no longer have to keep them separately.

Patch

diff --git a/mercurial/parser.py b/mercurial/parser.py
--- a/mercurial/parser.py
+++ b/mercurial/parser.py
@@ -251,13 +251,8 @@  class basealiasrules(object):
         raise TypeError("'%s' is not instantiatable" % cls.__name__)
 
     @staticmethod
-    def _parsedecl(spec):
-        """Parse an alias name and arguments"""
-        raise NotImplementedError
-
-    @staticmethod
-    def _parsedefn(spec):
-        """Parse an alias definition"""
+    def _parse(spec):
+        """Parse an alias name, arguments and definition"""
         raise NotImplementedError
 
     @staticmethod
@@ -270,7 +265,7 @@  class basealiasrules(object):
         """Parse an alias declaration into ``(name, tree, args, errorstr)``
 
         This function analyzes the parsed tree. The parsing rule is provided
-        by ``_parsedecl()``.
+        by ``_parse()``.
 
         - ``name``: of declared alias (may be ``decl`` itself at error)
         - ``tree``: parse result (or ``None`` at error)
@@ -311,7 +306,7 @@  class basealiasrules(object):
         ...         return list(tree[1:])
         ...     return [tree]
         >>> class aliasrules(basealiasrules):
-        ...     _parsedecl = staticmethod(parse)
+        ...     _parse = staticmethod(parse)
         ...     _getlist = staticmethod(getlist)
         >>> builddecl = aliasrules._builddecl
         >>> builddecl('foo')
@@ -342,7 +337,7 @@  class basealiasrules(object):
         ('foo', None, None, 'argument names collide with each other')
         """
         try:
-            tree = cls._parsedecl(decl)
+            tree = cls._parse(decl)
         except error.ParseError as inst:
             return (decl, None, None, parseerrordetail(inst))
 
@@ -392,7 +387,7 @@  class basealiasrules(object):
         """Parse an alias definition into a tree and marks substitutions
 
         This function marks alias argument references as ``_aliasarg``. The
-        parsing rule is provided by ``_parsedefn()``.
+        parsing rule is provided by ``_parse()``.
 
         ``args`` is a list of alias argument names, or None if the alias
         is declared as a symbol.
@@ -404,7 +399,7 @@  class basealiasrules(object):
         ...     '"$1" or "foo"': ('or', ('string', '$1'), ('string', 'foo')),
         ... }
         >>> class aliasrules(basealiasrules):
-        ...     _parsedefn = staticmethod(parsemap.__getitem__)
+        ...     _parse = staticmethod(parsemap.__getitem__)
         ...     _getlist = staticmethod(lambda x: [])
         >>> builddefn = aliasrules._builddefn
         >>> def pprint(tree):
@@ -429,7 +424,7 @@  class basealiasrules(object):
           ('string', '$1')
           ('string', 'foo'))
         """
-        tree = cls._parsedefn(defn)
+        tree = cls._parse(defn)
         if args:
             args = set(args)
         else:
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2257,8 +2257,7 @@  def _parsealias(spec):
 class _aliasrules(parser.basealiasrules):
     """Parsing and expansion rule set of revset aliases"""
     _section = _('revset alias')
-    _parsedecl = staticmethod(_parsealias)
-    _parsedefn = staticmethod(_parsealias)
+    _parse = staticmethod(_parsealias)
     _getlist = staticmethod(getlist)
 
 class revsetalias(object):