
    	^clf                         d dl mZ d dlmZmZ d dlmZ  G d d          Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd ZddZd Z G d d          Z G d d          ZdS )   )_)errorutil)
stringutilc                   J    e Zd ZddZd Zd Zd ZddZddZd	 Z	d
 Z
d ZdS )parserNc                 0    || _         || _        d | _        d S N)	_elements_methodscurrent)selfelementsmethodss      2/usr/lib/python3/dist-packages/mercurial/parser.py__init__zparser.__init__   s    !    c                 H    | j         }t          | j        d          | _         |S )zadvance the tokenizerN)r   next_iter)r   ts     r   _advancezparser._advance"   s!    LDJ--r   c                 \    t          | j        | j        d                  dd                   S )z%True if next token may start new term    r      )anyr   r   )r   s    r   _hasnewtermzparser._hasnewterm(   s&    4>$,q/21Q37888r   c                     | j         d         |k    r;t          j        t          d          | j         d         z  | j         d                   |                                  dS )z0make sure the tokenizer matches an end conditionr   s   unexpected token: %s   N)r   r   
ParseErrorr   r   )r   ms     r   _matchzparser._match,   sZ    <?a")**T\!_<dl1o   	r   c                     |r| j         d         |k    rd}n|                     |          }|r|                     |           |S )zLgather right-hand-side operand until an end condition or binding
        metr   N)r   _parser"   )r   bindr!   exprs       r   _parseoperandzparser._parseoperand4   sP      	%aA%%DD;;t$$D 	KKNNNr   r   c                    |                                  \  }}}| j        |         dd         \  }}|r|r|                                 s||f}nB|r|d          | j        |dd           f}n%t	          j        t          d          |z  |          || j        | j        d                  d         k     r|                                  \  }}}| j        |         dd          \  }}	|	r|r|                                 s|	|f}nC|r|d         | | j        |dd           f}n%t	          j        t          d          |z  |          || j        | j        d                  d         k     |S )Nr   r   r   s   not a prefix: %ss   not an infix: %s)r   r   r   r'   r   r    r   r   )
r   r%   tokenvalueposprimaryprefixr&   infixsuffixs
             r   r$   zparser._parse?   s    MMOOuc./!4 	HF 	Ht'7'7'9'9 	HU#DD 	H1I1t16!"":>?DD"1%8#9#9E#A3GGGT^DLO4Q777 $E5# N51!""5ME6 Lu L)9)9);); L~ La$(:(:E!""I(FG&q)<'='='EsKKK T^DLO4Q777 r   c                 ~    || _         |                                  |                                 }| j        \  }}}||fS )z!generate a parse tree from tokens)r   r   r$   r   )r   	tokeniterresr)   r*   r+   s         r   parsezparser.parseV   s:    
kkmm LucCxr   c                      t          |t                    s|S   j        |d                   fd|dd         D              S )z4recursively evaluate a parse tree using node methodsr   c                 :    g | ]}                     |          S  )eval).0r   r   s     r   
<listcomp>zparser.eval.<locals>.<listcomp>b   s#    'G'G'G		!'G'G'Gr   r   N)
isinstancetupler   )r   trees   ` r   r7   zparser.eval^   sO    $&& 	K%t}T!W%'G'G'G'Gd122h'G'G'GHHr   c                 h    |                      |          }| j        r|                     |          S |S )z<parse tokens into a parse tree and evaluate if methods given)r3   r   r7   )r   r1   r   s      r   __call__zparser.__call__d   s2    JJy!!= 	 99Q<<r   r
   )r   )__name__
__module____qualname__r   r   r   r"   r'   r$   r3   r7   r>   r6   r   r   r   r      s           
  9 9 9  	 	 	 	   .  I I I    r   r   c                    d}|                      d          \  }}}|rY|                                }|st          j        d          t	          |          dk    rt          j        d          |d         }|                     d          \  }}}|                                }|                                }|r*|st          j        d          ||d         |dd         |fS g d||fS )	a  Parse spec of function arguments into (poskeys, varkey, keys, optkey)

    >>> splitargspec(b'')
    ([], None, [], None)
    >>> splitargspec(b'foo bar')
    ([], None, ['foo', 'bar'], None)
    >>> splitargspec(b'foo *bar baz **qux')
    (['foo'], 'bar', ['baz'], 'qux')
    >>> splitargspec(b'*foo')
    ([], 'foo', [], None)
    >>> splitargspec(b'**foo')
    ([], None, [], 'foo')
    Ns   **s   no **optkey name providedr   s!   excessive **optkey names providedr      *s   no *varkey name provided)	partitionsplitr   ProgrammingErrorlen)specoptkeypreseppostpostspress          r   splitargspecrO   l   s     F^^E**NCd
 

 	G()EFFFu::>>()MNNNq]]4((NCd99;;DJJLLE
 1 	F()DEEEU1XuQRRy&00tT6!!r   c                    |\  }}}}t          fdt          |           D             t          |                     }	|	t          |          k     r4t          j        t          d          |t          |          dz            |sg|	t          |          t          |          z   k    rDt          j        t          d          |t          |          t          |          z   dz            t          j                    }
t          || d|	                   D ]
\  }}||
|<   |r| t          |
          |	         |
|<   n0t          || t          |
          |	                   D ]
\  }}||
|<   |rt          j                    |
|<   | |	d         D ]}|r|d         k    s|d         d         |k    r&t          j        t          d          d	|iz            |d         d         }||v r|
}n1|s't          j        t          d
          ||dz            |
|         }||v r't          j        t          d          ||dz            |d         ||<   |
S )a  Build dict from list containing positional and keyword arguments

    Arguments are specified by a tuple of ``(poskeys, varkey, keys, optkey)``
    where

    - ``poskeys``: list of names of positional arguments
    - ``varkey``: optional argument name that takes up remainder
    - ``keys``: list of names that can be either positional or keyword arguments
    - ``optkey``: optional argument name that takes up excess keyword arguments

    If ``varkey`` specified, all ``keys`` must be given as keyword arguments.

    Invalid keywords, too few positional arguments, or too many positional
    arguments are rejected, but missing keyword arguments are just omitted.
    c              3   >   K   | ]\  }}||d          k    |V  dS r   Nr6   )r8   ixkeyvaluenodes      r   	<genexpr>z buildargsdict.<locals>.<genexpr>   s:      FFtq!1F11E1E1E1E1E1EFFr   s6   %(func)s takes at least %(nargs)d positional arguments)   funcs   nargss5   %(func)s takes at most %(nargs)d positional argumentsNr   r   s    %(func)s got an invalid argumentrW   s5   %(func)s got an unexpected keyword argument '%(key)s')rW   s   keys;   %(func)s got multiple values for keyword argument '%(key)s'r   )	r   	enumeraterG   r   r    r   r   sortdictzip)treesfuncnameargspecrU   keynodeposkeysvarkeykeysrI   kwstartargskrT   ds      `          r   buildargsdictrf      s     %,!GVT6FFFFy''FFFE

 G WGHH CLL99:
 
 	
  
gGs4yy 888FGG CLL3t99,DEEF
 
 	
 =??DGU8G8_--  1Q SYY01VeCII$7899 	 	DAqDGG '}V788_   	AaDL((AaDGw,>,>"566'89LL   aDG99AA 	"JKK$a001  
 VA66"*  %a00	1   t!Kr   c                     	 t          j        |           S # t          $ r=}t          j        t          j        |                                                    d }~ww xY wr
   )r   unescapestr
ValueErrorr   r    forcebytestrlower)ses     r   rh   rh      sf    C%a((( C C C
 z6q99??AABBBCs    
A8AAc                    t          | t                    s+|                    |t          j        |           f           d S | d         |v rYt          t          j        | dd                    }|                    |d| d         d                    |          fz  f           d S |                    |d| d         z  f           | dd          D ]}t          |||dz   |           |d         d         |d         d         dz   fg|dd <   d S )Nr   r   s   (%s %s)    s   (%s   ))r:   r;   appendr   pprintmapjoin_prettyformat)r<   	leafnodeslevellinesrsrl   s         r   rv   rv      s   dE"" 	;eZ.t44566666	aI		"DH--eZ47DIIbMM*BBCDDDDDeVd1g-.///abb 	: 	:A!Y	59999Ry|U2Yq\D%89:bcc


r   c                 l    g }t          | |d|           d                    d |D                       }|S )Nr      
c              3   ,   K   | ]\  }}d |z  |z   V  dS )s     Nr6   )r8   lrl   s      r   rV   zprettyformat.<locals>.<genexpr>   s.      ::DAqQ::::::r   )rv   ru   )r<   rw   ry   outputs       r   prettyformatr      s@    E$	1e,,,ZZ::E:::::FMr   c                    t          | t                    s| S | d         }|vr'|ft          fd| dd         D                       z   S g }| }|d         |k    r>|dd         \  }}|                    t          |                     |}|d         |k    >|                    t          |                     |                    |           t          t	          |                    S )a_  Flatten chained infix operations to reduce usage of Python stack

    >>> from . import pycompat
    >>> def f(tree):
    ...     s = prettyformat(simplifyinfixops(tree, (b'or',)), (b'symbol',))
    ...     print(pycompat.sysstr(s))
    >>> f((b'or',
    ...     (b'or',
    ...       (b'symbol', b'1'),
    ...       (b'symbol', b'2')),
    ...     (b'symbol', b'3')))
    (or
      (symbol '1')
      (symbol '2')
      (symbol '3'))
    >>> f((b'func',
    ...     (b'symbol', b'p1'),
    ...     (b'or',
    ...       (b'or',
    ...         (b'func',
    ...           (b'symbol', b'sort'),
    ...           (b'list',
    ...             (b'or',
    ...               (b'or',
    ...                 (b'symbol', b'1'),
    ...                 (b'symbol', b'2')),
    ...               (b'symbol', b'3')),
    ...             (b'negate',
    ...               (b'symbol', b'rev')))),
    ...         (b'and',
    ...           (b'symbol', b'4'),
    ...           (b'group',
    ...             (b'or',
    ...               (b'or',
    ...                 (b'symbol', b'5'),
    ...                 (b'symbol', b'6')),
    ...               (b'symbol', b'7'))))),
    ...       (b'symbol', b'8'))))
    (func
      (symbol 'p1')
      (or
        (func
          (symbol 'sort')
          (list
            (or
              (symbol '1')
              (symbol '2')
              (symbol '3'))
            (negate
              (symbol 'rev'))))
        (and
          (symbol '4')
          (group
            (or
              (symbol '5')
              (symbol '6')
              (symbol '7'))))
        (symbol '8')))
    r   c              3   8   K   | ]}t          |          V  d S r
   )simplifyinfixops)r8   rT   targetnodess     r   rV   z#simplifyinfixops.<locals>.<genexpr>4  s.      PP!-a==PPPPPPr   r   N)r:   r;   rr   r   reversed)r<   r   op
simplifiedrT   r~   rs    `     r   r   r      s   x dE"" 	aB	uuPPPPtABBxPPPPPPP
 JA
A$"**u1*1k::;;; A$"** &q+66777b*%%&&&r   c                     | k    r                                 S t          | t                    s| S t          fd| D                       S )Nc              3   :   K   | ]}t          |          V  d S r
   )
_buildtree)r8   rT   placeholder	replstacks     r   rV   z_buildtree.<locals>.<genexpr>I  s/      II1A{I66IIIIIIr   )popr:   r;   )templater   r   s    ``r   r   r   D  sZ    ;}}h&& IIIIIIIIIIIr   c                     t          |t                    st          j        d          t	          t          |                    }t          | ||          }|rt          j        d          |S )a  Create new tree by substituting placeholders by replacements

    >>> _ = (b'symbol', b'_')
    >>> def f(template, *repls):
    ...     return buildtree(template, _, *repls)
    >>> f((b'func', (b'symbol', b'only'), (b'list', _, _)),
    ...   ('symbol', '1'), ('symbol', '2'))
    ('func', ('symbol', 'only'), ('list', ('symbol', '1'), ('symbol', '2')))
    >>> f((b'and', _, (b'not', _)), (b'symbol', b'1'), (b'symbol', b'2'))
    ('and', ('symbol', '1'), ('not', ('symbol', '2')))
        placeholder must be a node tuples   too many replacements)r:   r;   r   rF   listr   r   )r   r   replsr   r   s        r   	buildtreer   L  sl     k5)) J$%HIIIXe__%%I8[)44A ?$%=>>>Hr   c                 X   | |k    rdS t          | t                    rt          |t                    sdS | k    r!|d         vr                    |           dS t          |           t          |          k    rdS t	          fdt          | |          D                       S )NTFr   c              3   D   K   | ]\  }}t          ||          V  d S r
   )
_matchtree)r8   prT   incompletenodesmatchesr   s      r   rV   z_matchtree.<locals>.<genexpr>k  sK        Aq 	1aow??     r   )r:   r;   rr   rG   allrZ   patternr<   r   r   r   s     ```r   r   r   a  s    $tgu%% Ze-D-D u+$q'"@"@tt
7||s4yy  u      &&     r   Nr6   c                     |)t          |t                    st          j        d          |g}t	          | ||||          r|S dS )a	  If a tree matches the pattern, return a list of the tree and nodes
    matched with the placeholder; Otherwise None

    >>> def f(pattern, tree):
    ...     m = matchtree(pattern, tree, _, {b'keyvalue', b'list'})
    ...     if m:
    ...         return m[1:]

    >>> _ = (b'symbol', b'_')
    >>> f((b'func', (b'symbol', b'ancestors'), _),
    ...   (b'func', (b'symbol', b'ancestors'), (b'symbol', b'1')))
    [('symbol', '1')]
    >>> f((b'func', (b'symbol', b'ancestors'), _),
    ...   (b'func', (b'symbol', b'ancestors'), None))
    >>> f((b'range', (b'dagrange', _, _), _),
    ...   (b'range',
    ...     (b'dagrange', (b'symbol', b'1'), (b'symbol', b'2')),
    ...     (b'symbol', b'3')))
    [('symbol', '1'), ('symbol', '2'), ('symbol', '3')]

    The placeholder does not match the specified incomplete nodes because
    an incomplete node (e.g. argument list) cannot construct an expression.

    >>> f((b'func', (b'symbol', b'ancestors'), _),
    ...   (b'func', (b'symbol', b'ancestors'),
    ...     (b'list', (b'symbol', b'1'), (b'symbol', b'2'))))

    The placeholder may be omitted, but which shouldn't match a None node.

    >>> _ = None
    >>> f((b'func', (b'symbol', b'ancestors'), None),
    ...   (b'func', (b'symbol', b'ancestors'), (b'symbol', b'0')))
    Nr   )r:   r;   r   rF   r   r   s        r   	matchtreer   q  sZ    D z+u'E'E$%HIIIfG'4owGG  r   c                 Z    | j         t          d          | j         | j        fz  S | j        S )z6Compose error message from specified ParseError objectNs	   at %d: %s)locationr   message)insts    r   parseerrordetailr     s,    } $-!>>>|r   c                       e Zd ZdZd ZdS )aliaszParsed result of aliasc                 L    || _         || _        || _        || _        d| _        d S )NF)namerc   r   replacementwarned)r   r   rc   errr   s        r   r   zalias.__init__  s,    		
& r   N)r?   r@   rA   __doc__r   r6   r   r   r   r     s)              r   r   c                      e Zd ZdZdZdZd Zed             Zed             Z	e
d             Ze
d             Ze
d	             Ze
d
             Ze
d             Ze
d             Ze
d             Ze
d             Ze
d             ZdS )basealiasrulesaw  Parsing and expansion rule set of aliases

    This is a helper for fileset/revset/template aliases. A concrete rule set
    should be made by sub-classing this and implementing class/static methods.

    It supports alias expansion of symbol and function-call styles::

        # decl = defn
        h = heads(default)
        b($1) = ancestors($1) - ancestors(default)
    Ns   symbolc                 0    t          d| j        z            )Ns   '%s' is not instantiatable)	TypeErrorr?   )clss    r   __new__zbasealiasrules.__new__  s    5DEEEr   c                     t           )z-Parse an alias name, arguments and definitionNotImplementedError)rH   s    r   r$   zbasealiasrules._parse  
     "!r   c                     t           )z9Return (name, args) if tree is a function; otherwise Noner   )r<   s    r   _trygetfunczbasealiasrules._trygetfunc  r   r   c                     	                       |          }n.# t          j        $ r}|dt          |          fcY d}~S d}~ww xY w|d          j        k    r7|d         }|                    d          r|dt          d          |z  fS |ddfS                      |          }|r|\  }}|                    d          r|dt          d          |z  fS t           fd|D                       r|dt          d          fS t          |          t          t          |                    k    r|dt          d	          fS |d
 |D             dfS |dt          d          fS )a  Parse an alias declaration into ``(name, args, errorstr)``

        This function analyzes the parsed tree. The parsing rule is provided
        by ``_parse()``.

        - ``name``: of declared alias (may be ``decl`` itself at error)
        - ``args``: list of argument names (or None for symbol declaration)
        - ``errorstr``: detail about detected error (or None)

        >>> sym = lambda x: (b'symbol', x)
        >>> symlist = lambda *xs: (b'list',) + tuple(sym(x) for x in xs)
        >>> func = lambda n, a: (b'func', sym(n), a)
        >>> parsemap = {
        ...     b'foo': sym(b'foo'),
        ...     b'$foo': sym(b'$foo'),
        ...     b'foo::bar': (b'dagrange', sym(b'foo'), sym(b'bar')),
        ...     b'foo()': func(b'foo', None),
        ...     b'$foo()': func(b'$foo', None),
        ...     b'foo($1, $2)': func(b'foo', symlist(b'$1', b'$2')),
        ...     b'foo(bar_bar, baz.baz)':
        ...         func(b'foo', symlist(b'bar_bar', b'baz.baz')),
        ...     b'foo(bar($1, $2))':
        ...         func(b'foo', func(b'bar', symlist(b'$1', b'$2'))),
        ...     b'foo($1, $2, nested($1, $2))':
        ...         func(b'foo', (symlist(b'$1', b'$2') +
        ...                      (func(b'nested', symlist(b'$1', b'$2')),))),
        ...     b'foo("bar")': func(b'foo', (b'string', b'bar')),
        ...     b'foo($1, $2': error.ParseError(b'unexpected token: end', 10),
        ...     b'foo("bar': error.ParseError(b'unterminated string', 5),
        ...     b'foo($1, $2, $1)': func(b'foo', symlist(b'$1', b'$2', b'$1')),
        ... }
        >>> def parse(expr):
        ...     x = parsemap[expr]
        ...     if isinstance(x, Exception):
        ...         raise x
        ...     return x
        >>> def trygetfunc(tree):
        ...     if not tree or tree[0] != b'func' or tree[1][0] != b'symbol':
        ...         return None
        ...     if not tree[2]:
        ...         return tree[1][1], []
        ...     if tree[2][0] == b'list':
        ...         return tree[1][1], list(tree[2][1:])
        ...     return tree[1][1], [tree[2]]
        >>> class aliasrules(basealiasrules):
        ...     _parse = staticmethod(parse)
        ...     _trygetfunc = staticmethod(trygetfunc)
        >>> builddecl = aliasrules._builddecl
        >>> builddecl(b'foo')
        ('foo', None, None)
        >>> builddecl(b'$foo')
        ('$foo', None, "invalid symbol '$foo'")
        >>> builddecl(b'foo::bar')
        ('foo::bar', None, 'invalid format')
        >>> builddecl(b'foo()')
        ('foo', [], None)
        >>> builddecl(b'$foo()')
        ('$foo()', None, "invalid function '$foo'")
        >>> builddecl(b'foo($1, $2)')
        ('foo', ['$1', '$2'], None)
        >>> builddecl(b'foo(bar_bar, baz.baz)')
        ('foo', ['bar_bar', 'baz.baz'], None)
        >>> builddecl(b'foo($1, $2, nested($1, $2))')
        ('foo($1, $2, nested($1, $2))', None, 'invalid argument list')
        >>> builddecl(b'foo(bar($1, $2))')
        ('foo(bar($1, $2))', None, 'invalid argument list')
        >>> builddecl(b'foo("bar")')
        ('foo("bar")', None, 'invalid argument list')
        >>> builddecl(b'foo($1, $2')
        ('foo($1, $2', None, 'at 10: unexpected token: end')
        >>> builddecl(b'foo("bar')
        ('foo("bar', None, 'at 5: unterminated string')
        >>> builddecl(b'foo($1, $2, $1)')
        ('foo', None, 'argument names collide with each other')
        Nr   r      $   invalid symbol '%s's   invalid function '%s'c              3   :   K   | ]}|d          j         k    V  dS rR   )_symbolnode)r8   r   r   s     r   rV   z,basealiasrules._builddecl.<locals>.<genexpr>.  s.      99q1Q43?*999999r   s   invalid argument lists&   argument names collide with each otherc                     g | ]
}|d          S )r   r6   )r8   r   s     r   r9   z-basealiasrules._builddecl.<locals>.<listcomp>6  s    ...A1Q4...r   s   invalid format)r$   r   r    r   r   
startswithr   r   r   rG   set)r   declr<   r   r   funcrc   s   `      r   
_builddeclzbasealiasrules._builddecl  s   Z	8::d##DD 	8 	8 	8$ 0 6 67777777	8 7co%%7Dt$$ FdA&<$=$=$DEE$%%t$$ 	6JD$t$$ HdA&>$?$?$$FGG9999D99999 AdA&>$?$?@@4yyCD		NN**?@@ 
 .....55dA/0011s    A?AAc                 l    t          |t                    s|S |d         }| j        k    r(|ft           fd|dd         D                       z   S t          |          dk    sJ |d         }|v rd}n9|                    d          r$t          j        t          d          |z            ||fS )	z%Mark alias arguments as ``_aliasarg``r   c              3   D   K   | ]}                     |          V  d S r
   )_relabelargs)r8   rT   rc   r   s     r   rV   z.basealiasrules._relabelargs.<locals>.<genexpr>A  s3       M Mq!1!1!T!:!: M M M M M Mr   r   Nr   	   _aliasargr   r   )r:   r;   r   rG   r   r   r    r   )r   r<   rc   r   syms   ` `  r   r   zbasealiasrules._relabelargs:  s     $&& 	K!W  55 M M M M MDH M M MMMMM4yyA~~~~1g$;;BB^^D!! 	D"1%;#<#<s#BCCCCyr   c                     |                      |          }|rt          |          }nt                      }|                     ||          S )a  Parse an alias definition into a tree and marks substitutions

        This function marks alias argument references as ``_aliasarg``. The
        parsing rule is provided by ``_parse()``.

        ``args`` is a list of alias argument names, or None if the alias
        is declared as a symbol.

        >>> from . import pycompat
        >>> parsemap = {
        ...     b'$1 or foo': (b'or', (b'symbol', b'$1'), (b'symbol', b'foo')),
        ...     b'$1 or $bar':
        ...         (b'or', (b'symbol', b'$1'), (b'symbol', b'$bar')),
        ...     b'$10 or baz':
        ...         (b'or', (b'symbol', b'$10'), (b'symbol', b'baz')),
        ...     b'"$1" or "foo"':
        ...         (b'or', (b'string', b'$1'), (b'string', b'foo')),
        ... }
        >>> class aliasrules(basealiasrules):
        ...     _parse = staticmethod(parsemap.__getitem__)
        ...     _trygetfunc = staticmethod(lambda x: None)
        >>> builddefn = aliasrules._builddefn
        >>> def pprint(tree):
        ...     s = prettyformat(tree, (b'_aliasarg', b'string', b'symbol'))
        ...     print(pycompat.sysstr(s))
        >>> args = [b'$1', b'$2', b'foo']
        >>> pprint(builddefn(b'$1 or foo', args))
        (or
          (_aliasarg '$1')
          (_aliasarg 'foo'))
        >>> try:
        ...     builddefn(b'$1 or $bar', args)
        ... except error.ParseError as inst:
        ...     print(pycompat.sysstr(parseerrordetail(inst)))
        invalid symbol '$bar'
        >>> args = [b'$1', b'$10', b'foo']
        >>> pprint(builddefn(b'$10 or baz', args))
        (or
          (_aliasarg '$10')
          (symbol 'baz'))
        >>> pprint(builddefn(b'"$1" or "foo"', args))
        (or
          (string '$1')
          (string 'foo'))
        )r$   r   r   )r   defnrc   r<   s       r   
_builddefnzbasealiasrules._builddefnK  sJ    ^ zz$ 	t99DD55Dd+++r   c                 H   dx}}|                      |          \  }}}|rt          d          }nR	 |                     ||          }n:# t          j        $ r(}t          |          }t          d          }Y d}~nd}~ww xY w|r|| j        ||dz  }t          ||||          S )z>Parse an alias declaration and definition into an alias objectNs4   bad declaration of %(section)s "%(name)s": %(error)ss3   bad definition of %(section)s "%(name)s": %(error)s)   section   names   error)r   r   r   r   r    r   _sectionr   )	r   r   r   replefmtr   rc   r   r   s	            r   buildzbasealiasrules.build  s     t....dC 	QLMMDDQ~~dD11# Q Q Q&t,,OPPQ  	L  C
 T4d+++s   A A?A::A?c                 Z    i }|D ]%\  }}|                      ||          }|||j        <   &|S )zTParse a list of alias (name, replacement) pairs into a dict of
        alias objects)r   r   )r   itemsaliasesr   r   as         r   buildmapzbasealiasrules.buildmap  sA      	  	 JD$		$%%AGAFOOr   c                 &   t          |t                    sdS |d         | j        k    r*|d         }|                    |          }|r|j        |dfS |                     |          }|r'|\  }}|                    |          }|r|j        ||fS dS )zrIf tree looks like an unexpanded alias, return (alias, pattern-args)
        pair. Return None otherwise.
        Nr   r   )r:   r;   r   getrc   r   )r   r   r<   r   r   r   rc   s          r   	_getaliaszbasealiasrules._getalias  s    
 $&& 	47co%%7DD!!A QV^$wt$$ 	JD$D!!A QV'$wtr   c                      t          |t                    s|S |d         dk    r|d         }|         S t           fd|D                       S )zoReplace _aliasarg instances with the substitution value of the
        same name in args, recursively.
        r   r   r   c              3   D   K   | ]}                     |          V  d S r
   )_expandargs)r8   r   rc   r   s     r   rV   z-basealiasrules._expandargs.<locals>.<genexpr>  s1      <<!S__Q--<<<<<<r   )r:   r;   )r   r<   rc   r   s   ` ` r   r   zbasealiasrules._expandargs  se    
 $&& 	K7l""q'C9<<<<<t<<<<<<r   c           	      j    t          |t                    s|S                      |          }|t           fd|D                       S |\  }}|j        rt          j        |j                  |v r1t          j        t          d           j        |j        dz            	                    |           |j        vr% 
                    |j                  |j        <   |j                 }                                 |j        |S t          |          t          |j                  k    r1t          j        t          d          t          |          z             fd|D             }                     |t!          t#          |j        |                              S )Nc              3   H   K   | ]}                     |          V  d S r
   _expand)r8   r   r   cacher   	expandings     r   rV   z)basealiasrules._expand.<locals>.<genexpr>  sF        >?GQ	599     r   s5   infinite expansion of %(section)s "%(name)s" detected)r   r   s   invalid number of arguments: %dc                 @    g | ]}                     |g           S r6   r   )r8   r   r   r   r   s     r   r9   z*basealiasrules._expand.<locals>.<listcomp>  s+    ;;;AS[[!R//;;;r   )r:   r;   r   r   Abortr    r   r   r   rr   r   r   r   rc   rG   r   dictrZ   )	r   r   r<   r   r   r   r   r~   results	   `` ``    r   r   zbasealiasrules._expand  s   $&& 	KMM'4((9       CG      17 	'+ag&&&	>>"JKK"|af==>  
 	6KK	5 E!&M qv6>Mq66S[[  "455A>   <;;;;;;;;vtCNN';';<<<r   c                 2    |                      ||g i           S )zExpand aliases in tree, recursively.

        'aliases' is a dictionary mapping user defined aliases to alias objects.
        r   )r   r   r<   s      r   expandzbasealiasrules.expand  s     {{7D"b111r   )r?   r@   rA   r   r   r   r   staticmethodr$   r   classmethodr   r   r   r   r   r   r   r   r   r6   r   r   r   r     sk       
 
 HKF F F " " \" " " \" h2 h2 [h2T   [  3, 3, [3,j , , [,(   [   [& 	= 	= [	=  =  = [ =D 2 2 [2 2 2r   r   )Nr6   )i18nr    r   r   utilsr   r   rO   rf   rh   rv   r   r   r   r   r   r   r   r   r   r6   r   r   <module>r      s  (                   M M M M M M M M`" " "DC C CLC C C
; 
; 
;  M' M' M'`J J J  *   & & & &R         y2 y2 y2 y2 y2 y2 y2 y2 y2 y2r   