[PATCH 2 of 4] revset: inline isvalidsymbol() and getsymbol() into _parsealiasdecl()
Yuya Nishihara
yuya at tcha.org
Wed Mar 30 11:38:19 EDT 2016
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1456731138 -32400
# Mon Feb 29 16:32:18 2016 +0900
# Node ID 47f49b9d2307e21c32147b8b5006fa5498cd87c9
# Parent 5074171ac66d513f1e4597927308920ffc654be2
revset: inline isvalidsymbol() and getsymbol() into _parsealiasdecl()
Since I'm going to extract a common alias parser, I want to eliminate
dependencies to the revset parsing rules. These functions are trivial,
so we can go without them.
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -337,29 +337,17 @@ def getargsdict(x, funcname, keys):
return parser.buildargsdict(getlist(x), funcname, keys.split(),
keyvaluenode='keyvalue', keynode='symbol')
-def isvalidsymbol(tree):
- """Examine whether specified ``tree`` is valid ``symbol`` or not
- """
- return tree[0] == 'symbol'
-
-def getsymbol(tree):
- """Get symbol name from valid ``symbol`` in ``tree``
-
- This assumes that ``tree`` is already examined by ``isvalidsymbol``.
- """
- return tree[1]
-
def isvalidfunc(tree):
"""Examine whether specified ``tree`` is valid ``func`` or not
"""
- return tree[0] == 'func' and isvalidsymbol(tree[1])
+ return tree[0] == 'func' and tree[1][0] == 'symbol'
def getfuncname(tree):
"""Get function name from valid ``func`` in ``tree``
This assumes that ``tree`` is already examined by ``isvalidfunc``.
"""
- return getsymbol(tree[1])
+ return tree[1][1]
def getfuncargs(tree):
"""Get list of function arguments from valid ``func`` in ``tree``
@@ -2323,9 +2311,9 @@ def _parsealiasdecl(decl):
raise error.ParseError(_('invalid token'), pos)
tree = parser.simplifyinfixops(tree, ('list',))
- if isvalidsymbol(tree):
+ if tree[0] == 'symbol':
# "name = ...." style
- name = getsymbol(tree)
+ name = tree[1]
if name.startswith('$'):
return (decl, None, None, _("'$' not for alias arguments"))
return (name, ('symbol', name), None, None)
@@ -2337,9 +2325,9 @@ def _parsealiasdecl(decl):
return (decl, None, None, _("'$' not for alias arguments"))
args = []
for arg in getfuncargs(tree):
- if not isvalidsymbol(arg):
+ if arg[0] != 'symbol':
return (decl, None, None, _("invalid argument list"))
- args.append(getsymbol(arg))
+ args.append(arg[1])
if len(args) != len(set(args)):
return (name, None, None,
_("argument names collide with each other"))
More information about the Mercurial-devel
mailing list