Patchwork [1,of,3] revset: inline _tokenizealias() into _parsealias()

login
register
mail settings
Submitter Yuya Nishihara
Date May 4, 2016, 12:11 p.m.
Message ID <57e38af84899a6fbb0a6.1462363901@mimosa>
Download mbox | patch
Permalink /patch/14878/
State Accepted
Delegated to: Augie Fackler
Headers show

Comments

Yuya Nishihara - May 4, 2016, 12:11 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1460865447 -32400
#      Sun Apr 17 12:57:27 2016 +0900
# Node ID 57e38af84899a6fbb0a63cf84f60c17f3a6cf782
# Parent  8eba4cdcfd810d80785c94d770a442c5bd1f9d0f
revset: inline _tokenizealias() into _parsealias()

This helps factoring out common part between _parsealias() and parse().

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2217,18 +2217,12 @@  def optimize(x, small):
 _aliassyminitletters = set(c for c in [chr(i) for i in xrange(256)]
                            if c.isalnum() or c in '._@$' or ord(c) > 127)
 
-def _tokenizealias(program, lookup=None):
-    """Parse alias declaration/definition into a stream of tokens
+def _parsealias(spec):
+    """Parse alias declaration/definition ``spec``
 
     This allows symbol names to use also ``$`` as an initial letter
     (for backward compatibility), and callers of this function should
     examine whether ``$`` is used also for unexpected symbols or not.
-    """
-    return tokenize(program, lookup=lookup,
-                    syminitletters=_aliassyminitletters)
-
-def _parsealias(spec):
-    """Parse alias declaration/definition ``spec``
 
     >>> _parsealias('foo($1)')
     ('func', ('symbol', 'foo'), ('symbol', '$1'))
@@ -2238,7 +2232,7 @@  def _parsealias(spec):
     ParseError: ('invalid token', 4)
     """
     p = parser.parser(elements)
-    tree, pos = p.parse(_tokenizealias(spec))
+    tree, pos = p.parse(tokenize(spec, syminitletters=_aliassyminitletters))
     if pos != len(spec):
         raise error.ParseError(_('invalid token'), pos)
     return parser.simplifyinfixops(tree, ('list', 'or'))