AlkantarClanX12

Your IP : 3.144.21.206


Current Path : /opt/alt/python34/lib64/python3.4/lib2to3/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/lib2to3/__pycache__/patcomp.cpython-34.pyo

�
i f��@sdZdZddlZddlZddlmZmZmZmZm	Z	m
Z
ddlmZddlm
Z
ejjejje�d�ZGd	d
�d
e�Zdd�ZGd
d�de�Ziejd6ejd6ejd6dd6Zdd�Zdd�Zdd�ZdS)z�Pattern compiler.

The grammer 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/python34/lib64/python3.4/lib2to3/patcomp.pyrsrc	csqtjtjtjh}tjtj|�j�}x7|D]/}|\}}}}}||kr:|Vq:q: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.
        �convertN)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
sK|j�jjkr%|jd}n|j�jjkr��fdd�|jddd�D�}t|�dkr}|dStjdd�|D�ddd	d�}|j�S|j�jj	kr"�fd
d�|jD�}t|�dkr�|dStj|gddd	d�}|j�S|j�jj
krl�j|jdd��}tj|�}|j�Sd}|j}t|�dkr�|djt
jkr�|dj}|dd�}nd}t|�dkr|d
j�jjkr|d}|dd�}n�j||�}|dk	r)|j}	|	d}
|
jt
jkrfd}tj}nx|
jt
jkr�d}tj}nT|
jt
jkr��j|	d�}}t|	�dkr��j|	d�}q�n|dks�|dkr)|j�}tj|ggd|d	|�}q)n|dk	rA||_n|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	�����r6r6)rr"ZMatcher�childrenZAlternatives�lenr	�WildcardPattern�optimizeZAlternativeZNegatedUnit�
compile_basicZNegatedPatternr�EQUALrZRepeater�STARZHUGE�PLUS�LBRACE�get_int�name)
r%�nodeZalts�pZunits�patternrA�nodes�repeatr7Zchildr2r3r)r%rr)Ds^)(


	(
+
	
'zPatternCompiler.compile_nodeNcCs�|d}|jtjkrJttj|j��}tjt	|�|�S|jtj
krd|j}|j�r�|tkr�t
d|��n|dd�r�t
d��ntjt|�S|dkr�d}nF|jd�st|j|d�}|dkrt
d|��qn|dd�rK|j|djd�g}nd}tj||�Sna|jdkr�|j|d�S|jd	kr�|j|d�}tj|ggd
ddd�SdS)NrzInvalid token: %rrzCan't have details for token�any�_zInvalid symbol: %r�(�[r2r3)rr�STRINGr(rZ
evalStringrr	ZLeafPattern�_type_of_literal�NAME�isupper�	TOKEN_MAPr�
startswith�getattrr#r)r7ZNodePatternr9)r%rErFrBrrZcontent�
subpatternrrrr;�s8
		 zPatternCompiler.compile_basiccCs
t|j�S)N)�intr)r%rBrrrr@�szPatternCompiler.get_int)	rr
r�_PATTERN_GRAMMAR_FILEr&r,r)r;r@rrrrr +s
G#r rMrK�NUMBERZTOKENcCs9|dj�rtjS|tjkr1tj|SdSdS)Nr)�isalpharrMrZopmap)rrrrrL�s
rLcCsW|\}}}}|s'||jkr=tj||d|�Stj||d|�SdS)z9Converts raw node information to a Node or Leaf instance.�contextN)Z
number2symbolr	ZNodeZLeaf)rZ
raw_node_inforrrWr7rrrr$�sr$cCst�j|�S)N)r r,)rDrrrr,�sr,)�__doc__�
__author__r�osZpgen2rrrrrr�r	r
�path�join�dirname�__file__rT�	Exceptionrr�objectr rMrKrUrOrLr$r,rrrr�<module>	s$.	
�