mercurial/parser.py
changeset 28892 0c135f37c6f8
parent 28875 2e9f5453ab5a
child 28893 ee11167fe1da
--- a/mercurial/parser.py	Fri Apr 08 16:42:43 2016 +0200
+++ b/mercurial/parser.py	Mon Feb 29 18:33:30 2016 +0900
@@ -229,6 +229,19 @@
     else:
         return inst.args[0]
 
+class alias(object):
+    """Parsed result of alias"""
+
+    def __init__(self, name, tree, args, err, replacement):
+        self.name = name
+        self.tree = tree
+        self.args = args
+        self.error = err
+        self.replacement = replacement
+        # whether own `error` information is already shown or not.
+        # this avoids showing same warning multiple times at each `findaliases`.
+        self.warned = False
+
 class basealiasrules(object):
     """Parsing and expansion rule set of aliases
 
@@ -430,3 +443,22 @@
         else:
             args = set()
         return cls._relabelargs(tree, args)
+
+    @classmethod
+    def build(cls, decl, defn):
+        """Parse an alias declaration and definition into an alias object"""
+        repl = efmt = None
+        name, tree, args, err = cls._builddecl(decl)
+        if err:
+            efmt = _('failed to parse the declaration of %(section)s '
+                     '"%(name)s": %(error)s')
+        else:
+            try:
+                repl = cls._builddefn(defn, args)
+            except error.ParseError as inst:
+                err = parseerrordetail(inst)
+                efmt = _('failed to parse the definition of %(section)s '
+                         '"%(name)s": %(error)s')
+        if err:
+            err = efmt % {'section': cls._section, 'name': name, 'error': err}
+        return alias(name, tree, args, err, repl)