o
    iW                  	   @   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   e/var/www/html/eduruby.in/lip-sync/lip-sync-env/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   middle)r#   r   r   r   replace-   s.   




z(CodeTemplate.substitute.<locals>.replace)r   objectr   r   substitutionsubr   )r   r   r   r1   r   )r   r#   r   r   r   
substitute   s   zCodeTemplate.substitute)r   r
   )__name__
__module____qualname__Zsubstitution_strrecompile	MULTILINEr3   r   __annotations__staticmethodr   r   r   r   r2   r5   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...Zothers)argsbarabstuffempty)r9   typingr   r   r   r   r   r6   cprintr5   r   r   r   r   <module>   s$    <