o
    ôjW  ã                	   @   sl   d dl Z d dlmZmZmZmZ G dd„ dƒZedkr4edƒZe	ej
ddgd	d
gddddgg d�ƒ dS dS )é    N)ÚMappingÚMatchÚOptionalÚSequencec                   @   s„   e Zd ZU dZe eej¡Zee	d< ee	d< e
dedd fdd„ƒZddededdfd	d
„Z	ddeeeef  dedefdd„ZdS )ÚCodeTemplatez-(^[^\n\S]*)?\$([^\d\W]\w*|\{,?[^\d\W]\w*\,?})ÚpatternÚfilenameÚreturnc                 C   s:   t | ƒ�}t| ¡ | ƒW  d   ƒ S 1 sw   Y  d S ©N)Úopenr   Úread)r   Úf© r   úg/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/torchgen/code_template.pyÚ	from_file   s   
$ÿzCodeTemplate.from_fileÚ Nc                 C   s   || _ || _d S r
   )r   r   )Úselfr   r   r   r   r   Ú__init__   s   
zCodeTemplate.__init__ÚenvÚkwargsc                    sj   ˆ d u ri ‰ dt dtf‡ ‡fdd„‰dt dtt dt fdd„‰dtt  dt f‡‡fd	d
„}| j || j¡S )NÚvr	   c                    s$   ˆ d usJ ‚| ˆv rˆ|  S ˆ |  S r
   r   )r   )r   r   r   r   Úlookup$   s   z'CodeTemplate.substitute.<locals>.lookupÚindentc                    s   d  ‡ fdd„|D ƒ¡ ¡ S )Nr   c                    s*   g | ]}t |ƒ ¡ D ]}ˆ | d  ‘q
qS )Ú
)ÚstrÚ
splitlines)Ú.0ÚeÚl©r   r   r   Ú
<listcomp>*   s   * zACodeTemplate.substitute.<locals>.indent_lines.<locals>.<listcomp>)ÚjoinÚrstrip)r   r   r   r   r   Úindent_lines(   s
   ÿþz-CodeTemplate.substitute.<locals>.indent_linesÚmatchc                    sØ   |   d¡}|   d¡}d}d}|d dkr6|dd… }|d dkr(d}|dd … }|d dkr6d}|d d… }ˆ|ƒ}|d urKt|tƒsF|g}ˆ ||ƒS t|tƒrhd d	d
„ |D ƒ¡}t|ƒdkrb|S || | S t|ƒS )Né   é   r   r   Ú{éÿÿÿÿú,z, c                 S   s   g | ]}t |ƒ‘qS r   )r   )r   Úxr   r   r   r    @   s    z<CodeTemplate.substitute.<locals>.replace.<locals>.<listcomp>)ÚgroupÚ
isinstanceÚlistr!   Úlenr   )r$   r   ÚkeyZcomma_beforeZcomma_afterr   Zmiddle)r#   r   r   r   Úreplace-   s.   




z(CodeTemplate.substitute.<locals>.replace)r   Úobjectr   r   ÚsubstitutionÚsubr   )r   r   r   r0   r   )r   r#   r   r   r   Ú
substitute   s   zCodeTemplate.substitute)r   r
   )Ú__name__Ú
__module__Ú__qualname__Zsubstitution_strÚreÚcompileÚ	MULTILINEr2   r   Ú__annotations__Ústaticmethodr   r   r   r   r1   r4   r   r   r   r   r      s    
 ÿÿÿþr   Ú__main__zŽ    int foo($args) {

        $bar
            $bar
        $a+$b
    }
    int commatest(int a${,stuff})
    int notest(int a${,empty,})
    Úhié   Úwhaté   é   é   z	things...Úothers)ÚargsÚbarÚaÚbÚstuffÚempty)r8   Útypingr   r   r   r   r   r5   ÚcÚprintr4   r   r   r   r   Ú<module>   s$    <ÿúÿó