AlkantarClanX12

Your IP : 3.136.26.156


Current Path : /proc/self/root/opt/alt/python35/lib64/python3.5/lib2to3/__pycache__/
Upload File :
Current File : //proc/self/root/opt/alt/python35/lib64/python3.5/lib2to3/__pycache__/patcomp.cpython-35.pyc



��Yf��@sdZdZddlZddlZddlmZmZmZmZm	Z	m
Z
ddlmZddlm
Z
ejjejje�d�ZGd	d
�d
e�Zdd�ZGd
d�de�ZdejdejdejddiZdd�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)�pygramzPatternGrammar.txtc@seZdZdS)�PatternSyntaxErrorN)�__name__�
__module__�__qualname__�rr�4/opt/alt/python35/lib64/python3.5/lib2to3/patcomp.pyrsrc	csntjtjtjh}tjtj|�j�}x4|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_wrapper!s
rc@sXeZdZedd�Zdddd�Zdd�Zdd	d
�Zdd�ZdS)
�PatternCompilercCs^tj|�|_tj|j�|_tj|_tj|_	tj
|jdt�|_dS)z^Initializer.

        Takes an optional alternative filename for the pattern grammar.
        ZconvertN)rZload_grammarrr
ZSymbols�symsZpython_grammarZ	pygrammarZpython_symbols�pysymsZDriver�pattern_convert)�selfZgrammar_filerrr�__init__-s
zPatternCompiler.__init__FcCs�t|�}y|jj|d|�}Wn:tjk
rd}ztt|���WYdd}~XnX|r~|j|�|fS|j|�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_pattern8s%zPatternCompiler.compile_patternc
s�|j�jjkr"|jd}|j�jjkr��fdd�|jddd�D�}t|�dkrz|dStjdd�|D�ddd	d�}|j�S|j�jj	kr�fd
d�|jD�}t|�dkr�|dStj|gddd	d�}|j�S|j�jj
kri�j|jdd��}tj|�}|j�S|j�jj
ks�t�d}|j}t|�dkr�|djtjkr�|dj}|dd�}d}t|�dkr#|dj�jjkr#|d}|dd�}�j||�}|dk	r�|j�jjks\t�|j}	|	d}
|
jtjkr�d}tj}n�|
jtjkr�d}tj}n�|
jtjkr<|	djtjks�t�t|	�dks�t��j|	d�}}t|	�dkrH�j|	d�}nd
sHt�|dks`|dkr�|j�}tj|ggd|d	|�}|dk	r�||_|j�S)zXCompiles a node, recursively.

        This is one big switch on the node type.
        rcsg|]}�j|��qSr)r()�.0�ch)r$rr�
<listcomp>Ps	z0PatternCompiler.compile_node.<locals>.<listcomp>N�rcSsg|]}|g�qSrr)r,�arrrr.Ss	�min�maxcsg|]}�j|��qSr)r()r,r-)r$rrr.Ws	��F���r5r5r5)r3r4)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(Dsh
)(


	(
+
	
!	zPatternCompiler.compile_nodeNcCs�t|�dkst�|d}|jtjkrbttj|j��}t	j
t|�|�S|jtjkrp|j}|j
�r�|tkr�td|��|dd�r�td��t	j
t|�S|dkr�d}n@|jd�s't|j|d�}|dkr'td|��|dd�rW|j|djd�g}nd}t	j||�Sns|jdkr�|j|d�S|jd	kr�|dks�t�|j|d�}t	j|ggd
ddd�Sds�t|��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)	rr
r�_PATTERN_GRAMMAR_FILEr%r+r(r:rArrrrr +s
G#r rNrLrTZTOKENcCs9|dj�rtjS|tjkr1tj|SdSdS)Nr)�isalpharrNrZopmap)rrrrrM�s
rMcCsW|\}}}}|s'||jkr=tj||d|�Stj||d|�SdS)z9Converts raw node information to a Node or Leaf instance.�contextN)Z
number2symbolr	ZNodeZLeaf)rZ
raw_node_inforrrXr6rrrr#�sr#cCst�j|�S)N)r r+)rErrrr+�sr+)�__doc__�
__author__r�osZpgen2rrrrrr�r	r
�path�join�dirname�__file__rV�	Exceptionrr�objectr rNrLrTrPrMr#r+rrrr�<module>	s$.	
�