Mercurial > public > mercurial-scm > hg
comparison mercurial/revset.py @ 28720:639e0f1e8ffa
parser: move parsererrordetail() function from revset module
This will be used by common alias functions introduced by future patches.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Mon, 29 Feb 2016 17:02:56 +0900 |
parents | f103f985ac00 |
children | 87b89dca669d |
comparison
equal
deleted
inserted
replaced
28719:dd2cf90a3731 | 28720:639e0f1e8ffa |
---|---|
298 raise error.ParseError(_("syntax error in revset '%s'") % | 298 raise error.ParseError(_("syntax error in revset '%s'") % |
299 program, pos) | 299 program, pos) |
300 pos += 1 | 300 pos += 1 |
301 yield ('end', None, pos) | 301 yield ('end', None, pos) |
302 | 302 |
303 def parseerrordetail(inst): | |
304 """Compose error message from specified ParseError object | |
305 """ | |
306 if len(inst.args) > 1: | |
307 return _('at %s: %s') % (inst.args[1], inst.args[0]) | |
308 else: | |
309 return inst.args[0] | |
310 | |
311 # helpers | 303 # helpers |
312 | 304 |
313 def getstring(x, err): | 305 def getstring(x, err): |
314 if x and (x[0] == 'string' or x[0] == 'symbol'): | 306 if x and (x[0] == 'string' or x[0] == 'symbol'): |
315 return x[1] | 307 return x[1] |
2310 _("argument names collide with each other")) | 2302 _("argument names collide with each other")) |
2311 return (name, tree[:2], args, None) | 2303 return (name, tree[:2], args, None) |
2312 | 2304 |
2313 return (decl, None, None, _("invalid format")) | 2305 return (decl, None, None, _("invalid format")) |
2314 except error.ParseError as inst: | 2306 except error.ParseError as inst: |
2315 return (decl, None, None, parseerrordetail(inst)) | 2307 return (decl, None, None, parser.parseerrordetail(inst)) |
2316 | 2308 |
2317 def _relabelaliasargs(tree, args): | 2309 def _relabelaliasargs(tree, args): |
2318 if not isinstance(tree, tuple): | 2310 if not isinstance(tree, tuple): |
2319 return tree | 2311 return tree |
2320 op = tree[0] | 2312 op = tree[0] |
2347 ('_aliasarg', '$1') | 2339 ('_aliasarg', '$1') |
2348 ('_aliasarg', 'foo')) | 2340 ('_aliasarg', 'foo')) |
2349 >>> try: | 2341 >>> try: |
2350 ... _parsealiasdefn('$1 or $bar', args) | 2342 ... _parsealiasdefn('$1 or $bar', args) |
2351 ... except error.ParseError, inst: | 2343 ... except error.ParseError, inst: |
2352 ... print parseerrordetail(inst) | 2344 ... print parser.parseerrordetail(inst) |
2353 '$' not for alias arguments | 2345 '$' not for alias arguments |
2354 >>> args = ['$1', '$10', 'foo'] | 2346 >>> args = ['$1', '$10', 'foo'] |
2355 >>> print prettyformat(_parsealiasdefn('$10 or foobar', args)) | 2347 >>> print prettyformat(_parsealiasdefn('$10 or foobar', args)) |
2356 (or | 2348 (or |
2357 ('_aliasarg', '$10') | 2349 ('_aliasarg', '$10') |
2392 | 2384 |
2393 try: | 2385 try: |
2394 self.replacement = _parsealiasdefn(value, self.args) | 2386 self.replacement = _parsealiasdefn(value, self.args) |
2395 except error.ParseError as inst: | 2387 except error.ParseError as inst: |
2396 self.error = _('failed to parse the definition of revset alias' | 2388 self.error = _('failed to parse the definition of revset alias' |
2397 ' "%s": %s') % (self.name, parseerrordetail(inst)) | 2389 ' "%s": %s') % (self.name, |
2390 parser.parseerrordetail(inst)) | |
2398 | 2391 |
2399 def _getalias(aliases, tree): | 2392 def _getalias(aliases, tree): |
2400 """If tree looks like an unexpanded alias, return it. Return None | 2393 """If tree looks like an unexpanded alias, return it. Return None |
2401 otherwise. | 2394 otherwise. |
2402 """ | 2395 """ |