Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/revset.py @ 23843:c4d0c3d05721
revset: factor out composing error message for ParseError to reuse
This patch defines the composing function not in "ParseError" class but
in "revset" module, because:
- "_()" shouldn't be used in "ParseError", to avoid adding "from
i18n import _" i18n" to "error" module
- generalizing message composition of"ParseError" for all code paths
other than revset isn't the purpose of this patch
we should also take care of showing "unexpected leading
whitespace" for some code paths, to generalize widely.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Sat, 10 Jan 2015 23:18:11 +0900 |
parents | 91dbb98b3513 |
children | ddf2172e901d |
comparison
equal
deleted
inserted
replaced
23842:91dbb98b3513 | 23843:c4d0c3d05721 |
---|---|
237 else: | 237 else: |
238 raise error.ParseError(_("syntax error"), pos) | 238 raise error.ParseError(_("syntax error"), pos) |
239 pos += 1 | 239 pos += 1 |
240 yield ('end', None, pos) | 240 yield ('end', None, pos) |
241 | 241 |
242 def parseerrordetail(inst): | |
243 """Compose error message from specified ParseError object | |
244 """ | |
245 if len(inst.args) > 1: | |
246 return _('at %s: %s') % (inst.args[1], inst.args[0]) | |
247 else: | |
248 return inst.args[0] | |
249 | |
242 # helpers | 250 # helpers |
243 | 251 |
244 def getstring(x, err): | 252 def getstring(x, err): |
245 if x and (x[0] == 'string' or x[0] == 'symbol'): | 253 if x and (x[0] == 'string' or x[0] == 'symbol'): |
246 return x[1] | 254 return x[1] |
2144 if pos != len(value): | 2152 if pos != len(value): |
2145 raise error.ParseError(_('invalid token'), pos) | 2153 raise error.ParseError(_('invalid token'), pos) |
2146 # Check for placeholder injection | 2154 # Check for placeholder injection |
2147 _checkaliasarg(self.replacement, self.args) | 2155 _checkaliasarg(self.replacement, self.args) |
2148 except error.ParseError, inst: | 2156 except error.ParseError, inst: |
2149 if len(inst.args) > 1: | 2157 self.error = parseerrordetail(inst) |
2150 self.error = _('at %s: %s') % (inst.args[1], inst.args[0]) | |
2151 else: | |
2152 self.error = inst.args[0] | |
2153 | 2158 |
2154 def _getalias(aliases, tree): | 2159 def _getalias(aliases, tree): |
2155 """If tree looks like an unexpanded alias, return it. Return None | 2160 """If tree looks like an unexpanded alias, return it. Return None |
2156 otherwise. | 2161 otherwise. |
2157 """ | 2162 """ |