Your IP : 18.188.245.152


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

�

�Q�fQ����dZdZddgZddlZddlZddlZddlZddlZddlm	Z	m
Z
mZmZm
Z
Gd�de�Zd	�Z		dd
�Zd�Zd�Zd
�Zedk(rej,ee���yy)zZParser driver.

This provides a high-level interface to parse a file into a syntax tree.

z#Guido van Rossum <guido@python.org>�Driver�load_grammar�N�)�grammar�parse�token�tokenize�pgenc�<�eZdZdd�Zd	d�Zd	d�Zd	d�Zd
d�Zd	d�Zy)rNc�Z�||_|�tj�}||_||_y)N)r�logging�	getLogger�logger�convert)�selfrrrs    �;/opt/alt/python312/lib64/python3.12/lib2to3/pgen2/driver.py�__init__zDriver.__init__s*������>��&�&�(�F�������c�f�tj|j|j�}|j	�d}d}dx}x}x}x}	}
d}|D�]H}|\}}}}	}
|||fk7r:||f|ksJ||f|f��|\}
}||
kr|d|
|z
zz
}|
}d}||kr
||
||z
}|}|t
jt
jfvr#||z
}|	\}}|jd�r|dz
}d}��|tjk(rtj|}|r/|jjdtj|||�|j||||f�r*|r|jjd�|j"Sd}|	\}}|jd�s��B|dz
}d}��Ktj d||||f��)	z4Parse a series of tokens and return the syntax tree.rrN��
z%s %r (prefix=%r)zStop.zincomplete input)r�Parserrr�setupr	�COMMENT�NL�endswithr�OP�opmapr�debug�tok_name�addtoken�
ParseError�rootnode)r�tokensr�p�lineno�column�type�value�start�end�	line_text�prefix�	quintuple�s_lineno�s_columns               r�parse_tokenszDriver.parse_tokens&s���
�L�L����t�|�|�4��	���	�����15�5��5�u�5�u�5�s�Y����I�1:�.�D�%���Y����(�(���'�5�0�K�F�F�3C�U�2K�K�0�%*�"��(��H�$��d�h��&7�8�8�F�%�F��F��H�$��i��x�8�8�F�%�F���(�(�(�+�+�6�6��%���!$�����>�>�$�'��a�K�F��F���u�x�x���}�}�U�+������!�!�"5�"'�.�.��"6��v�G��z�z�$�����7���K�K�%�%�g�.���z�z���F� �N�F�F��~�~�d�#��!�����A �F�"�"�#5�#'�����A�
Arc�d�tj|j�}|j||�S�z*Parse a stream and return the syntax tree.)r	�generate_tokens�readliner1)r�streamrr$s    r�parse_stream_rawzDriver.parse_stream_rawVs)���)�)�&�/�/�:��� � ���/�/rc�&�|j||�Sr3)r7)rr6rs   r�parse_streamzDriver.parse_stream[s���$�$�V�U�3�3rc��tj|d|��5}|j||�cddd�S#1swYyxYw)z(Parse a file and return the syntax tree.�r)�encodingN)�io�openr9)r�filenamer<rr6s     r�
parse_filezDriver.parse_file_s5��
�W�W�X�s�X�
6�&��$�$�V�U�3�	4�	4�
6�
6�s�5�>c��tjtj|�j�}|j||�S)z*Parse a string and return the syntax tree.)r	r4r=�StringIOr5r1)r�textrr$s    r�parse_stringzDriver.parse_stringds4���)�)�"�+�+�d�*;�*D�*D�E��� � ���/�/r)NN)F)NF)	�__name__�
__module__�__qualname__rr1r7r9r@rD�rrrrs!���.�`0�
4�4�
0rc��tjj|�\}}|dk(rd}||zdjt	t
tj��zdzS)Nz.txtr�.z.pickle)�os�path�splitext�join�map�str�sys�version_info)�gt�head�tails   r�_generate_pickle_namerVjsP�����!�!�"�%�J�D�$��v�~����$�;����#�c�3�+;�+;�"<�=�=�	�I�Irc��|�tj�}|�t|�n|}|st||�sQ|j	d|�tj|�}|r&|j	d|�	|j|�|S|Stj�}|j|�|S#t$r}|j	d|�Yd}~|Sd}~wwxYw)z'Load the grammar (maybe from a pickle).Nz!Generating grammar tables from %szWriting grammar tables to %szWriting failed: %s)r
rrV�_newer�infor
�generate_grammar�dump�OSErrorr�Grammar�load)rS�gp�save�forcer�g�es       rrrqs����~��"�"�$��&(�j�	�r�	"�b�B��F�2�r�N����7��<��!�!�"�%����K�K�6��;�
5����r�
�
�H�1�H�
�O�O���	���r�
��H���
5����0�!�4�4�
�H��
5�s�0B,�,	C�5C
�
Cc��tjj|�sytjj|�sytjj|�tjj|�k\S)z0Inquire whether file a was written since file b.FT)rKrL�exists�getmtime)�a�bs  rrXrX�sQ��
�7�7�>�>�!���
�7�7�>�>�!���
�7�7���A��"�'�'�"2�"2�1�"5�5�5rc� �tjj|�rt|�St	tjj|��}t
j||�}tj�}|j|�|S)a�Normally, loads a pickled grammar by doing
        pkgutil.get_data(package, pickled_grammar)
    where *pickled_grammar* is computed from *grammar_source* by adding the
    Python version and using a ``.pickle`` extension.

    However, if *grammar_source* is an extant file, load_grammar(grammar_source)
    is called instead. This facilitates using a packaged grammar file when needed
    but preserves load_grammar's automatic regeneration behavior when possible.

    )rKrL�isfilerrV�basename�pkgutil�get_datarr]�loads)�package�grammar_source�pickled_name�datarbs     r�load_packaged_grammarrs�sf��
�w�w�~�~�n�%��N�+�+�(����)9�)9�.�)I�J�L����G�\�2�D�����A��G�G�D�M��Hrc��|stjdd}tjtjtj
d��|D]}t
|dd���y)z�Main program, when run as a script: produce grammar pickle files.

    Calls load_grammar for each argument, a path to a grammar text file.
    rNz%(message)s)�levelr6�formatT)r`ra)rQ�argvr
�basicConfig�INFO�stdoutr)�argsrSs  r�mainr|�sL��
��x�x���|�����g�l�l�3�:�:�,�.����R�d�$�/��r�__main__)zGrammar.txtNTFN)�__doc__�
__author__�__all__r=rKr
rlrQrrrrr	r
�objectrrVrrXrsr|rE�exit�intrHrr�<module>r�s����3�
��^�
$��
�	���
�4�3�J0�V�J0�ZJ�'+�04�
�*6�
�(��z���C�H�H�S�T�V��_��r

?>