Hacked By AnonymousFox

Current Path : /opt/alt/python37/lib64/python3.7/lib2to3/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/lib2to3/__pycache__/btm_utils.cpython-37.pyc

B

� f�&�@s|dZddlmZddlmZmZddlmZmZeZ	eZ
ejZeZ
dZdZdZGdd	�d	e�Zddd�Zd
d�Zdd�Zd
S)z0Utility functions used by the btm_matcher module�)�pytree)�grammar�token)�pattern_symbols�python_symbols���������c@s:eZdZdZd
dd�Zdd�Zdd�Zd	d
�Zdd�ZdS)�MinNodez�This class serves as an intermediate representation of the
    pattern tree during the conversion to sets of leaf-to-root
    subpatternsNcCs.||_||_g|_d|_d|_g|_g|_dS)NF)�type�name�children�leaf�parent�alternatives�group)�selfrr�r�6/opt/alt/python37/lib64/python3.7/lib2to3/btm_utils.py�__init__szMinNode.__init__cCst|j�dt|j�S)N� )�strrr)rrrr�__repr__szMinNode.__repr__cCs�|}g}x�|r�|jtkr`|j�|�t|j�t|j�krTt|j�g}g|_|j}q
n|j}d}P|jtkr�|j	�|�t|j	�t|j�kr�t
|j	�}g|_	|j}q
n|j}d}P|jtjkr�|j
r�|�|j
�n|�|j�|j}q
W|S)z�Internal method. Returns a characteristic path of the
        pattern tree. This method must be run for all leaves until the
        linear subpatterns are merged into a singleN)r�TYPE_ALTERNATIVESr�append�lenr
�tupler�
TYPE_GROUPr�get_characteristic_subpattern�token_labels�NAMEr)r�node�subprrr�leaf_to_root!s8



zMinNode.leaf_to_rootcCs&x |��D]}|��}|r
|Sq
WdS)a�Drives the leaf_to_root method. The reason that
        leaf_to_root must be run multiple times is because we need to
        reject 'group' matches; for example the alternative form
        (a | b c) creates a group [b c] that needs to be matched. Since
        matching multiple linear patterns overcomes the automaton's
        capabilities, leaf_to_root merges each group into a single
        choice based on 'characteristic'ity,

        i.e. (a|b c) -> (a|b) if b more characteristic than c

        Returns: The most 'characteristic'(as defined by
          get_characteristic_subpattern) path for the compiled pattern
          tree.
        N)�leavesr#)r�lr"rrr�get_linear_subpatternKszMinNode.get_linear_subpatternccs.x|jD]}|��EdHqW|js*|VdS)z-Generator that returns the leaves of the treeN)r
r$)r�childrrrr$`szMinNode.leaves)NN)	�__name__�
__module__�__qualname__�__doc__rrr#r&r$rrrrr
s
	*r
Nc
Cs�d}|jtjkr|jd}|jtjkr�t|j�dkrFt|jd|�}nJttd�}x>|jD]4}|j�	|�drnqXt||�}|dk	rX|j�
|�qXW�n|jtjk�rt|j�dkr�ttd�}x(|jD]}t||�}|r�|j�
|�q�W|js�d}nt|jd|�}�n�|jtj
k�r�t|jdtj��rH|jdjdk�rHt|jd|�St|jdtj��rn|jdjdk�s�t|j�dk�r�t|jdd��r�|jdjdk�r�dSd	}d}d}d
}d}	d
}
xn|jD]d}|jtjk�r�d
}|}n*|jtjk�r�d	}|}	n|jtjk�r|}t|d��r�|jdk�r�d	}
�q�W|
�rb|jd}t|d��rl|jdk�rl|jd}n
|jd}|jtjk�r�|jd
k�r�ttd�}n4tt|j��r�ttt|j�d�}nttt|j�d�}n\|jtjk�r|j�d�}|tk�r�tt|d�}nttj|d�}n|jtjk�r$t||�}|�rZ|	jdjdk�rBd}n|	jdjdk�rVnt�|�r�|dk	�r�x8|jdd�D]&}t||�}|dk	�rz|j�
|��qzW|�r�||_|S)z�
    Internal function. Reduces a compiled pattern tree to an
    intermediate representation suitable for feeding the
    automaton. This also trims off any optional pattern elements(like
    [a], a*).
    N��)rr�(�[�valueTF�=��any�')rr�*�+r)r�symsZMatcherr
ZAlternativesr�reduce_treer
r�indexrZAlternativerZUnit�
isinstancerZLeafr0�hasattrZDetailsZRepeaterrr �TYPE_ANY�getattr�pysyms�STRING�strip�tokens�NotImplementedErrorr)
r!rZnew_noder'ZreducedrZdetails_nodeZalternatives_nodeZhas_repeaterZ
repeater_nodeZhas_variable_nameZ	name_leafrrrrr8gs�











r8cs�t|t�s|St|�dkr"|dSg}g}dddddg�g}d�xl|D]d}tt|d	d
���rFtt|�fdd
���r~|�|�qFtt|�fdd
���r�|�|�qF|�|�qFW|r�|}n|r�|}n|r�|}t|td
�S)z�Picks the most characteristic from a list of linear patterns
    Current order used is:
    names > common_names > common_chars
    rr,�in�for�if�not�Nonez[]().,:cSst|�tkS)N)rr)�xrrr�<lambda>��z/get_characteristic_subpattern.<locals>.<lambda>cst|t�o|�kS)N)r:r)rH)�common_charsrrrIrJcst|t�o|�kS)N)r:r)rH)�common_namesrrrIrJ)�key)r:�listrr3�rec_testr�max)ZsubpatternsZsubpatterns_with_namesZsubpatterns_with_common_namesZsubpatterns_with_common_chars�
subpatternr)rKrLrr�s2

rccs<x6|D].}t|ttf�r*t||�EdHq||�VqWdS)zPTests test_func on all items of sequence and items of included
    sub-iterablesN)r:rNrrO)ZsequenceZ	test_funcrHrrrrOs
rO)N)r+�rZpgen2rrZpygramrrr7r>ZopmaprArr<rr�objectr
r8rrOrrrr�<module>sW
%

Hacked By AnonymousFox1.0, Coded By AnonymousFox