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.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
s�|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�|�}|��S|j�jj
ks�J�d}|j}t|�d
kr�|djtjkr�|dj}|dd�}d}t|�dkr�|dj�jjkr�|d}|dd�}��||�}|du�rA|j�jjks�J�|j}	|	d}
|
jtjkr�d}tj}nA|
jtjkr�d}tj}n5|
jtjk�r'|	djtjk�sJ�t|	�dv�sJ���|	d�}}t|	�d
k�r&��|	d
�}nJ�|dk�s3|dk�rA|��}tj|gg||d�}|du�rI||_|��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����)r8�r:)rr!ZMatcher�childrenZAlternatives�lenr	�WildcardPattern�optimizeZAlternativeZNegatedUnit�
compile_basicZNegatedPatternZUnitr�EQUALrZRepeater�STARZHUGE�PLUS�LBRACE�RBRACE�get_int�name)
r$�nodeZalts�pZunits�patternrF�nodes�repeatr;�childr6r7rr0rr(Csj



�
zPatternCompiler.compile_nodecCsZt|�dksJ�|d}|jtjkr"tt�|j��}t�	t
|�|�S|jtjkr�|j}|��rJ|t
vr9td|��|dd�rCtd��t�	t
|�S|dkrQd}n|�d�sgt|j|d�}|durgtd|��|dd�ry|�|djd�g}nd}t�||�S|jdkr�|�|d�S|jd	kr�|dus�J�|�|d�}tj|ggddd
�SJ|��)NrrzInvalid token: %rzCan't have details for token�any�_zInvalid symbol: %r�(�[r5)r<rr�STRINGr'rZ
evalStringrr	ZLeafPattern�_type_of_literal�NAME�isupper�	TOKEN_MAPr�
startswith�getattrr"r(r;ZNodePatternr=)r$rJrKrGrrZcontent�
subpatternrrrr?�s<


zPatternCompiler.compile_basiccCs|jtjksJ�t|j�S�N)rr�NUMBER�intr)r$rGrrrrE�s
zPatternCompiler.get_intrY)FF)rr
rr%r+r(r?rErrrrr &s


G#r )rSrQrZZTOKENcCs*|d��r	tjS|tjvrtj|SdS)Nr)�isalpharrSrZopmap)rrrrrR�s


rRcCs:|\}}}}|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��|�SrY)r r+)rIrrrr+�sr+)�__doc__�
__author__rZpgen2rrrrrr�r	r
�	Exceptionrr�objectr rSrQrZrUrRr#r+rrrr�<module>s$ 
�		

Hacked By AnonymousFox1.0, Coded By AnonymousFox