Your IP : 13.58.105.80


Current Path : /opt/alt/python311/lib64/python3.11/lib2to3/__pycache__/
Upload File :
Current File : //opt/alt/python311/lib64/python3.11/lib2to3/__pycache__/btm_utils.cpython-311.opt-1.pyc

�

c��f�&���dZddlmZddlmZmZddlmZmZeZ	eZ
ejZeZ
dZdZdZGd�d	e��Zdd�Zd�Zd
�Zd
S)z0Utility functions used by the btm_matcher module�)�pytree)�grammar�token)�pattern_symbols�python_symbols���������c�2�eZdZdZdd�Zd�Zd�Zd�Zd�ZdS)	�MinNodez�This class serves as an intermediate representation of the
    pattern tree during the conversion to sets of leaf-to-root
    subpatternsNc�h�||_||_g|_d|_d|_g|_g|_dS)NF)�type�name�children�leaf�parent�alternatives�group)�selfrrs   �8/opt/alt/python311/lib64/python3.11/lib2to3/btm_utils.py�__init__zMinNode.__init__s8����	���	���
���	���������
�
�
�c�Z�t|j��dzt|j��zS)N� )�strrr)rs r�__repr__zMinNode.__repr__s"���4�9�~�~��#�c�$�)�n�n�4�4rc���|}g}|�r^|jtkrr|j�|��t	|j��t	|j��kr$t
|j��g}g|_|j}�{|j}d}n�|jtkrq|j	�|��t	|j	��t	|j��kr#t|j	��}g|_	|j}��|j}d}n[|jtjkr"|j
r|�|j
��n|�|j��|j}|��^|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�subps   r�leaf_to_rootzMinNode.leaf_to_root!sZ�������!	��y�-�-�-��!�(�(��.�.�.��t�(�)�)�S���-?�-?�?�?�!�$�"3�4�4�5�D�(*�D�%��;�D���;�D��D���y�J�&�&��
�!�!�$�'�'�'��t�z�?�?�c�$�-�&8�&8�8�8�8���D�D�D�!#�D�J��;�D���;�D��D���y�L�-�-�-�$�)�-����D�I�&�&�&�&����D�I�&�&�&��;�D�C�!	�D�rc�h�|���D]}|���}|r|cS�dS)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's   r�get_linear_subpatternzMinNode.get_linear_subpatternKsJ�� �����	�	�A��>�>�#�#�D��
�����
�	�	rc#�lK�|jD]}|���Ed{V���|js|V�dSdS)z-Generator that returns the leaves of the treeN)rr*)r�childs  rr*zMinNode.leaves`s[�����]�	&�	&�E��|�|�~�~�%�%�%�%�%�%�%�%��}�	��J�J�J�J�J�	�	r)NN)	�__name__�
__module__�__qualname__�__doc__rrr(r,r*�rrrrso������������5�5�5�(�(�(�T���*����rrNc��	�d}|jtjkr
|jd}|jtjkr�t|j��dkrt
|jd|��}�nstt���}|jD]L}|j�	|��dzr� t
||��}|�|j�
|���M�n|jtjkr�t|j��dkrVtt���}|jD].}t
||��}|r|j�
|���/|jsd}�n�t
|jd|��}�nh|jtj
k�rRt|jdtj��r1|jdjdkrt
|jd|��St|jdtj��r|jdjdksIt|j��dkr3t%|jdd��r|jdjdkrdSd	}d}d}d
}d}	d
}
|jD]j}|jtjkrd
}|}n1|jtjkrd	}|}	n|jtjkr|}t%|d��r
|jdkrd	}
�k|
r6|jd}t%|d��r|jdkr
|jd}n
|jd}|jt*jkr�|jd
krtt.���}�nt%t*|j��r)tt1t*|j�����}n�tt1t2|j�����}n�|jt*jkr[|j�d��}|t8vrtt8|���}nAtt*j|���}n%|jtjkrt
||��}|r7|	jdjdkrd}n|	jdjdkrnt:�|r@|�>|jdd�D].}t
||��}|�|j�
|���/|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�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_leafrs
             rrCrCgs����H��y�D�L� � ��}�Q����y�D�%�%�%��t�}����"�"�"�4�=��#3�V�<�<�H�H��$5�6�6�6�H���
6�
6���=�&�&�u�-�-�a�/���%�e�X�6�6���&��%�,�,�W�5�5�5��
6�
��d�&�	&�	&��t�}����!�!��J�/�/�/�H���
6�
6��%�e�X�6�6���6��%�,�,�W�5�5�5���$�
 ����#�4�=��#3�V�<�<�H�H�	
��d�i�	�	��t�}�Q�'���5�5�	9��M�!��"�c�)�)��t�}�Q�/��8�8�8�
��
�a�(�&�+�
6�
6�	��}�Q��%��,�,��D�M�"�"�1�$�$��t�}�Q�'��1�1�%��}�Q��%��,�,��4����� �����
�!���]�
	)�
	)�E��z�T�\�)�)���$�����t�}�,�,�#�� %�
�
���t�0�0�0�$)�!��u�g�&�&�
)�5�;�#�+=�+=�$(�!���	)��
�a�(�I��y�'�*�*�
-�y��#�/E�/E� �M�!�,�	���
�a�(�I��>�\�.�.�.���%�'�'�"��1�1�1����<���9�9�N�&�G�L�)�/�,R�,R�S�S�S�H�H�&�G�F�I�O�,L�,L�M�M�M�H�H�
�^�|�2�
2�
2��?�(�(��-�-�D��v�~�~�"��t��5�5�5���"��(9��E�E�E���
�^�t�0�
0�
0�"�#4�f�=�=�H��		*��%�a�(�.�#�5�5�����'��*�0�C�7�7��*�)��	6�H�0�%�.�q��t�4�
6�
6��%�e�X�6�6���&��%�,�,�W�5�5�5���!� ����Orc����t|t��s|St|��dkr|dSg}g}gd��g}d�|D]�}tt	|d�����r�tt	|�fd�����r|�|���Vtt	|�fd�����r|�|����|�|����|r|}n	|r|}n|r|}t
|t���S)	z�Picks the most characteristic from a list of linear patterns
    Current order used is:
    names > common_names > common_chars
    rr5)�in�for�if�not�Nonez[]().,:c�.�t|��tuS�N)rr)�xs r�<lambda>z/get_characteristic_subpattern.<locals>.<lambda>�s��d�1�g�g��n�rc�6��t|t��o|�vSrb�rGr)rc�common_charss �rrdz/get_characteristic_subpattern.<locals>.<lambda>�s���j��C�&8�&8�&N�Q�,�=N�rc�6��t|t��o|�vSrbrf)rc�common_namess �rrdz/get_characteristic_subpattern.<locals>.<lambda>s���
�1�c�(:�(:�(P�q�L�?P�r)�key)rG�listr r<�rec_testr�max)�subpatterns�subpatterns_with_names�subpatterns_with_common_names�subpatterns_with_common_chars�
subpatternrgris     @@rr#r#�so����
�k�4�(�(����
�;�������1�~�� ��$&�!�6�6�6�L�$&�!��L�!�
:�
:�
��x�
�$<�$<�=�=�>�>�		:��8�J�N�N�N�N�P�P�Q�Q�
:�-�4�4�Z�@�@�@�@��X�j�P�P�P�P�R�R�S�S�
:�-�4�4�Z�@�@�@�@�'�-�-�j�9�9�9���4�,���	&�4�3���	&�4�3���{��$�$�$�$rc#�K�|D]B}t|ttf��rt||��Ed{V���5||��V��CdS)zPTests test_func on all items of sequence and items of included
    sub-iterablesN)rGrkr!rl)�sequence�	test_funcrcs   rrlrlss���������a�$���'�'�	���9�-�-�-�-�-�-�-�-�-�-��)�A�,�,�����	�rrb)r2�r�pgen2rr�pygramrrr@rN�opmaprQr$rLrr"�objectrrCr#rlr3rr�<module>r{s���2�2�������!�!�!�!�!�!�!�!�3�3�3�3�3�3�3�3���	��	�����
����
�
�U�U�U�U�U�f�U�U�U�nB�B�B�B�J#%�#%�#%�J����r

?>