§
    8P„j  ã                   ó²   — d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlZddlm	Z	 ddlm
Z ddlmZ  G d	„ d
e¦  «        Z G d„ de	j        ¦  «        Zd„ ZdS )z,Generate code from an annotated syntax tree.é    )Úabsolute_import)Údivision)Úprint_functionN)Úannotate)Ú
formatting)Úfstring_utilsc                   ó   — e Zd ZdZdS )Ú
PrintErrorz2An exception for when we failed to print the tree.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© ó    úW/root/disk_3tb/conda_envs/Huy-visual/lib/python3.11/site-packages/pasta/base/codegen.pyr
   r
      s   € € € € € Ø:Ð:Ð:Ð:r   r
   c                   ón   ‡ — e Zd ZdZˆ fd„Zˆ fd„Zd„ Zd„ Zd„ Zd„ Z	d„ Z
	 dd
„Zdd„Zd„ Zd„ Zd„ Zˆ xZS )ÚPrinteraœ  Traverses an AST and generates formatted python source code.
  
  This uses the same base visitor as annotating the AST, but instead of eating a
  token it spits one out. For special formatting information which was stored on
  the node, this is output exactly as it was read in unless one or more of the
  dependency attributes used to generate it has changed, in which case its
  default formatting is used.
  c                 ód   •— t          t          | ¦  «                             ¦   «          d| _        d S ©NÚ )Úsuperr   Ú__init__Úcode)ÚselfÚ	__class__s    €r   r   zPrinter.__init__,   s*   ø€ Ý	�'�4ÑÔ×!Ò!Ñ#Ô#Ð#Ø€D„I€I€Ir   c                 óü   •— t          j        d„ ¦  «        |_        	 t          t          | ¦  «                             |¦  «         n4# t          t          t          t          f$ r}t          |¦  «        ‚d }~ww xY w|`d S )Nc                  ó   — dS )NFr   r   r   r   ú<lambda>zPrinter.visit.<locals>.<lambda>1   s   € ¸€ r   )ÚcollectionsÚdefaultdictÚ_printer_infor   r   ÚvisitÚ	TypeErrorÚ
ValueErrorÚ
IndexErrorÚKeyErrorr
   )r   ÚnodeÚer   s      €r   r"   zPrinter.visit0   s~   ø€ Ý$Ô0°°Ñ?Ô?€DÔðÝ�G�TÑÔ× Ò  Ñ&Ô&Ð&Ð&øÝ•z¥:­xÐ8ð ð ð Ý�q‰MŒMÐøøøøðøøøàÐÐÐs   �(A ÁA7Á#A2Á2A7c                 óÐ   — |                       |¦  «         t          j        |d¦  «        }| xj        |�|nt	          |j        ¦  «        z  c_        |                      |¦  «         d S ©NÚcontent)ÚprefixÚfmtÚgetr   ÚreprÚnÚsuffix©r   r'   r+   s      r   Ú	visit_NumzPrinter.visit_Num8   ó^   € Ø‡K‚K�ÑÔÐÝŒg�d˜IÑ&Ô&€GØ€I„I˜GÐ/��µT¸$¼&±\´\ÑA€I„IØ‡K‚K�ÑÔÐÐÐr   c                 óÐ   — |                       |¦  «         t          j        |d¦  «        }| xj        |�|nt	          |j        ¦  «        z  c_        |                      |¦  «         d S r*   ©r,   r-   r.   r   r/   Úsr1   r2   s      r   Ú	visit_StrzPrinter.visit_Str>   r4   r   c                 ó8  — |                       |¦  «         t          j        |d¦  «        }|€—g }|j        D ]k}t	          |t
          j        ¦  «        r|                     |j        ¦  «         Œ7|                     t          j
        t          |¦  «        ¦  «        ¦  «         Œlt          d                     |¦  «        ¦  «        }d„ t          j        |¦  «        D ¦   «         }| xj        t          j        ||¦  «        z  c_        |                      |¦  «         d S )Nr+   r   c                 ó,   — g | ]}t          |¦  «        ‘ŒS r   )Úto_str)Ú.0Úvs     r   ú
<listcomp>z+Printer.visit_JoinedStr.<locals>.<listcomp>Q   s   € ÐJÐJÐJ˜A�f�Q‰iŒiÐJÐJÐJr   )r,   r-   r.   ÚvaluesÚ
isinstanceÚastÚStrÚappendr7   r   ÚplaceholderÚlenr/   ÚjoinÚget_formatted_valuesr   Úperform_replacementsr1   )r   r'   r+   ÚpartsÚvalr?   s         r   Úvisit_JoinedStrzPrinter.visit_JoinedStrD   sû   € Ø‡K‚K�ÑÔÐÝŒg�d˜IÑ&Ô&€Gà€Ø€eØ”ð >ð >ˆ#Ý�c�3œ7Ñ#Ô#ð 	>Ø
�,Š,�s”uÑ
Ô
Ð
Ð
à
�,Š,•}Ô0µ°U±´Ñ<Ô<Ñ
=Ô
=Ð
=Ð
=Ý�R—W’W˜U‘^”^Ñ$Ô$€gàJÐJ¥Ô!CÀDÑ!IÔ!IÐJÑJÔJ€FØ€I„I•Ô3°G¸VÑDÔDÑD€I„IØ‡K‚K�ÑÔÐÐÐr   c                 óÐ   — |                       |¦  «         t          j        |d¦  «        }| xj        |�|nt	          |j        ¦  «        z  c_        |                      |¦  «         d S r*   r6   r2   s      r   Úvisit_ByteszPrinter.visit_BytesU   r4   r   c                 ó&   — | xj         |z  c_         d S )N)r   )r   Úvalues     r   ÚtokenzPrinter.token[   s   € Ø€I„I�Ñ€I„I€I€Ir   Fc                 ób   — ~t          j        ||¦  «        }|€|r|}| xj        |pdz  c_        d S r   )r-   r.   r   )r   r'   Ú	attr_nameÚ	token_valÚallow_whitespace_prefixÚdefaultrO   s          r   Úoptional_tokenzPrinter.optional_token^   s<   € àÝŒG�D˜)Ñ$Ô$€EØ€}˜€}Ø€eØ€I„I��˜"Ñ€I„I€I€Ir   Nc                 óð   ‡— ~t          ‰d¦  «        r‰j        |         rdS d‰j        |<   t          j        ‰|¦  «        }|�|rt	          ˆfd„|D ¦   «         ¦  «        r|}| xj        |�|ndz  c_        dS )a©  Add the formatted data stored for a given attribute on this node.

    If any of the dependent attributes of the node have changed since it was
    annotated, then the stored formatted data for this attr_name is no longer
    valid, and we must use the default instead.
    
    Arguments:
      node: (ast.AST) An AST node to retrieve formatting information from.
      attr_name: (string) Name to load the formatting information from.
      attr_vals: (list of functions/strings) Unused here.
      deps: (optional, set of strings) Attributes of the node which the stored
        formatting data depends on.
      default: (string) Default formatted data for this attribute.
    r!   NTc              3   ón   •K  — | ]/}t          ‰|d ¦  «        t          j        ‰|dz   ¦  «        k    V — Œ0d S )NÚ__src)Úgetattrr-   r.   )r<   Údepr'   s     €r   ú	<genexpr>zPrinter.attr.<locals>.<genexpr>{   sX   øè è € ð ð Øõ �D˜#˜tÑ$Ô$­¬°°c¸G±mÑ(DÔ(DÒDð ð ð ð ð ð r   r   )Úhasattrr!   r-   r.   Úanyr   )r   r'   rR   Ú	attr_valsÚdepsrU   rJ   s    `     r   ÚattrzPrinter.attrf   s°   ø€ ð 	Ý�4˜Ñ)Ô)ð ¨TÔ-?À	Ô-Jð Ø€fØ$(€DÔ�yÑ!Ý
Œ'�$˜	Ñ
"Ô
"€CØˆ�tˆÝð ð ð ð Øðñ ô ñ 	ô 	ð 	ð €cØ€I„I˜˜��¨RÑ/€I„I€I€Ir   c                 óP   — 	 t          j        |d¦  «        S # t          $ r Y dS w xY w)NÚis_elifF)r-   r.   ÚAttributeError©r   r'   s     r   Úcheck_is_elifzPrinter.check_is_elif€   s;   € ðÝŒW�T˜9Ñ%Ô%Ð%øÝð ð ð ØˆUˆUðøøøs   ‚ —
%¤%c                 ó$   — t          |dd¦  «        S ©NÚis_continuedF©rZ   re   s     r   Úcheck_is_continued_tryzPrinter.check_is_continued_try†   ó   € å�4˜¨Ñ/Ô/Ð/r   c                 ó$   — t          |dd¦  «        S rh   rj   re   s     r   Úcheck_is_continued_withzPrinter.check_is_continued_withŠ   rl   r   )FF)NN)r   r   r   r   r   r"   r3   r8   rK   rM   rP   rV   ra   rf   rk   rn   Ú__classcell__)r   s   @r   r   r   "   s  ø€ € € € € ðð ðð ð ð ð ðð ð ð ð ðð ð ðð ð ðð ð ð"ð ð ðð ð ð =Bðð ð ð ð0ð 0ð 0ð 0ð4ð ð ð0ð 0ð 0ð0ð 0ð 0ð 0ð 0ð 0ð 0r   r   c                 óz  — t          ¦   «         }t          j        d„ ¦  «        }t          j        | ¦  «        D ]*}t          j        |dd¦  «        }|r||xx         dz  cc<   Œ+|r<t          t          j	        |¦  «        d„ ¬¦  «        \  }}| 
                    |¦  «         |                     | ¦  «         |j        S )z8Convenient function to get the python source for an AST.c                  ó   — dS )Nr   r   r   r   r   r   zto_str.<locals>.<lambda>•   s   € °a€ r   Úindent_diffr   é   c                 ó&   — | d         r| d         ndS )Nr   rs   éÿÿÿÿr   )Útups    r   r   zto_str.<locals>.<lambda>œ   s   € °3°q´6Ð)A¨¨Q¬¨¸r€ r   )Úkey)r   r   r    rA   Úwalkr-   r.   ÚmaxÚsixÚ	iteritemsÚset_default_indent_diffr"   r   )ÚtreeÚpÚseen_indent_diffsr'   rr   Ú_s         r   r;   r;   �   sÏ   € å�i„i€!õ "Ô-¨i¨iÑ8Ô8ÐÝŒh�t‰nŒnð *ð *€dÝ”'˜$ ¨rÑ2Ô2€KØð *Ø˜Ð$Ð$Ô$¨Ñ)Ð$Ð$Ñ$øØð +Ý�œÐ'8Ñ9Ô9ØAÐAðCñ Cô C�N€K�à×Ò˜kÑ*Ô*Ð*à‡'‚'ˆ$�-„-€-Ø	
Œ€-r   )r   Ú
__future__r   r   r   rA   r   rz   Ú
pasta.baser   r   r-   r   Ú	Exceptionr
   ÚBaseVisitorr   r;   r   r   r   ú<module>r…      s  ðà 2Ð 2ð 'Ð &Ð &Ð &Ð &Ð &Ø Ð Ð Ð Ð Ð Ø %Ð %Ð %Ð %Ð %Ð %à 
€
€
€
Ø Ð Ð Ð Ø 
€
€
€
à Ð Ð Ð Ð Ð Ø (Ð (Ð (Ð (Ð (Ð (Ø $Ð $Ð $Ð $Ð $Ð $ð;ð ;ð ;ð ;ð ;�ñ ;ô ;ð ;ðj0ð j0ð j0ð j0ð j0ˆhÔ"ñ j0ô j0ð j0ðZð ð ð ð r   