[PATCH 2 of 6] parser: add stub class that will host alias parsing and expansion

Yuya Nishihara yuya at tcha.org
Fri Apr 1 11:37:08 EDT 2016


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1456734174 -32400
#      Mon Feb 29 17:22:54 2016 +0900
# Node ID 2cad9bec8edb7d4a2cd9e317a942d9098e1eda82
# Parent  d30389cc8809d79f9afa1a52275546c816398ab0
parser: add stub class that will host alias parsing and expansion

This class will keep syntax rules that are necessary to parse and expand
aliases. The implementations will be extracted from the revset module. In
order to make the porting easier, this class keeps parsedecl and parsedefn
separately. These functions will be unified later.

The following public functions will be added:

  rules.build(decl, defn) -> aliasobj
    parse decl and defn into an object that keeps alias name, arguments
    and replacement tree.
  rules.buildmap(aliasitems) -> aliasdict
    helper to build() a dict of alias objects from a list of (decl, defn)
  rules.expand(aliasdict, tree) -> tree
    expand aliases in tree recursively

Because these functions aren't introduced by this series, there would remain
a couple of wrapper functions in the revset module. These ugly wrappers
should be eliminated by the next series.

diff --git a/mercurial/parser.py b/mercurial/parser.py
--- a/mercurial/parser.py
+++ b/mercurial/parser.py
@@ -228,3 +228,28 @@ def parseerrordetail(inst):
         return _('at %s: %s') % (inst.args[1], inst.args[0])
     else:
         return inst.args[0]
+
+class aliasrules(object):
+    """Parsing and expansion rule set of aliases
+
+    This class supports aliases of symbol and function-call styles::
+
+        # decl = defn
+        h = heads(default)
+        b($1) = ancestors($1) - ancestors(default)
+
+    - ``section`` is typically a config section name, which will be included
+      in error messages
+    - ``parsedecl(spec)`` parses an alias name and arguments
+    - ``parsedefn(spec)`` parses an alias definition
+    - ``getlist(tree)`` extracts a list of arguments from parsed tree
+    """
+
+    def __init__(self, section, parsedecl, parsedefn, getlist,
+                 symbolnode='symbol', funcnode='func'):
+        self._section = section
+        self._parsedecl = parsedecl
+        self._parsedefn = parsedefn
+        self._getlist = getlist
+        self._symbolnode = symbolnode
+        self._funcnode = funcnode


More information about the Mercurial-devel mailing list