
    ;e&                         	 d dl mZ d dlmZmZ d dlmZmZ eZeZ	ej
        ZeZdZdZdZ G d de          Zdd
Zd Zd Zd	S )   )pytree)grammartoken)pattern_symbolspython_symbolsc                   0    e Zd Z	 ddZd Zd Zd Zd ZdS )MinNodeNc                 h    || _         || _        g | _        d| _        d | _        g | _        g | _        d S )NF)typenamechildrenleafparentalternativesgroup)selfr   r   s      (/usr/lib/python3.11/lib2to3/btm_utils.py__init__zMinNode.__init__   s8    			


    c                 Z    t          | j                  dz   t          | j                  z   S )N )strr   r   )r   s    r   __repr__zMinNode.__repr__   s"    49~~#c$)nn44r   c                    	 | }g }|r^|j         t          k    rr|j                            |           t	          |j                  t	          |j                  k    r$t          |j                  g}g |_        |j        }{|j        }d }n|j         t          k    rq|j	                            |           t	          |j	                  t	          |j                  k    r#t          |j	                  }g |_	        |j        }|j        }d }n[|j         t          j        k    r"|j        r|                    |j                   n|                    |j                    |j        }|^|S N)r   TYPE_ALTERNATIVESr   appendlenr   tupler   
TYPE_GROUPr   get_characteristic_subpatterntoken_labelsNAMEr   )r   nodesubps      r   leaf_to_rootzMinNode.leaf_to_root!   s_   	7  !	y---!((...t())S-?-???!$"3445D(*D%;D;DDyJ&&
!!$'''tz??c$-&8&8888DDD!#DJ;D;DDyL---$)-DI&&&&DI&&&;DC  !	D r   c                 j    	 |                                  D ]}|                                }|r|c S d S r   )leavesr)   )r   lr(   s      r   get_linear_subpatternzMinNode.get_linear_subpatternK   sO    	  	 	A>>##D 	 	r   c              #   n   K   	 | j         D ]}|                                E d {V  | j         s| V  d S d S r   )r   r+   )r   childs     r   r+   zMinNode.leaves`   s^      7] 	& 	&E||~~%%%%%%%%} 	JJJJJ	 	r   )NN)__name__
__module____qualname__r   r   r)   r-   r+    r   r   r   r      sj           5 5 5( ( (T  *    r   r   Nc                 	   	 d }| j         t          j        k    r| j        d         } | j         t          j        k    rt          | j                  dk    rt          | j        d         |          }nst          t                    }| j        D ]L}| j        	                    |          dz  r t          ||          }||j        
                    |           Mn| j         t          j        k    rt          | j                  dk    rVt          t                    }| j        D ].}t          ||          }|r|j        
                    |           /|j        sd }nt          | j        d         |          }nh| j         t          j        k    rRt          | j        d         t          j                  r1| j        d         j        dk    rt          | j        d         |          S t          | j        d         t          j                  r| j        d         j        dk    sIt          | j                  dk    r3t%          | j        d         d          r| j        d         j        dk    rd S d}d }d }d	}d }	d	}
| j        D ]j}|j         t          j        k    rd	}|}n1|j         t          j        k    rd}|}	n|j         t          j        k    r|}t%          |d          r|j        d
k    rd}
k|
r6| j        d         }t%          |d          r|j        dk    r| j        d         }n| j        d         }|j         t*          j        k    r|j        dk    rt          t.                    }nt%          t*          |j                  r)t          t1          t*          |j                            }nt          t1          t2          |j                            }n|j         t*          j        k    r[|j                            d          }|t8          v rt          t8          |                   }nAt          t*          j        |          }n%|j         t          j        k    rt          ||          }|r7|	j        d         j        dk    rd }n|	j        d         j        dk    rnt:          |r@|>|j        dd         D ].}t          ||          }||j        
                    |           /|r||_        |S )N       )r   r   ([valueTF=   any')r   r   *+r   )r   symsMatcherr   Alternativesr!   reduce_treer   r   indexr    Alternativer#   Unit
isinstancer   Leafr9   hasattrDetailsRepeaterr%   r&   TYPE_ANYgetattrpysymsSTRINGstriptokensNotImplementedErrorr   )r'   r   new_noder/   reducedr   details_nodealternatives_nodehas_repeaterrepeater_nodehas_variable_name	name_leafr   s                r   rC   rC   g   s    HyDL  }QyD%%%t}"""4=#3V<<HH $5666H 6 6=&&u--a/ %eX66&%,,W5556 
d&	&	&t}!!J///H 6 6%eX66 6%,,W555$   #4=#3V<<HH	di		t}Q'55 	9M!"c))t}Q/888a(&+66 	}Q%,,DM""1$$t}Q'11 %}Q%,,4 !] 
	) 
	)EzT\))$t},,# %t000$)!ug&& )5;#+=+=$(!  	)a(Iy'** -y#/E/E M!,	a(I >\...%''"111<99 N&GL)/,R,RSSSHH&GFIO,L,LMMMHH^|222 ?((--Dv~~"t555"(9EEE^t000"#4f==H  		*%a(.#55'*0C77 *)  	6H0%.qt4 6 6%eX66&%,,W555 ! Or   c                    	 t          | t                    s| S t          |           dk    r| d         S g }g }g dg }d| D ]}t          t	          |d                     rt          t	          |fd                    r|                    |           Vt          t	          |fd                    r|                    |           |                    |           |r|} n	|r|} n|r|} t          | t                    S )	Nr   r5   )inforifnotNonez[]().,:c                 .    t          |           t          u S r   )r   r   )xs    r   <lambda>z/get_characteristic_subpattern.<locals>.<lambda>   s    d1ggn r   c                 6    t          | t                    o| v S r   rG   r   )rb   common_charss    r   rc   z/get_characteristic_subpattern.<locals>.<lambda>   s    jC&8&8&NQ,=N r   c                 6    t          | t                    o| v S r   re   )rb   common_namess    r   rc   z/get_characteristic_subpattern.<locals>.<lambda>  s    
1c(:(:(PqL?P r   )key)rG   listr!   r<   rec_testr    max)subpatternssubpatterns_with_namessubpatterns_with_common_namessubpatterns_with_common_chars
subpatternrf   rh   s        @@r   r$   r$      st    k4(( 
;1~  $&!666L$&!L! 
: 
:
x
$<$<==>> 		:8JNNNNP P Q Q :-44Z@@@@XjPPPPR R S S :-44Z@@@@ '--j999 4,	& 43	& 43{$$$$r   c              #      K   	 | D ]B}t          |t          t          f          rt          ||          E d {V  5 ||          V  Cd S r   )rG   rj   r"   rk   )sequence	test_funcrb   s      r   rk   rk     sv        a$'' 	9----------)A,,	 r   r   ) r   pgen2r   r   pygramr   r   r@   rN   opmaprQ   r%   rL   r   r#   objectr   rC   r$   rk   r3   r   r   <module>rz      s    2       ! ! ! ! ! ! ! ! 3 3 3 3 3 3 3 3		 
U U U U Uf U U UnB B B BJ#% #% #%J    r   