Patchwork [1,of,6] parser: move parsererrordetail() function from revset module

login
register
mail settings
Submitter Yuya Nishihara
Date April 1, 2016, 3:37 p.m.
Message ID <d30389cc8809d79f9afa.1459525027@mimosa>
Download mbox | patch
Permalink /patch/14222/
State Accepted
Headers show

Comments

Yuya Nishihara - April 1, 2016, 3:37 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1456732976 -32400
#      Mon Feb 29 17:02:56 2016 +0900
# Node ID d30389cc8809d79f9afa1a52275546c816398ab0
# Parent  1490e850cffc0103fd42714cf1245a55bcbdc4a6
parser: move parsererrordetail() function from revset module

This will be used by common alias functions introduced by future patches.
Pierre-Yves David - April 1, 2016, 9:12 p.m.
On 04/01/2016 08:37 AM, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1456732976 -32400
> #      Mon Feb 29 17:02:56 2016 +0900
> # Node ID d30389cc8809d79f9afa1a52275546c816398ab0
> # Parent  1490e850cffc0103fd42714cf1245a55bcbdc4a6
> parser: move parsererrordetail() function from revset module
>
> This will be used by common alias functions introduced by future patches.

I've pushed patch 1. The rest seems to be going in the right direction, 
however, is a fairly advance and obscure. I need more time too look at 
it and will start by asking more documentation.

Patch

diff --git a/mercurial/parser.py b/mercurial/parser.py
--- a/mercurial/parser.py
+++ b/mercurial/parser.py
@@ -220,3 +220,11 @@  def simplifyinfixops(tree, targetnodes):
     simplified.append(simplifyinfixops(x, targetnodes))
     simplified.append(op)
     return tuple(reversed(simplified))
+
+def parseerrordetail(inst):
+    """Compose error message from specified ParseError object
+    """
+    if len(inst.args) > 1:
+        return _('at %s: %s') % (inst.args[1], inst.args[0])
+    else:
+        return inst.args[0]
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -305,14 +305,6 @@  def tokenize(program, lookup=None, symin
         pos += 1
     yield ('end', None, pos)
 
-def parseerrordetail(inst):
-    """Compose error message from specified ParseError object
-    """
-    if len(inst.args) > 1:
-        return _('at %s: %s') % (inst.args[1], inst.args[0])
-    else:
-        return inst.args[0]
-
 # helpers
 
 def getstring(x, err):
@@ -2316,7 +2308,7 @@  def _parsealiasdecl(decl):
 
         return (decl, None, None, _("invalid format"))
     except error.ParseError as inst:
-        return (decl, None, None, parseerrordetail(inst))
+        return (decl, None, None, parser.parseerrordetail(inst))
 
 def _relabelaliasargs(tree, args):
     if not isinstance(tree, tuple):
@@ -2353,7 +2345,7 @@  def _parsealiasdefn(defn, args):
     >>> try:
     ...     _parsealiasdefn('$1 or $bar', args)
     ... except error.ParseError, inst:
-    ...     print parseerrordetail(inst)
+    ...     print parser.parseerrordetail(inst)
     '$' not for alias arguments
     >>> args = ['$1', '$10', 'foo']
     >>> print prettyformat(_parsealiasdefn('$10 or foobar', args))
@@ -2398,7 +2390,8 @@  class revsetalias(object):
             self.replacement = _parsealiasdefn(value, self.args)
         except error.ParseError as inst:
             self.error = _('failed to parse the definition of revset alias'
-                           ' "%s": %s') % (self.name, parseerrordetail(inst))
+                           ' "%s": %s') % (self.name,
+                                           parser.parseerrordetail(inst))
 
 def _getalias(aliases, tree):
     """If tree looks like an unexpanded alias, return it. Return None