Mercurial > hg-stable
changeset 28875:2e9f5453ab5a
parser: unify parser function of alias declaration and definition
We no longer have to keep them separately.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Tue, 29 Mar 2016 00:08:25 +0900 |
parents | 552eabef663b |
children | 79b8f052ee51 |
files | mercurial/parser.py mercurial/revset.py |
diffstat | 2 files changed, 9 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/parser.py Tue Mar 29 00:05:14 2016 +0900 +++ b/mercurial/parser.py Tue Mar 29 00:08:25 2016 +0900 @@ -251,13 +251,8 @@ raise TypeError("'%s' is not instantiatable" % cls.__name__) @staticmethod - def _parsedecl(spec): - """Parse an alias name and arguments""" - raise NotImplementedError - - @staticmethod - def _parsedefn(spec): - """Parse an alias definition""" + def _parse(spec): + """Parse an alias name, arguments and definition""" raise NotImplementedError @staticmethod @@ -270,7 +265,7 @@ """Parse an alias declaration into ``(name, tree, args, errorstr)`` This function analyzes the parsed tree. The parsing rule is provided - by ``_parsedecl()``. + by ``_parse()``. - ``name``: of declared alias (may be ``decl`` itself at error) - ``tree``: parse result (or ``None`` at error) @@ -311,7 +306,7 @@ ... return list(tree[1:]) ... return [tree] >>> class aliasrules(basealiasrules): - ... _parsedecl = staticmethod(parse) + ... _parse = staticmethod(parse) ... _getlist = staticmethod(getlist) >>> builddecl = aliasrules._builddecl >>> builddecl('foo') @@ -342,7 +337,7 @@ ('foo', None, None, 'argument names collide with each other') """ try: - tree = cls._parsedecl(decl) + tree = cls._parse(decl) except error.ParseError as inst: return (decl, None, None, parseerrordetail(inst)) @@ -392,7 +387,7 @@ """Parse an alias definition into a tree and marks substitutions This function marks alias argument references as ``_aliasarg``. The - parsing rule is provided by ``_parsedefn()``. + parsing rule is provided by ``_parse()``. ``args`` is a list of alias argument names, or None if the alias is declared as a symbol. @@ -404,7 +399,7 @@ ... '"$1" or "foo"': ('or', ('string', '$1'), ('string', 'foo')), ... } >>> class aliasrules(basealiasrules): - ... _parsedefn = staticmethod(parsemap.__getitem__) + ... _parse = staticmethod(parsemap.__getitem__) ... _getlist = staticmethod(lambda x: []) >>> builddefn = aliasrules._builddefn >>> def pprint(tree): @@ -429,7 +424,7 @@ ('string', '$1') ('string', 'foo')) """ - tree = cls._parsedefn(defn) + tree = cls._parse(defn) if args: args = set(args) else:
--- a/mercurial/revset.py Tue Mar 29 00:05:14 2016 +0900 +++ b/mercurial/revset.py Tue Mar 29 00:08:25 2016 +0900 @@ -2253,8 +2253,7 @@ class _aliasrules(parser.basealiasrules): """Parsing and expansion rule set of revset aliases""" _section = _('revset alias') - _parsedecl = staticmethod(_parsealias) - _parsedefn = staticmethod(_parsealias) + _parse = staticmethod(_parsealias) _getlist = staticmethod(getlist) class revsetalias(object):