##// END OF EJS Templates
parser: drop redundant comparison between alias declaration tree and pattern...
Yuya Nishihara -
r28908:7a772def default
parent child Browse files
Show More
@@ -232,9 +232,8 b' def parseerrordetail(inst):'
232 232 class alias(object):
233 233 """Parsed result of alias"""
234 234
235 def __init__(self, name, tree, args, err, replacement):
235 def __init__(self, name, args, err, replacement):
236 236 self.name = name
237 self.tree = tree
238 237 self.args = args
239 238 self.error = err
240 239 self.replacement = replacement
@@ -276,13 +275,12 b' class basealiasrules(object):'
276 275
277 276 @classmethod
278 277 def _builddecl(cls, decl):
279 """Parse an alias declaration into ``(name, tree, args, errorstr)``
278 """Parse an alias declaration into ``(name, args, errorstr)``
280 279
281 280 This function analyzes the parsed tree. The parsing rule is provided
282 281 by ``_parse()``.
283 282
284 283 - ``name``: of declared alias (may be ``decl`` itself at error)
285 - ``tree``: parse result (or ``None`` at error)
286 284 - ``args``: list of argument names (or None for symbol declaration)
287 285 - ``errorstr``: detail about detected error (or None)
288 286
@@ -324,60 +322,59 b' class basealiasrules(object):'
324 322 ... _getlist = staticmethod(getlist)
325 323 >>> builddecl = aliasrules._builddecl
326 324 >>> builddecl('foo')
327 ('foo', ('symbol', 'foo'), None, None)
325 ('foo', None, None)
328 326 >>> builddecl('$foo')
329 ('$foo', None, None, "'$' not for alias arguments")
327 ('$foo', None, "'$' not for alias arguments")
330 328 >>> builddecl('foo::bar')
331 ('foo::bar', None, None, 'invalid format')
329 ('foo::bar', None, 'invalid format')
332 330 >>> builddecl('foo()')
333 ('foo', ('func', ('symbol', 'foo')), [], None)
331 ('foo', [], None)
334 332 >>> builddecl('$foo()')
335 ('$foo()', None, None, "'$' not for alias arguments")
333 ('$foo()', None, "'$' not for alias arguments")
336 334 >>> builddecl('foo($1, $2)')
337 ('foo', ('func', ('symbol', 'foo')), ['$1', '$2'], None)
335 ('foo', ['$1', '$2'], None)
338 336 >>> builddecl('foo(bar_bar, baz.baz)')
339 ('foo', ('func', ('symbol', 'foo')), ['bar_bar', 'baz.baz'], None)
337 ('foo', ['bar_bar', 'baz.baz'], None)
340 338 >>> builddecl('foo($1, $2, nested($1, $2))')
341 ('foo($1, $2, nested($1, $2))', None, None, 'invalid argument list')
339 ('foo($1, $2, nested($1, $2))', None, 'invalid argument list')
342 340 >>> builddecl('foo(bar($1, $2))')
343 ('foo(bar($1, $2))', None, None, 'invalid argument list')
341 ('foo(bar($1, $2))', None, 'invalid argument list')
344 342 >>> builddecl('foo("bar")')
345 ('foo("bar")', None, None, 'invalid argument list')
343 ('foo("bar")', None, 'invalid argument list')
346 344 >>> builddecl('foo($1, $2')
347 ('foo($1, $2', None, None, 'at 10: unexpected token: end')
345 ('foo($1, $2', None, 'at 10: unexpected token: end')
348 346 >>> builddecl('foo("bar')
349 ('foo("bar', None, None, 'at 5: unterminated string')
347 ('foo("bar', None, 'at 5: unterminated string')
350 348 >>> builddecl('foo($1, $2, $1)')
351 ('foo', None, None, 'argument names collide with each other')
349 ('foo', None, 'argument names collide with each other')
352 350 """
353 351 try:
354 352 tree = cls._parse(decl)
355 353 except error.ParseError as inst:
356 return (decl, None, None, parseerrordetail(inst))
354 return (decl, None, parseerrordetail(inst))
357 355
358 356 if tree[0] == cls._symbolnode:
359 357 # "name = ...." style
360 358 name = tree[1]
361 359 if name.startswith('$'):
362 return (decl, None, None, _("'$' not for alias arguments"))
363 return (name, tree, None, None)
360 return (decl, None, _("'$' not for alias arguments"))
361 return (name, None, None)
364 362
365 363 if tree[0] == cls._funcnode and tree[1][0] == cls._symbolnode:
366 364 # "name(arg, ....) = ...." style
367 365 name = tree[1][1]
368 366 if name.startswith('$'):
369 return (decl, None, None, _("'$' not for alias arguments"))
367 return (decl, None, _("'$' not for alias arguments"))
370 368 args = []
371 369 for arg in cls._getlist(tree[2]):
372 370 if arg[0] != cls._symbolnode:
373 return (decl, None, None, _("invalid argument list"))
371 return (decl, None, _("invalid argument list"))
374 372 args.append(arg[1])
375 373 if len(args) != len(set(args)):
376 return (name, None, None,
377 _("argument names collide with each other"))
378 return (name, tree[:2], args, None)
374 return (name, None, _("argument names collide with each other"))
375 return (name, args, None)
379 376
380 return (decl, None, None, _("invalid format"))
377 return (decl, None, _("invalid format"))
381 378
382 379 @classmethod
383 380 def _relabelargs(cls, tree, args):
@@ -449,7 +446,7 b' class basealiasrules(object):'
449 446 def build(cls, decl, defn):
450 447 """Parse an alias declaration and definition into an alias object"""
451 448 repl = efmt = None
452 name, tree, args, err = cls._builddecl(decl)
449 name, args, err = cls._builddecl(decl)
453 450 if err:
454 451 efmt = _('failed to parse the declaration of %(section)s '
455 452 '"%(name)s": %(error)s')
@@ -462,7 +459,7 b' class basealiasrules(object):'
462 459 '"%(name)s": %(error)s')
463 460 if err:
464 461 err = efmt % {'section': cls._section, 'name': name, 'error': err}
465 return alias(name, tree, args, err, repl)
462 return alias(name, args, err, repl)
466 463
467 464 @classmethod
468 465 def buildmap(cls, items):
@@ -484,12 +481,12 b' class basealiasrules(object):'
484 481 if tree[0] == cls._symbolnode:
485 482 name = tree[1]
486 483 a = aliases.get(name)
487 if a and a.args is None and a.tree == tree:
484 if a and a.args is None:
488 485 return a
489 486 if tree[0] == cls._funcnode and tree[1][0] == cls._symbolnode:
490 487 name = tree[1][1]
491 488 a = aliases.get(name)
492 if a and a.args is not None and a.tree == tree[:2]:
489 if a and a.args is not None:
493 490 return a
494 491 return None
495 492
General Comments 0
You need to be logged in to leave comments. Login now