Your IP : 3.148.117.240


Current Path : /usr/lib64/python3.8/lib2to3/pgen2/__pycache__/
Upload File :
Current File : //usr/lib64/python3.8/lib2to3/pgen2/__pycache__/driver.cpython-38.pyc

U

e5dQ�@s�dZdZddgZddlZddlZddlZddlZddlZddlm	Z	m
Z
mZmZm
Z
Gdd�de�Zd	d
�Zddd�Zdd�Zdd�Zdd�Zedkr�e�ee���dS)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@sHeZdZddd�Zddd�Zddd�Zdd	d
�Zddd�Zdd
d�ZdS)rNcCs&||_|dkrt��}||_||_dS)N)r�logging�	getLogger�logger�convert)�selfrr
r�r�,/usr/lib64/python3.8/lib2to3/pgen2/driver.py�__init__s
zDriver.__init__FcCs�t�|j|j�}|��d}d}d}}}}	}
d}|D�]8}|\}}}}	}
|||fkr�||f|ksxt||f|f��|\}
}||
kr�|d|
|7}|
}d}||kr�||
||�7}|}|tjtjfkr�||7}|	\}}|�	d�r<|d7}d}q<|t
jk�r
tj|}|�r(|j
�dt
j|||�|�||||f��rT|�rN|j
�d��q�d}|	\}}|�	d�r<|d7}d}q<t�d||||f��|jS)	z4Parse a series of tokens and return the syntax tree.rrN��
z%s %r (prefix=%r)zStop.zincomplete input)rZParserrr
Zsetup�AssertionErrorr�COMMENT�NL�endswithr�OPZopmapr�debug�tok_nameZaddtokenZ
ParseErrorZrootnode)r�tokensr�p�lineno�column�type�value�start�endZ	line_text�prefixZ	quintupleZs_linenoZs_columnrrr�parse_tokens&s`


�
�zDriver.parse_tokenscCst�|j�}|�||�S�z*Parse a stream and return the syntax tree.)r�generate_tokens�readliner$)r�streamrrrrr�parse_stream_rawVszDriver.parse_stream_rawcCs|�||�Sr%)r))rr(rrrr�parse_stream[szDriver.parse_streamc
Cs4tj|d|d��}|�||�W5QR�SQRXdS)z(Parse a file and return the syntax tree.�r)�encodingN)�io�openr*)r�filenamer,rr(rrr�
parse_file_szDriver.parse_filecCst�t�|�j�}|�||�S)z*Parse a string and return the syntax tree.)rr&r-�StringIOr'r$)r�textrrrrr�parse_stringdszDriver.parse_string)NN)F)F)F)NF)F)	�__name__�
__module__�__qualname__rr$r)r*r0r3rrrrrs

0


cCs:tj�|�\}}|dkrd}||d�tttj��dS)Nz.txtr�.z.pickle)�os�path�splitext�join�map�str�sys�version_info)�gt�head�tailrrr�_generate_pickle_namejsrC�Grammar.txtTFc
Cs�|dkrt��}|dkr t|�n|}|s2t||�s�|�d|�t�|�}|r�|�d|�z|�|�Wq�tk
r�}z|�d|�W5d}~XYq�Xnt	�
�}|�|�|S)z'Load the grammar (maybe from a pickle).Nz!Generating grammar tables from %szWriting grammar tables to %szWriting failed: %s)r
rrC�_newer�infor	Zgenerate_grammar�dump�OSErrorr�Grammar�load)r@Zgp�save�forcer�g�errrrqs
 
cCs8tj�|�sdStj�|�s dStj�|�tj�|�kS)z0Inquire whether file a was written since file b.FT)r8r9�exists�getmtime)�a�brrrrE�s
rEcCsFtj�|�rt|�Sttj�|��}t�||�}t�	�}|�
|�|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.

    )r8r9�isfilerrC�basename�pkgutil�get_datarrI�loads)�packageZgrammar_sourceZpickled_name�datarMrrr�load_packaged_grammar�s
rZcGsB|stjdd�}tjtjtjdd�|D]}t|ddd�q*dS)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)�levelr(�formatT)rKrL)r>�argvr
ZbasicConfig�INFO�stdoutr)�argsr@rrr�main�s�ra�__main__)rDNTFN)�__doc__�
__author__�__all__r-r8r
rUr>rrrrrr	�objectrrCrrErZrar4�exit�intrrrr�<module>s(M�
	


?>