AlkantarClanX12

Your IP : 18.225.195.4


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

�

�Q�f�����dZdZddlZddlmZmZmZmZmZm	Z	ddl
mZddl
mZGd�d	e
�Zd
�ZGd�de�Zej$ej&ej(dd
�Zd�Zd�Zd�Zy)z�Pattern compiler.

The grammar is taken from PatternGrammar.txt.

The compiler compiles a pattern to a pytree.*Pattern instance.
z#Guido van Rossum <guido@python.org>�N�)�driver�literals�token�tokenize�parse�grammar)�pytree)�pygramc��eZdZy)�PatternSyntaxErrorN)�__name__�
__module__�__qualname__���6/opt/alt/python312/lib64/python3.12/lib2to3/patcomp.pyr
r
s��rr
c#�K�tjtjtjh}t	j
t
j|�j�}|D]}|\}}}}}||vs�|���y�w)z6Tokenizes a string suppressing significant whitespace.N)	r�NEWLINE�INDENT�DEDENTr�generate_tokens�io�StringIO�readline)	�input�skip�tokens�	quintuple�type�value�start�end�	line_texts	         r�tokenize_wrapperr%sd�����M�M�5�<�<����6�D�
�
%�
%�b�k�k�%�&8�&A�&A�
B�F��	�-6�*��e�U�C���t���O��s�A3A=�6A=c�0�eZdZdd�Zdd�Zd�Zdd�Zd�Zy)	�PatternCompilerNc��|�+tj|_tj|_n>tj|�|_tj|j�|_tj|_	tj|_tj|jt��|_y)z^Initializer.

        Takes an optional alternative filename for the pattern grammar.
        N)�convert)r�pattern_grammarr	�pattern_symbols�symsr�load_grammar�Symbols�python_grammar�	pygrammar�python_symbols�pysyms�Driver�pattern_convert)�self�grammar_files  r�__init__zPatternCompiler.__init__(sz��
��!�1�1�D�L��.�.�D�I�!�.�.�|�<�D�L����t�|�|�4�D�I��.�.����+�+����m�m�D�L�L�/�J��rc��t|�}	|jj||��}|r|j|�|fS|j|�S#tj$r}tt
|��d�d}~wwxYw)z=Compiles a pattern string to a nested pytree.*Pattern object.)�debugN)r%r�parse_tokensr�
ParseErrorr
�str�compile_node)r5rr9�	with_treer�root�es       r�compile_patternzPatternCompiler.compile_pattern7s��!�%�(��	7��;�;�+�+�F�%�+�@�D���$�$�T�*�D�0�0��$�$�T�*�*�����	7�$�S��V�,�$�6��	7�s�A�A=�#A8�8A=c��|j|jjk(r|jd}|j|jjk(rx|jddd�D�cgc]}|j|���}}t
|�dk(r|dStj|D�cgc]}|g��c}dd��}|j�S|j|jjk(rd|jD�cgc]}|j|���}}t
|�dk(r|dStj|gdd��}|j�S|j|jjk(rC|j|jdd�}tj|�}|j�S|j|jjk(sJ�d}|j}	t
|	�dk\r4|	djtj k(r|	dj"}|	dd}	d}
t
|	�dk\r0|	dj|jj$k(r
|	d}
|	dd}	|j|	|
�}|
��S|
j|jj$k(sJ�|
j}|d}|jtj&k(rd}
tj(}n�|jtj*k(rd}
tj(}n�|jtj,k(rj|djtj.k(sJ�t
|�dvsJ�|j1|d�x}
}t
|�d	k(r|j1|d�}nJ�|
dk7s|dk7r*|j�}tj|gg|
|��}|�||_|j�Scc}wcc}wcc}w)
zXCompiles a node, recursively.

        This is one big switch on the node type.
        rN�r��min�max����)rG�rI)r r,�Matcher�children�Alternativesr=�lenr
�WildcardPattern�optimize�Alternative�NegatedUnit�
compile_basic�NegatedPattern�Unitr�EQUALr!�Repeater�STAR�HUGE�PLUS�LBRACE�RBRACE�get_int�name)r5�node�ch�alts�a�p�units�patternr]�nodes�repeatrK�childrErFs               rr=zPatternCompiler.compile_nodeCse���9�9��	�	�)�)�)��=�=��#�D��9�9��	�	�.�.�.�48�M�M�#�A�#�4F�G�4F�b�D�%�%�b�)�4F�D�G��4�y�A�~��A�w���&�&�T�':�T����T�':��q�I�A��:�:�<���9�9��	�	�-�-�-�59�]�]�C�]�r�T�&�&�r�*�]�E�C��5�z�Q���Q�x���&�&��w�A�1�=�A��:�:�<���9�9��	�	�-�-�-��(�(����q�r�):�;�G��%�%�g�.�A��:�:�<���y�y�D�I�I�N�N�*�*�*����
�
���u�:��?�u�Q�x�}�}����;���8�>�>�D��!�"�I�E����u�:��?�u�R�y�~�~����1C�1C�C��2�Y�F��#�2�J�E��$�$�U�F�3�����;�;�$�)�)�"4�"4�4�4�4����H��Q�K�E��z�z�U�Z�Z�'����k�k�����u�z�z�)����k�k�����u�|�|�+���|�(�(�E�L�L�8�8�8��H�
��/�/�/� �L�L��!��5�5��c��x�=�A�%��,�,�x��{�3�C��u��a�x�3�!�8�!�*�*�,�� �0�0�7�)��#�3�O�����G�L����!�!��sH��(;��Ds�*O1�*
O6�?O;c��t|�dk\sJ�|d}|jtjk(rGt	tj|j��}tjt|�|�S|jtjk(r�|j}|j�rB|tvrtd|z��|ddrtd��tjt|�S|dk(rd}n8|jd�s't!|j"|d�}|�td|z��|ddr#|j%|dj&d�g}nd}tj(|�S|jdk(r|j%|d�S|jd	k(r2|�J�|j%|d�}tj*|ggdd�
�SJ|��)NrrzInvalid token: %rzCan't have details for token�any�_zInvalid symbol: %r�(�[rD)rMr r�STRINGr<r�
evalStringr!r
�LeafPattern�_type_of_literal�NAME�isupper�	TOKEN_MAPr
�
startswith�getattrr2r=rK�NodePatternrN)r5rerfr^r!r �content�
subpatterns        rrRzPatternCompiler.compile_basic�s����5�z�Q�����Q�x���9�9����$���+�+�D�J�J�7�8�E��%�%�&6�u�&=�u�E�E�
�Y�Y�%�*�*�
$��J�J�E��}�}���	�)�,�-@�5�-H�I�I����9�,�-K�L�L��)�)�)�E�*:�;�;��E�>��D��)�)�#�.�"�4�;�;��t�<�D��|�0�1E��1M�N�N����9�#�0�0��q��1B�1B�1�1E�F�G�G�"�G��)�)�$��8�8�
�Z�Z�3�
��$�$�U�1�X�.�.�
�Z�Z�3�
��>�!�>��*�*�5��8�4�J��)�)�J�<�.�a�Q�G�G��d��urc�j�|jtjk(sJ�t|j�S�N)r r�NUMBER�intr!)r5r^s  rr\zPatternCompiler.get_int�s&���y�y�E�L�L�(�(�(��4�:�:��rrz)FF)rrrr7rAr=rRr\rrrr'r'&s��
K�
+�E"�N!�Frr')rqrmr{�TOKENc��|dj�rtjS|tjvrtj|Sy)Nr)�isalpharrqr	�opmap)r!s rrprp�s:���Q�x�����z�z��	�'�-�-�	��}�}�U�#�#�rc��|\}}}}|s||jvrtj|||��Stj|||��S)z9Converts raw node information to a Node or Leaf instance.)�context)�
number2symbolr
�Node�Leaf)r	�
raw_node_infor r!r�rKs      rr4r4�sF��%2�"�D�%��(��4�7�0�0�0��{�{�4��7�;�;��{�{�4���8�8rc�4�t�j|�Srz)r'rA)rds rrArA�s����,�,�W�5�5r)�__doc__�
__author__r�pgen2rrrrrr	�r
r�	Exceptionr
r%�objectr'rqrmr{rsrpr4rArrr�<module>r�sw���3�
�
�E�D���	��	��I�f�I�Z�Z�Z��|�|��|�|��
�	��9�6r