AlkantarClanX12

Your IP : 18.225.92.60


Current Path : /opt/alt/python38/lib64/python3.8/lib2to3/pgen2/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib64/python3.8/lib2to3/pgen2/__pycache__/driver.cpython-38.opt-1.pyc

U

i�fQ�@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�9/opt/alt/python38/lib64/python3.8/lib2to3/pgen2/driver.py�__init__s
zDriver.__init__FcCstt�|j|j�}|��d}d}d}}}}	}
d}|D�]}|\}}}}	}
|||fkr�|\}
}||
kr�|d|
|7}|
}d}||kr�||
||�7}|}|tjtjfkr�||7}|	\}}|�d�r<|d7}d}q<|t	j
kr�tj|}|�r
|j�
dt	j|||�|�||||f��r6|�r0|j�
d��qnd}|	\}}|�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
Zsetupr�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)r/r2rrrrrs

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_namejsrB�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
rrB�_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)r7r8�exists�getmtime)�a�brrrrD�s
rDcCsFtj�|�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.

    )r7r8�isfilerrB�basename�pkgutil�get_datarrH�loads)�packageZgrammar_sourceZpickled_name�datarLrrr�load_packaged_grammar�s
rYcGsB|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)rJrK)r=�argvr
ZbasicConfig�INFO�stdoutr)�argsr?rrr�main�s�r`�__main__)rCNTFN)�__doc__�
__author__�__all__r,r7r
rTr=rrrrrr	�objectrrBrrDrYr`r3�exit�intrrrr�<module>s(M�