# HG changeset patch # User Yuya Nishihara # Date 1459177514 -32400 # Node ID 552eabef663bd7a43eeb44523bff4cabae5ca873 # Parent 2ca3b7c563f3bbb8a2cc250f3ce96dba2c76f0a4 revset: unify function that parses alias declaration and definition We no longer need separate parsers. Only difference between _parsealiasdecl() and _parsealiasdefn() is whether or not to flatten 'or' tree. Since alias declaration should have no 'or' operator, there was no practical difference. diff -r 2ca3b7c563f3 -r 552eabef663b mercurial/revset.py --- a/mercurial/revset.py Mon Feb 29 18:10:07 2016 +0900 +++ b/mercurial/revset.py Tue Mar 29 00:05:14 2016 +0900 @@ -2234,35 +2234,27 @@ return tokenize(program, lookup=lookup, syminitletters=_aliassyminitletters) -def _parsealiasdecl(decl): - """Parse alias declaration ``decl`` - - >>> _parsealiasdecl('foo($1)') +def _parsealias(spec): + """Parse alias declaration/definition ``spec`` + + >>> _parsealias('foo($1)') ('func', ('symbol', 'foo'), ('symbol', '$1')) - >>> _parsealiasdecl('foo bar') + >>> _parsealias('foo bar') Traceback (most recent call last): ... ParseError: ('invalid token', 4) """ p = parser.parser(elements) - tree, pos = p.parse(_tokenizealias(decl)) - if pos != len(decl): - raise error.ParseError(_('invalid token'), pos) - return parser.simplifyinfixops(tree, ('list',)) - -def _parsealiasdefn(defn): - """Parse alias definition ``defn``""" - p = parser.parser(elements) - tree, pos = p.parse(_tokenizealias(defn)) - if pos != len(defn): + tree, pos = p.parse(_tokenizealias(spec)) + if pos != len(spec): raise error.ParseError(_('invalid token'), pos) return parser.simplifyinfixops(tree, ('list', 'or')) class _aliasrules(parser.basealiasrules): """Parsing and expansion rule set of revset aliases""" _section = _('revset alias') - _parsedecl = staticmethod(_parsealiasdecl) - _parsedefn = staticmethod(_parsealiasdefn) + _parsedecl = staticmethod(_parsealias) + _parsedefn = staticmethod(_parsealias) _getlist = staticmethod(getlist) class revsetalias(object):