AlkantarClanX12

Your IP : 18.221.90.184


Current Path : /proc/self/root/usr/lib64/python3.6/lib2to3/pgen2/__pycache__/
Upload File :
Current File : //proc/self/root/usr/lib64/python3.6/lib2to3/pgen2/__pycache__/driver.cpython-36.pyc

3


 \��@s�dZdZddgZddlZddlZddlZddlZddlZddlZddl	m
Z
mZmZm
Z
mZGdd�de�Zd	d
�Zddd�Zdd�Zdd�Zdd�Zedkr�ejee���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&||_|dkrtj�}||_||_dS)N)r�logging�	getLogger�logger�convert)�selfrr
r�r�,/usr/lib64/python3.6/lib2to3/pgen2/driver.py�__init__ s
zDriver.__init__FcCs�tj|j|j�}|j�d}d}d}}}}	}
d}�xR|D�]4}|\}}}}	}
|||fkr�||f|ks|t||f|f��|\}
}||
kr�|d|
|7}|
}d}||kr�||
||�7}|}|tjtjfkr�||7}|	\}}|j	d�r@|d7}d}q@|t
jk�rtj|}|�r,|j
jdt
j|||�|j||||f��rT|�rR|j
jd�Pd}|	\}}|j	d�r@|d7}d}q@Wtjd||||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_tokenscCstj|j�}|j||�S)z*Parse a stream and return the syntax tree.)r�generate_tokens�readliner$)r�streamrrrrr�parse_stream_rawWszDriver.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||�S|j�XdS)z(Parse a file and return the syntax tree.�rN)�codecs�openr)�close)r�filename�encodingrr'rrr�
parse_file`szDriver.parse_filecCstjtj|�j�}|j||�S)z*Parse a string and return the syntax tree.)rr%�io�StringIOr&r$)r�textrrrrr�parse_stringhszDriver.parse_string)NN)F)F)F)NF)F)	�__name__�
__module__�__qualname__rr$r(r)r0r4rrrrrs

0


cCs:tjj|�\}}|dkrd}||djtttj��dS)Nz.txtr�.z.pickle)�os�path�splitext�join�map�str�sys�version_info)�gt�head�tailrrr�_generate_pickle_namensrD�Grammar.txtTFcCs�|dkrtj�}|dkr t|�n|}|s4t||�r�|jd|�tj|�}|r�|jd|�y|j|�Wq�tk
r�}z|jd|�WYdd}~Xq�Xnt	j
�}|j|�|S)z'Load the grammar (maybe from a pickle).Nz!Generating grammar tables from %szWriting grammar tables to %szWriting failed: %s)r
rrD�_newer�infor	Zgenerate_grammar�dump�OSErrorr�Grammar�load)rAZgp�save�forcer�g�errrrus
 
cCs8tjj|�sdStjj|�s dStjj|�tjj|�kS)z0Inquire whether file a was written since file b.FT)r9r:�exists�getmtime)�a�brrrrF�s
rFcCsFtjj|�rt|�Sttjj|��}tj||�}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.

    )r9r:�isfilerrD�basename�pkgutil�get_datarrJ�loads)�packageZgrammar_sourceZpickled_name�datarNrrr�load_packaged_grammar�s
r[cGsF|stjdd�}tjtjtjdd�x|D]}t|ddd�q,WdS)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)rLrM)r?�argvr
ZbasicConfig�INFO�stdoutr)�argsrArrr�main�s
rb�__main__)rENTFN)�__doc__�
__author__�__all__r+r1r9r
rVr?rrrrrr	�objectrrDrrFr[rbr5�exit�intrrrr�<module>s$P