o
    I5ii                  	   @  sp   d dl mZ d dlZd dlmZmZ G dd dZedkr6edZe	ej
dd	gd
dgddddgg d dS dS )    )annotationsN)MappingSequencec                   @  sX   e Zd ZU dZeeejZded< ded< e	dddZ
ddd
dZ	ddddZdS )CodeTemplatez-(^[^\n\S]*)?\$([^\d\W]\w*|\{,?[^\d\W]\w*\,?})strpatternfilenamereturnc                 C  s:   t | }t| | W  d    S 1 sw   Y  d S N)openr   read)r   f r   d/lsinfo/ai/hellotax_ai/llm_service/venv_embed/lib/python3.10/site-packages/torchgen/code_template.py	from_file   s   
$zCodeTemplate.from_file Nonec                 C  s   || _ || _d S r
   )r   r   )selfr   r   r   r   r   __init__   s   
zCodeTemplate.__init__NenvMapping[str, object] | Nonekwargsobjectc                   sF    d u ri  d fdddd	d
dfdd}| j || jS )Nvr   r	   r   c                   s$    d usJ | v r|  S  |  S r
   r   )r   )r   r   r   r   lookup'   s   z'CodeTemplate.substitute.<locals>.lookupindentSequence[object]c                   s   d  fdd|D  S )Nr   c                   s*   g | ]}t | D ]} | d  q
qS )
)r   
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matchre.Match[str]c                   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#   C   s    z<CodeTemplate.substitute.<locals>.replace.<locals>.<listcomp>)group
isinstancelistr$   lenr   )r'   r   keycomma_beforecomma_afterr   middle)r&   r   r   r   replace0   s.   




z(CodeTemplate.substitute.<locals>.replace)r   r   r	   r   )r   r   r   r   r	   r   )r'   r(   r	   r   )substitutionsubr   )r   r   r   r7   r   )r   r&   r   r   r   
substitute!   s   
zCodeTemplate.substitute)r   r   r	   r   )r   )r   r   r   r   r	   r   r
   )r   r   r   r   r	   r   )__name__
__module____qualname__substitution_strrecompile	MULTILINEr8   __annotations__staticmethodr   r   r:   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)
__future__r   r?   typingr   r   r   r;   cprintr:   r   r   r   r   <module>   s&    <