
    ;e                         	 d Z ddlZddlmZmZmZmZmZmZ ddl	m
Z
 ddl	mZ  G d de          Zd	 Z G d
 de          Zej        ej        ej        ddZd Zd Zd ZdS )z#Guido van Rossum <guido@python.org>    N   )driverliteralstokentokenizeparsegrammar)pytree)pygramc                       e Zd ZdS )PatternSyntaxErrorN)__name__
__module____qualname__     &/usr/lib/python3.11/lib2to3/patcomp.pyr   r      s        Dr   r   c              #      K   	 t           j        t           j        t           j        h}t	          j        t          j        |           j                  }|D ]}|\  }}}}}||vr|V  d S N)	r   NEWLINEINDENTDEDENTr   generate_tokensioStringIOreadline)	inputskiptokens	quintupletypevaluestartend	line_texts	            r   tokenize_wrapperr&      sv      @M5<6D%bk%&8&8&ABBF  	-6*eUCtOOO r   c                   2    e Zd ZddZd	dZd ZddZd ZdS )
PatternCompilerNc                 N   	 |#t           j        | _        t           j        | _        n7t          j        |          | _        t          j        | j                  | _        t           j        | _	        t           j
        | _        t          j        | j        t                    | _        d S )N)convert)r   pattern_grammarr	   pattern_symbolssymsr   load_grammarSymbolspython_grammar	pygrammarpython_symbolspysymsDriverpattern_convert)selfgrammar_files     r   __init__zPatternCompiler.__init__(   sz    	 !1DL.DII!.|<<DLt|44DI.+mDL/JJJr   Fc                 "   	 t          |          }	 | j                            ||          }n4# t          j        $ r"}t          t          |                    d d }~ww xY w|r|                     |          |fS |                     |          S )N)debug)r&   r   parse_tokensr   
ParseErrorr   strcompile_node)r6   r   r:   	with_treer   rootes          r   compile_patternzPatternCompiler.compile_pattern7   s    K!%((	7;++F%+@@DD 	7 	7 	7$SVV,,$6	7 	+$$T**D00$$T***s   / A AA c                 R    	 |j          j        j        k    r|j        d         }|j          j        j        k    rl fd|j        d d d         D             }t          |          dk    r|d         S t          j        d |D             dd          }|                                S |j          j        j	        k    rZ fd|j        D             }t          |          dk    r|d         S t          j        |gdd          }|                                S |j          j        j
        k    rJ                     |j        dd                    }t          j        |          }|                                S d }|j        }t          |          dk    r2|d         j         t          j        k    r|d         j        }|dd          }d }t          |          dk    r-|d	         j          j        j        k    r|d	         }|d d	         }                     ||          }||j        }	|	d         }
|
j         t          j        k    rd}t          j        }n|
j         t          j        k    rd}t          j        }n`|
j         t          j        k    rK                     |	d                   x}}t          |	          d
k    r                     |	d                   }|dk    s|dk    r-|                                }t          j        |gg||          }|||_        |                                S )Nr   c                 :    g | ]}                     |          S r   r>   .0chr6   s     r   
<listcomp>z0PatternCompiler.compile_node.<locals>.<listcomp>O   s'    GGGbD%%b))GGGr      r   c                     g | ]}|gS r   r   )rG   as     r   rI   z0PatternCompiler.compile_node.<locals>.<listcomp>R   s    ':':':':':':r   minmaxc                 :    g | ]}                     |          S r   rE   rF   s     r   rI   z0PatternCompiler.compile_node.<locals>.<listcomp>V   s'    CCCrT&&r**CCCr         )r!   r-   MatcherchildrenAlternativeslenr
   WildcardPatternoptimizeAlternativeNegatedUnitcompile_basicNegatedPatternr   EQUALr"   RepeaterSTARHUGEPLUSLBRACEget_intname)r6   nodealtspunitspatternre   nodesrepeatrU   childrN   rO   s   `            r   r>   zPatternCompiler.compile_nodeC   s   	 9	)))=#D9	...GGGGDM##A#4FGGGD4yyA~~Aw&':':T':':':qIIIA::<<9	---CCCCT]CCCE5zzQQx&wA1===A::<<9	---((qrr):;;G%g..A::<< u::??uQx};;8>D!""IEu::??uRy~1CCC2YF#2#JE $$UF33HQKEzUZ''kuz))ku|++ !LL!555cx==A%%,,x{33C axx3!88!**,, 07)#3OOOGL!!!r   c                    |d         }|j         t          j        k    rHt          t	          j        |j                            }t          j        t          |          |          S |j         t          j
        k    r|j        }|                                rS|t          vrt          d|z            |dd          rt          d          t          j        t          |                   S |dk    rd }n?|                    d          s*t          | j        |d           }|t          d|z            |dd          r(|                     |d         j        d                   g}nd }t          j        ||          S |j        dk    r|                     |d                   S |j        d	k    r4|                     |d                   }t          j        |ggdd
          S d S )Nr   zInvalid token: %rr   zCan't have details for tokenany_zInvalid symbol: %r([rM   )r!   r   STRINGr=   r   
evalStringr"   r
   LeafPattern_type_of_literalNAMEisupper	TOKEN_MAPr   
startswithgetattrr3   r>   rU   NodePatternrX   )r6   rk   rl   rf   r"   r!   content
subpatterns           r   r\   zPatternCompiler.compile_basic   s    Qx9$$+DJ7788E%&6u&=&=uEEEY%*$$JE}} 9	)),-@5-HIII9 M,-KLLL))E*:;;;E>>DD))#.. O"4;t<<D|01E1MNNN9 ##00q1B11EFFGGG"G)$888Z3$$U1X...Z3**5844J)J<.aQGGGG r   c                 *    t          |j                  S r   )intr"   )r6   rf   s     r   rd   zPatternCompiler.get_int   s    4:r   r   )FF)r   r   r   r8   rB   r>   r\   rd   r   r   r   r(   r(   &   sw        K K K K
+ 
+ 
+ 
+E" E" E"N! ! ! !F    r   r(   )rw   rs   NUMBERTOKENc                     | d                                          rt          j        S | t          j        v rt          j        |          S d S )Nr   )isalphar   rw   r	   opmap)r"   s    r   rv   rv      sA    Qx z	'-		}U##tr   c                     	 |\  }}}}|s	|| j         v rt          j        |||          S t          j        |||          S )N)context)number2symbolr
   NodeLeaf)r	   raw_node_infor!   r"   r   rU   s         r   r5   r5      sV    C%2"D%( 947000{47;;;;{48888r   c                 D    t                                          |           S r   )r(   rB   )rj   s    r   rB   rB      s    ,,W555r   )
__author__r   pgen2r   r   r   r   r   r	    r
   r   	Exceptionr   r&   objectr(   rw   rs   r   ry   rv   r5   rB   r   r   r   <module>r      s8   3
 
			 E D D D D D D D D D D D D D D D            	 	 	 	 	 	 	 	  I I I I If I I IZ Z|| 	  9 9 96 6 6 6 6r   