ok

Mini Shell

Direktori : /proc/thread-self/root/opt/alt/python37/lib64/python3.7/lib2to3/__pycache__/
Upload File :
Current File : //proc/thread-self/root/opt/alt/python37/lib64/python3.7/lib2to3/__pycache__/patcomp.cpython-37.pyc

B

� f��@s�dZdZddlZddlmZmZmZmZmZm	Z	ddl
mZddl
mZGdd	�d	e
�Zd
d�ZGdd
�d
e�Zejejejdd�Zdd�Zdd�Zdd�ZdS)z�Pattern compiler.

The grammar is taken from PatternGrammar.txt.

The compiler compiles a pattern to a pytree.*Pattern instance.
z#Guido van Rossum <guido@python.org>�N�)�driver�literals�token�tokenize�parse�grammar)�pytree)�pygramc@seZdZdS)�PatternSyntaxErrorN)�__name__�
__module__�__qualname__�rr�4/opt/alt/python37/lib64/python3.7/lib2to3/patcomp.pyrsrc	csPtjtjtjh}t�t�|�j�}x(|D] }|\}}}}}||kr(|Vq(WdS)z6Tokenizes a string suppressing significant whitespace.N)	r�NEWLINE�INDENT�DEDENTr�generate_tokens�io�StringIO�readline)	�input�skip�tokensZ	quintuple�type�value�start�endZ	line_textrrr�tokenize_wrappers
rc@s:eZdZd
dd�Zddd�Zdd�Zdd	d
�Zdd�ZdS)�PatternCompilerNcCsZ|dkrtj|_tj|_nt�|�|_t�|j�|_tj|_	tj
|_tj|jt
d�|_dS)z^Initializer.

        Takes an optional alternative filename for the pattern grammar.
        N)Zconvert)r
Zpattern_grammarrZpattern_symbols�symsrZload_grammarZSymbolsZpython_grammarZ	pygrammarZpython_symbols�pysymsZDriver�pattern_convert)�selfZgrammar_filerrr�__init__(s
zPatternCompiler.__init__Fc
Cspt|�}y|jj||d�}Wn2tjk
rN}ztt|��d�Wdd}~XYnX|rb|�|�|fS|�|�SdS)z=Compiles a pattern string to a nested pytree.*Pattern object.)�debugN)rrZparse_tokensrZ
ParseErrorr�str�compile_node)r$rr&Z	with_treer�root�errr�compile_pattern7s zPatternCompiler.compile_patternc
s�|j�jjkr|jd}|j�jjkrz�fdd�|jddd�D�}t|�dkrX|dStjdd�|D�ddd�}|��S|j�jj	krʇfd	d�|jD�}t|�dkr�|dStj|gddd�}|��S|j�jj
kr���|jdd��}t�|�}|��S|j�jj
k�st�d}|j}t|�d
k�rR|djtjk�rR|dj}|dd�}d}t|�dk�r�|dj�jjk�r�|d}|dd�}��||�}|dk	�r�|j�jjk�s�t�|j}	|	d}
|
jtjk�r�d}tj}n�|
jtjk�r�d}tj}np|
jtjk�r^|	djtjk�st�t|	�dk�s.t���|	d�}}t|	�d
k�rh��|	d
�}n
d�sht�|dk�s||dk�r�|��}tj|gg||d�}|dk	�r�||_|��S)zXCompiles a node, recursively.

        This is one big switch on the node type.
        rcsg|]}��|��qSr)r()�.0�ch)r$rr�
<listcomp>Osz0PatternCompiler.compile_node.<locals>.<listcomp>N�rcSsg|]
}|g�qSrr)r,�arrrr.Rs)�min�maxcsg|]}��|��qSr)r()r,r-)r$rrr.Vs����)r3�r5F)rr!ZMatcher�childrenZAlternatives�lenr	�WildcardPattern�optimizeZAlternativeZNegatedUnit�
compile_basicZNegatedPatternZUnit�AssertionErrorr�EQUALrZRepeater�STARZHUGE�PLUS�LBRACE�RBRACE�get_int�name)
r$�nodeZalts�pZunits�patternrB�nodes�repeatr6Zchildr1r2r)r$rr(Csh

 
"


zPatternCompiler.compile_nodecCsnt|�dkst�|d}|jtjkrDtt�|j��}t	�
t|�|�S|jtjk�r|j}|�
�r�|tkrttd|��|dd�r�td��t	�
t|�S|dkr�d}n,|�d�s�t|j|d�}|dkr�td|��|dd�r�|�|djd�g}nd}t	�||�SnV|jdk�r |�|d�S|jd	k�r\|dk�s:t�|�|d�}t	j|ggddd
�Sd�sjt|��dS)NrrzInvalid token: %rzCan't have details for token�any�_zInvalid symbol: %r�(�[)r1r2F)r7r;rr�STRINGr'rZ
evalStringrr	ZLeafPattern�_type_of_literal�NAME�isupper�	TOKEN_MAPr�
startswith�getattrr"r(r6ZNodePatternr8)r$rFrGrCrrZcontent�
subpatternrrrr:�s<
zPatternCompiler.compile_basiccCs|jtjkst�t|j�S)N)rr�NUMBERr;�intr)r$rCrrrrA�szPatternCompiler.get_int)N)FF)N)rr
rr%r+r(r:rArrrrr &s


G
#r )rNrLrTZTOKENcCs.|d��rtjS|tjkr&tj|SdSdS)Nr)�isalpharrNrZopmap)rrrrrM�s


rMcCs>|\}}}}|s||jkr*tj|||d�Stj|||d�SdS)z9Converts raw node information to a Node or Leaf instance.)�contextN)Z
number2symbolr	ZNodeZLeaf)rZ
raw_node_inforrrWr6rrrr#�sr#cCst��|�S)N)r r+)rErrrr+�sr+)�__doc__�
__author__rZpgen2rrrrrr�r	r
�	Exceptionrr�objectr rNrLrTrPrMr#r+rrrr�<module>	s  
		

Zerion Mini Shell 1.0