AlkantarClanX12

Your IP : 18.219.18.238


Current Path : /opt/alt/python312/lib64/python3.12/lib2to3/__pycache__/
Upload File :
Current File : //opt/alt/python312/lib64/python3.12/lib2to3/__pycache__/btm_utils.cpython-312.pyc

�

�Q�f�&���dZddlmZddlmZmZddlmZmZeZ	eZ
ejZeZ
dZdZdZGd�d	e�Zdd�Zd�Zd
�Zy
)z0Utility functions used by the btm_matcher module�)�pytree)�grammar�token)�pattern_symbols�python_symbols���������c�0�eZdZdZdd�Zd�Zd�Zd�Zd�Zy)	�MinNodez�This class serves as an intermediate representation of the
    pattern tree during the conversion to sets of leaf-to-root
    subpatternsNc�f�||_||_g|_d|_d|_g|_g|_y)NF)�type�name�children�leaf�parent�alternatives�group)�selfrrs   �8/opt/alt/python312/lib64/python3.12/lib2to3/btm_utils.py�__init__zMinNode.__init__s4����	���	���
���	���������
�c�^�t|j�dzt|j�zS)N� )�strrr)rs r�__repr__zMinNode.__repr__s"���4�9�9�~��#�c�$�)�)�n�4�4rc�D�|}g}|�r�|jtk(r�|jj|�t	|j�t	|j
�k(r*t
|j�g}g|_|j}��|j}d}	|S|jtk(r�|jj|�t	|j�t	|j
�k(r*t|j�}g|_	|j}��|j}d}	|S|jtjk(r(|jr|j|j�n|j|j�|j}|r���|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!sP��������y�y�-�-��!�!�(�(��.��t�(�(�)�S����-?�?�!�$�"3�"3�4�5�D�(*�D�%��;�;�D���;�;�D��D��,��)�y�y�J�&��
�
�!�!�$�'��t�z�z�?�c�$�-�-�&8�8�8����D�D�!#�D�J��;�;�D���;�;�D��D�����y�y�L�-�-�-�$�)�)����D�I�I�&����D�I�I�&��;�;�D�C�D�rc�Z�|j�D]}|j�}|s�|cSy)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_subpatternKs(�� ����A��>�>�#�D����rc#�K�|jD]}|j�Ed{����|js|��yy7��w)z-Generator that returns the leaves of the treeN)rr*)r�childs  rr*zMinNode.leaves`s9�����]�]�E��|�|�~�%�%�#��}�}��J��
&�s�#A�>�A)NN)	�__name__�
__module__�__qualname__�__doc__rrr(r,r*�rrrrs!����5�(�T�*rrNc�
�d}|jtjk(r|jd}|jtjk(r�t|j�dkrt
|jd|�}�n�tt��}|jD]K}|jj|�dzr�"t
||�}|��1|jj|��M�na|jtjk(r�t|j�dkDr\tt��}|jD],}t
||�}|s�|jj|��.|j�s�d}�n�t
|jd|�}�n�|jtjk(�r�t|jdtj �r5|jdj"dk(rt
|jd|�St|jdtj �r|jdj"dk(sMt|j�dkDr6t%|jdd�r|jdj"dk(ryd	}d}d}d
}d}	d
}
|jD]�}|jtj&k(rd
}|}nA|jtj(k(rd	}|}	n|jtjk(r|}t%|d�s�s|j"dk(s��d	}
��|
r:|jd}t%|d�r.|j"dk(r|jd}n|jd}|jt*j,k(r�|j"d
k(rtt.��}n�t%t*|j"�r%tt1t*|j"���}n�tt1t2|j"���}n�|jt*j4k(rS|j"j7d�}|t8vrtt8|��}nEtt*j,|��}n)|jtjk(rt
||�}|rB|	jdj"dk(rd}n#|	jdj"dk(rnt:�|r@|�>|jddD],}t
||�}|��|jj|��.|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
             rrCrCgsI���H��y�y�D�L�L� ��}�}�Q����y�y�D�%�%�%��t�}�}���"�"�4�=�=��#3�V�<�H��$5�6�H������=�=�&�&�u�-�a�/��%�e�X�6���&��%�%�,�,�W�5�'�
���d�&�&�	&��t�}�}���!��J�/�H�����%�e�X�6����%�%�,�,�W�5�'��$�$���#�4�=�=��#3�V�<�H�	
���d�i�i�	��t�}�}�Q�'����5��M�M�!��"�"�c�)��t�}�}�Q�/��8�8�
��
�
�a�(�&�+�+�
6��}�}�Q��%�%��,��D�M�M�"�1�$��t�}�}�Q�'��1��}�}�Q��%�%��,������ �����
�!���]�]�E��z�z�T�\�\�)���$�����t�}�}�,�#�� %�
����t�0�0�0�$)�!��u�g�&�5�;�;�#�+=�$(�!�#���
�
�a�(�I��y�'�*�y���#�/E� �M�M�!�,�	��
�
�a�(�I��>�>�\�.�.�.����%�'�"��1���<����9�&�G�L�)�/�/�,R�S�H�&�G�F�I�O�O�,L�M�H�
�^�^�|�2�2�
2��?�?�(�(��-�D��v�~�"��t��5��"��(9�(9��E��
�^�^�t�0�0�
0�"�#4�f�=�H���%�%�a�(�.�.�#�5����'�'��*�0�0�C�7��*�)��H�0�%�.�.�q��4��%�e�X�6���&��%�%�,�,�W�5�	5�
� ����Orc����t|t�s|St|�dk(r|dSg}g}gd��g}d�|D]~}tt	|d���s�tt	|�fd���r|j|��Dtt	|�fd���r|j|��n|j|���|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��nrc�0��t|t�xr|�vSrb�rGr)rc�common_charss �rrdz/get_characteristic_subpattern.<locals>.<lambda>�s���j��C�&8�&N�Q�,�=N�&Nrc�0��t|t�xr|�vSrbrf)rc�common_namess �rrdz/get_characteristic_subpattern.<locals>.<lambda>s���
�1�c�(:�(P�q�L�?P�(Pr)�key)rG�listr r<�rec_testr�max)�subpatterns�subpatterns_with_names�subpatterns_with_common_names�subpatterns_with_common_chars�
subpatternrgris     @@rr#r#�s����
�k�4�(���
�;�����1�~�� ��$&�!�6�L�$&�!��L�!�
��x�
�$<�=�>��8�J�N�P�Q�-�4�4�Z�@��X�j�P�R�S�-�4�4�Z�@�'�-�-�j�9�"��,��	&�3��	&�3���{��$�$rc#�K�|D]7}t|ttf�rt||�Ed{����.||����9y7��w)zPTests test_func on all items of sequence and items of included
    sub-iterablesN)rGrkr!rl)�sequence�	test_funcrcs   rrlrls=�������a�$���'���9�-�-�-��A�,��	�-�s�+A�A�Arb)r2�r�pgen2rr�pygramrrr@rN�opmaprQr$rLrr"�objectrrCr#rlr3rr�<module>r{sZ��2��!�3���	��	������
����
�
�U�f�U�nB�J#%�Jr