Hacked By AnonymousFox

Current Path : /opt/alt/python310/lib64/python3.10/lib2to3/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/lib2to3/__pycache__/patcomp.cpython-310.opt-1.pyc

o

6��f��@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�6/opt/alt/python310/lib64/python3.10/lib2to3/patcomp.pyrsrc	csN�tjtjtjh}t�t�|�j�}|D]}|\}}}}}||vr$|VqdS)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�Zd
d	d
�Zdd�ZdS)�PatternCompilerNcCsZ|dur
tj|_tj|_n
t�|�|_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
Csbt|�}z
|jj||d�}Wntjy"}ztt|��d�d}~ww|r,|�|�|fS|�|�S)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
sD|j�jjkr|jd}|j�jjkr=�fdd�|jddd�D�}t|�dkr,|dStjdd�|D�ddd�}|��S|j�jj	kre�fd	d�|jD�}t|�dkrX|dStj|gddd�}|��S|j�jj
kr��|jdd��}t�|�}|��Sd}|j}t|�d
kr�|djt
jkr�|dj}|dd�}d}t|�dkr�|dj�jjkr�|d}|dd�}��||�}|du�r|j}	|	d}
|
jt
jkr�d}tj}n(|
jt
jkr�d}tj}n|
jt
jkr���|	d�}}t|	�dkr���|	d
�}|dk�s|dk�r|��}tj|gg||d�}|du�r||_|��S)
zXCompiles a node, recursively.

        This is one big switch on the node type.
        rc�g|]}��|��qSr�r(��.0Zch�r$rr�
<listcomp>O�z0PatternCompiler.compile_node.<locals>.<listcomp>N�rcSsg|]}|g�qSrr)r/�arrrr1Rs��min�maxcr,rr-r.r0rrr1Vr2�����)rr!ZMatcher�childrenZAlternatives�lenr	�WildcardPattern�optimizeZAlternativeZNegatedUnit�
compile_basicZNegatedPatternr�EQUALrZRepeater�STARZHUGE�PLUS�LBRACE�get_int�name)
r$�nodeZalts�pZunits�patternrE�nodes�repeatr;�childr6r7rr0rr(Cs^




zPatternCompiler.compile_nodecCs:|d}|jtjkrtt�|j��}t�t	|�|�S|jtj
kry|j}|��rB|tvr1t
d|��|dd�r;t
d��t�t|�S|dkrId}n|�d�s_t|j|d�}|dur_t
d|��|dd�rq|�|djd�g}nd}t�||�S|jdkr�|�|d�S|jd	kr�|�|d�}tj|ggddd
�SdS)NrzInvalid token: %rrzCan't have details for token�any�_zInvalid symbol: %r�(�[r5)rr�STRINGr'rZ
evalStringrr	ZLeafPattern�_type_of_literal�NAME�isupper�	TOKEN_MAPr�
startswith�getattrr"r(r;ZNodePatternr=)r$rIrJrFrrZcontent�
subpatternrrrr?�s8


�zPatternCompiler.compile_basiccCs
t|j�S�N)�intr)r$rFrrrrD�s
zPatternCompiler.get_intrX)FF)rr
rr%r+r(r?rDrrrrr &s


G#r )rRrP�NUMBERZTOKENcCs*|d��r	tjS|tjvrtj|SdS)Nr)�isalpharrRrZopmap)rrrrrQ�s


rQcCs:|\}}}}|s
||jvrtj|||d�Stj|||d�S)z9Converts raw node information to a Node or Leaf instance.)�context)Z
number2symbolr	ZNodeZLeaf)rZ
raw_node_inforrr\r;rrrr#�sr#cCst��|�SrX)r r+)rHrrrr+�sr+)�__doc__�
__author__rZpgen2rrrrrr�r	r
�	Exceptionrr�objectr rRrPrZrTrQr#r+rrrr�<module>s$ 
�		

Hacked By AnonymousFox1.0, Coded By AnonymousFox