AlkantarClanX12

Your IP : 3.142.172.190


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.opt-1.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
s6|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�Sd}|j}t|�dkr�|djt
jkr�|dj}|dd�}d}t|�dkr|d
j�jjkr|d}|dd�}�j||�}|dk	r|j}	|	d}
|
jt
jkr]d}tj}nu|
jt
jkr�d}tj}nQ|
jt
jkr��j|	d�}}t|	�dkr��j|	d�}n|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	�����r5r5)rr!ZMatcher�childrenZAlternatives�lenr	�WildcardPattern�optimizeZAlternativeZNegatedUnit�
compile_basicZNegatedPatternr�EQUALrZRepeater�STARZHUGE�PLUS�LBRACE�get_int�name)
r$�nodeZalts�pZunits�patternr@�nodes�repeatr6Zchildr1r2r)r$rr(Ds^
)(


	(
+
	
!	zPatternCompiler.compile_nodeNcCs�|d}|jtjkrJttj|j��}tjt	|�|�S|jtj
krX|j}|j�r�|tkr�t
d|��|dd�r�t
d��tjt|�S|dkr�d}n@|jd�st|j|d�}|dkrt
d|��|dd�r?|j|djd�g}nd}tj||�Sna|jdkrx|j|d�S|jd	kr�|j|d�}tj|ggd
ddd�SdS)NrzInvalid token: %rrzCan't have details for token�any�_zInvalid symbol: %r�(�[r1r2)rr�STRINGr'rZ
evalStringrr	ZLeafPattern�_type_of_literal�NAME�isupper�	TOKEN_MAPr�
startswith�getattrr"r(r6ZNodePatternr8)r$rDrErArrZcontent�
subpatternrrrr:�s8
		 zPatternCompiler.compile_basiccCs
t|j�S)N)�intr)r$rArrrr?�szPatternCompiler.get_int)	rr
r�_PATTERN_GRAMMAR_FILEr%r+r(r:r?rrrrr +s
G#r rLrJ�NUMBERZTOKENcCs9|dj�rtjS|tjkr1tj|SdSdS)Nr)�isalpharrLrZopmap)rrrrrK�s
rKcCsW|\}}}}|s'||jkr=tj||d|�Stj||d|�SdS)z9Converts raw node information to a Node or Leaf instance.�contextN)Z
number2symbolr	ZNodeZLeaf)rZ
raw_node_inforrrVr6rrrr#�sr#cCst�j|�S)N)r r+)rCrrrr+�sr+)�__doc__�
__author__r�osZpgen2rrrrrr�r	r
�path�join�dirname�__file__rS�	Exceptionrr�objectr rLrJrTrNrKr#r+rrrr�<module>	s$.	
�