ok

Mini Shell

Direktori : /proc/thread-self/root/opt/alt/python34/lib64/python3.4/lib2to3/__pycache__/
Upload File :
Current File : //proc/thread-self/root/opt/alt/python34/lib64/python3.4/lib2to3/__pycache__/patcomp.cpython-34.pyc

�
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
s�|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�S|j�jj
ks�t�d}|j}t|�dkr�|djtjkr�|dj}|dd�}nd}t|�dkr,|dj�jjkr,|d}|dd�}n�j||�}|dk	r�|j�jjkset�|j}	|	d}
|
jtjkr�d}tj}n�|
jtjkr�d}tj}n�|
jtjkrH|	djtjks�t�t|	�dkst��j|	d�}}t|	�dkrT�j|	d�}qTnd
sTt�|dksl|dkr�|j�}tj|ggd|d	|�}q�n|dk	r�||_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	��F���r6r6r6)r4r5)rr"ZMatcher�childrenZAlternatives�lenr	�WildcardPattern�optimizeZAlternativeZNegatedUnit�
compile_basicZNegatedPatternZUnit�AssertionErrorr�EQUALrZRepeater�STARZHUGE�PLUS�LBRACE�RBRACE�get_int�name)
r%�nodeZalts�pZunits�patternrC�nodes�repeatr7Zchildr2r3r)r%rr)Dsh)(


	(
+
	
'zPatternCompiler.compile_nodeNcCst|�dkst�|d}|jtjkrbttj|j��}t	j
t|�|�S|jtjkr||j}|j
�r�|tkr�td|��n|dd�r�td��nt	j
t|�S|dkr�d}nF|jd�s3t|j|d�}|dkr3td|��q3n|dd�rc|j|djd�g}nd}t	j||�Sns|jdkr�|j|d�S|jd	kr�|dks�t�|j|d�}t	j|ggd
ddd�Sdst|��dS)
NrrzInvalid token: %rzCan't have details for token�any�_zInvalid symbol: %r�(�[r2r3F)r8r<rr�STRINGr(rZ
evalStringrr	ZLeafPattern�_type_of_literal�NAME�isupper�	TOKEN_MAPr�
startswith�getattrr#r)r7ZNodePatternr9)r%rGrHrDrrZcontent�
subpatternrrrr;�s<
		 zPatternCompiler.compile_basiccCs%|jtjkst�t|j�S)N)rr�NUMBERr<�intr)r%rDrrrrB�szPatternCompiler.get_int)	rr
r�_PATTERN_GRAMMAR_FILEr&r,r)r;rBrrrrr +s
G#r rOrMrUZTOKENcCs9|dj�rtjS|tjkr1tj|SdSdS)Nr)�isalpharrOrZopmap)rrrrrN�s
rNcCsW|\}}}}|s'||jkr=tj||d|�Stj||d|�SdS)z9Converts raw node information to a Node or Leaf instance.�contextN)Z
number2symbolr	ZNodeZLeaf)rZ
raw_node_inforrrYr7rrrr$�sr$cCst�j|�S)N)r r,)rFrrrr,�sr,)�__doc__�
__author__r�osZpgen2rrrrrr�r	r
�path�join�dirname�__file__rW�	Exceptionrr�objectr rOrMrUrQrNr$r,rrrr�<module>	s$.	
�



		

Zerion Mini Shell 1.0