comparison mercurial/revset.py @ 28870:475dad3432fd

parser: add stub class that will host alias parsing and expansion This class will keep syntax rules that are necessary to parse and expand aliases. The implementations will be extracted from the revset module. In order to make the porting easier, this class keeps parsedecl and parsedefn separately, which will be unified later. Also, getlist and funcnode will be refactored by future patches for better handling of the template aliases. The following public functions will be added: aliasrules.build(decl, defn) -> aliasobj parse decl and defn into an object that keeps alias name, arguments and replacement tree. aliasrules.buildmap(aliasitems) -> aliasdict helper to build() a dict of alias objects from a list of (decl, defn) aliasrules.expand(aliasdict, tree) -> tree expand aliases in tree recursively Because these functions aren't introduced by this series, there would remain a few wrapper functions in the revset module. These ugly wrappers should be eliminated by the next series. This class is considered an inheritable namespace, which will host only class/static methods. That's because it won't have no object-scope variables. I'm not a big fan of using class as a syntax sugar, but I admit it can improve code readability at some level. So let's give it a try.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 03 Apr 2016 16:55:23 +0900
parents f8182ab688a5
children 6d6201fc5aae
comparison
equal deleted inserted replaced
28869:f8182ab688a5 28870:475dad3432fd
2364 if pos != len(defn): 2364 if pos != len(defn):
2365 raise error.ParseError(_('invalid token'), pos) 2365 raise error.ParseError(_('invalid token'), pos)
2366 tree = parser.simplifyinfixops(tree, ('list', 'or')) 2366 tree = parser.simplifyinfixops(tree, ('list', 'or'))
2367 return _relabelaliasargs(tree, args) 2367 return _relabelaliasargs(tree, args)
2368 2368
2369 class _aliasrules(parser.basealiasrules):
2370 """Parsing and expansion rule set of revset aliases"""
2371 _section = _('revset alias')
2372 _getlist = staticmethod(getlist)
2373
2369 class revsetalias(object): 2374 class revsetalias(object):
2370 # whether own `error` information is already shown or not. 2375 # whether own `error` information is already shown or not.
2371 # this avoids showing same warning multiple times at each `findaliases`. 2376 # this avoids showing same warning multiple times at each `findaliases`.
2372 warned = False 2377 warned = False
2373 2378