AlkantarClanX12

Your IP : 3.141.29.202


Current Path : /lib64/python3.8/lib2to3/__pycache__/
Upload File :
Current File : //lib64/python3.8/lib2to3/__pycache__/patcomp.cpython-38.opt-1.pyc

U

e5d��@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�'/usr/lib64/python3.8/lib2to3/patcomp.pyrsrc	csLtjtjtjh}t�t�|�j�}|D] }|\}}}}}||kr&|Vq&dS)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|�}z|jj||d�}Wn2tjk
rN}ztt|��d�W5d}~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
sV|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�|�}|��Sd}|j}t|�d
k�r>|djt
jk�r>|dj}|dd�}d}t|�dk�rx|dj�jjk�rx|d}|dd�}��||�}|dk	�r>|j}	|	d}
|
jt
jk�r�d}tj}nX|
jt
jk�r�d}tj}n>|
jt
jk�r��|	d�}}t|	�dk�r��|	d
�}n|dk�s"|dk�r>|��}tj|gg||d�}|dk	�rN||_|��S)
zXCompiles a node, recursively.

        This is one big switch on the node type.
        rcsg|]}��|��qSr�r(��.0Zch�r$rr�
<listcomp>Osz0PatternCompiler.compile_node.<locals>.<listcomp>N�rcSsg|]
}|g�qSrr)r.�arrrr0Rs��min�maxcsg|]}��|��qSrr,r-r/rrr0Vs�����)rr!ZMatcher�childrenZAlternatives�lenr	�WildcardPattern�optimizeZAlternativeZNegatedUnit�
compile_basicZNegatedPatternr�EQUALrZRepeater�STARZHUGE�PLUS�LBRACE�get_int�name)
r$�nodeZalts�pZunits�patternrC�nodes�repeatr9Zchildr4r5rr/rr(Cs^

 
"

zPatternCompiler.compile_nodecCs@|d}|jtjkr4tt�|j��}t�t	|�|�S|jtj
kr�|j}|��r�|tkrbt
d|��|dd�rvt
d��t�t|�S|dkr�d}n,|�d�s�t|j|d�}|dkr�t
d|��|dd�r�|�|djd�g}nd}t�||�SnH|jdk�r|�|d�S|jd	k�r<|�|d�}tj|ggddd
�SdS)NrzInvalid token: %rrzCan't have details for token�any�_zInvalid symbol: %r�(�[r3)rr�STRINGr'rZ
evalStringrr	ZLeafPattern�_type_of_literal�NAME�isupper�	TOKEN_MAPr�
startswith�getattrr"r(r9ZNodePatternr;)r$rGrHrDrrZcontent�
subpatternrrrr=�s8
zPatternCompiler.compile_basiccCs
t|j�S�N)�intr)r$rDrrrrB�szPatternCompiler.get_int)N)FF)N)rr
rr%r+r(r=rBrrrrr &s


G
#r )rOrM�NUMBERZTOKENcCs.|d��rtjS|tjkr&tj|SdSdS)Nr)�isalpharrOrZopmap)rrrrrN�s


rNcCs>|\}}}}|s||jkr*tj|||d�Stj|||d�SdS)z9Converts raw node information to a Node or Leaf instance.)�contextN)Z
number2symbolr	ZNodeZLeaf)rZ
raw_node_inforrrYr9rrrr#�sr#cCst��|�SrU)r r+)rFrrrr+�sr+)�__doc__�
__author__rZpgen2rrrrrr�r	r
�	Exceptionrr�objectr rOrMrWrQrNr#r+rrrr�<module>s" 
�