Your IP : 3.135.215.149


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.opt-1.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�Sd}|j}	t
|	�dk\r4|	djtjk(r|	dj }|	dd}	d}
t
|	�dk\r0|	dj|jj"k(r
|	d}
|	dd}	|j|	|
�}|
��|
j}|d}|jtj$k(rd}
tj&}n�|jtj(k(rd}
tj&}nV|jtj*k(r9|j-|d�x}
}t
|�dk(r|j-|d�}	
dk7sdk7r*|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�����)r r,�Matcher�children�Alternativesr=�lenr
�WildcardPattern�optimize�Alternative�NegatedUnit�
compile_basic�NegatedPatternr�EQUALr!�Repeater�STAR�HUGE�PLUS�LBRACE�get_int�name)r5�node�ch�alts�a�p�units�patternr[�nodes�repeatrK�childrErFs               rr=zPatternCompiler.compile_nodeCs���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��:�:�<�����
�
���u�:��?�u�Q�x�}�}����;���8�>�>�D��!�"�I�E����u�:��?�u�R�y�~�~����1C�1C�C��2�Y�F��#�2�J�E��$�$�U�F�3�������H��Q�K�E��z�z�U�Z�Z�'����k�k�����u�z�z�)����k�k�����u�|�|�+�!�L�L��!��5�5��c��x�=�A�%��,�,�x��{�3�C��a�x�3�!�8�!�*�*�,�� �0�0�7�)��#�3�O�����G�L����!�!��sH��(;��Ds�*M3�*
M8�?M=c��|d}|jtjk(rGtt	j
|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|jdk(r|j#|d�S|jd	k(r.|j#|d�}tj(|ggdd�
�Sy)NrzInvalid token: %rrzCan't have details for token�any�_zInvalid symbol: %r�(�[rD)r r�STRINGr<r�
evalStringr!r
�LeafPattern�_type_of_literal�NAME�isupper�	TOKEN_MAPr
�
startswith�getattrr2r=rK�NodePatternrN)r5rcrdr\r!r �content�
subpatterns        rrRzPatternCompiler.compile_basic�s����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�rc�,�t|j�S�N)�intr!)r5r\s  rrZzPatternCompiler.get_int�s���4�:�:��rrx)FF)rrrr7rAr=rRrZrrrr'r'&s��
K�
+�E"�N!�Frr')rork�NUMBER�TOKENc��|dj�rtjS|tjvrtj|Sy)Nr)�isalpharror	�opmap)r!s rrnrn�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|�Srx)r'rA)rbs rrArA�s����,�,�W�5�5r)�__doc__�
__author__r�pgen2rrrrrr	�r
r�	Exceptionr
r%�objectr'rorkrzrqrnr4rArrr�<module>r�sw���3�
�
�E�D���	��	��I�f�I�Z�Z�Z��|�|��|�|��
�	��9�6r

?>