Your IP : 18.220.227.250


Current Path : /opt/alt/python34/lib64/python3.4/lib2to3/pgen2/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/lib2to3/pgen2/__pycache__/driver.cpython-34.pyc

�
j f!�@s�dZdZddgZddlZddlZddlZddlZddlZddlm	Z	m
Z
mZmZm
Z
Gdd�de�Zd	dd
dddd�Zd
d�Zdd�Zedkr�ejee���ndS)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@speZdZdddd�Zddd�Zddd�Zdd	d
�Zdddd�Zdd
d�ZdS)rNcCs:||_|dkr$tj�}n||_||_dS)N)r�logging�	getLogger�logger�convert)�selfrr
r�r�9/opt/alt/python34/lib64/python3.4/lib2to3/pgen2/driver.py�__init__s
		zDriver.__init__FcCs@tj|j|j�}|j�d}d}d}}}}	}
d}x�|D]�}|\}}}}	}
|||fkr
||f|ks�t||f|f��|\}
}||
kr�|d|
|7}|
}d}n||kr
||
||�7}|}q
n|tjtjfkrc||7}|	\}}|j	d�rQ|d7}d}qQqQn|t
jkr�tj|}n|r�|j
jdt
j|||�n|j||||f�r�|r�|j
jd�nPnd}|	\}}|j	d�rQ|d7}d}qQqQWtjd||||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&sT

*	

	

	zDriver.parse_tokenscCs"tj|j�}|j||�S)z*Parse a stream and return the syntax tree.)r�generate_tokens�readliner$)r�streamrrrrr�parse_stream_rawVszDriver.parse_stream_rawcCs|j||�S)z*Parse a stream and return the syntax tree.)r()rr'rrrr�parse_stream[szDriver.parse_streamc
Cs;tj|d|�}z|j||�SWd|j�XdS)z(Parse a file and return the syntax tree.�rN)�codecs�openr)�close)r�filename�encodingrr'rrr�
parse_file_szDriver.parse_filecCs+tjtj|�j�}|j||�S)z*Parse a string and return the syntax tree.)rr%�io�StringIOr&r$)r�textrrrrr�parse_stringgszDriver.parse_string)	�__name__�
__module__�__qualname__rr$r(r)r0r4rrrrrs0zGrammar.txtTFc	Cs<|dkrtj�}n|dkr~tjj|�\}}|dkrTd}n||djtttj	��d}n|s�t
||�r|jd|�tj
|�}|r8|jd|�y|j|�Wqtk
r}z|jdt|��WYdd}~XqXq8ntj�}|j|�|S)	z'Load the grammar (maybe from a pickle).Nz.txtr�.z.picklez!Generating grammar tables from %szWriting grammar tables to %szWriting failed:)r
r�os�path�splitext�join�map�str�sys�version_info�_newer�infor	Zgenerate_grammar�dump�OSErrorrZGrammar�load)	�gtZgp�save�forcer�head�tail�g�errrrms&	*0
cCsNtjj|�sdStjj|�s,dStjj|�tjj|�kS)z0Inquire whether file a was written since file b.FT)r9r:�exists�getmtime)�a�brrrrA�s
rAcGsi|stjdd�}ntjdtjdtjdd�x$|D]}t|ddd	d�qEWdS)
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.
    rN�levelr'�formatz%(message)srGTrH)r?�argvr
ZbasicConfig�INFO�stdoutr)�argsrFrrr�main�s
rW�__main__)�__doc__�
__author__�__all__r+r1r9r
r?rrrrrr	�objectrrrArWr5�exit�intrrrr�<module>s(P	


?>