
    f?                         d dl mZmZ d dlmZmZmZmZ d dlm	Z	 ddde
ddfd	Z G d
 d      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Zy)    )abstractmethodabstractproperty)ListOptionalTupleUnion)split_linesnode
NodeOrLeaf
node_typesreturnOptional[BaseNode]c                 ^    | j                   }||j                  |v r|S |j                   }|y)an  
    Recursively looks at the parents of a node and returns the first found node
    that matches ``node_types``. Returns ``None`` if no matching node is found.

    This function is deprecated, use :meth:`NodeOrLeaf.search_ancestor` instead.

    :param node: The ancestors of this node will be checked.
    :param node_types: type names that are searched for.
    Nparenttype)r
   r   ns      E/var/www/cvtools/html/venv/lib/python3.12/site-packages/parso/tree.pysearch_ancestorr      s8     	A
-66ZHHH -     c                      e Zd ZU dZdZeed<   	 ded<   	 d Zd Zd Z	d	 Z
d
 Zedeeef   fd       Zedeeef   fd       Zed        Zed        Zed        Zedd       ZdeddfdZdddeeeef      defdZy)r   z.
    The base class for nodes and leaves.
    r   r   r   r   c                 T    | }|j                   |j                   }|j                   |S )z
        Returns the root node of a parser tree. The returned node doesn't have
        a parent node like all the other nodes/leaves.
        r   )selfscopes     r   get_root_nodezNodeOrLeaf.get_root_node(   s-    
 ll&LLE ll&r   c                     | j                   }|yt        |j                        D ](  \  }}|| u s	 | j                   j                  |dz      c S  y# t        $ r Y  yw xY w)z
        Returns the node immediately following this node in this parent's
        children list. If this node does not have a next sibling, it is None
        N   )r   	enumeratechildren
IndexErrorr   r   ichilds       r   get_next_siblingzNodeOrLeaf.get_next_sibling2   sl    
 > "&//2 	 HAu} ;;//A66	  "   s   A	AAc                     | j                   }|yt        |j                        D ].  \  }}|| u s|dk(  r y| j                   j                  |dz
     c S  y)z
        Returns the node immediately preceding this node in this parent's
        children list. If this node does not have a previous sibling, it is
        None.
        Nr   r   )r   r   r    r"   s       r   get_previous_siblingzNodeOrLeaf.get_previous_siblingC   s]     > "&//2 	3HAu}6{{++AE22		3r   c                    | j                   y| }	 |j                   j                  }|j                  |      }|dk(  r|j                   }|j                   
y||dz
     }nO	 	 |j                  d   }# t        $ r |cY S w xY w)z
        Returns the previous leaf in the parser tree.
        Returns `None` if this is the first element in the parser tree.
        Nr   r   )r   r    indexAttributeErrorr   r
   cr#   s       r   get_previous_leafzNodeOrLeaf.get_previous_leafT   s    
 ;;$$AAAv{{;;&Qx  }}R(  " s   "A2 2B ?B c                    | j                   y| }	 |j                   j                  }|j                  |      }|t        |      dz
  k(  r|j                   }|j                   
y||dz      }n[	 	 |j                  d   }# t        $ r |cY S w xY w)z
        Returns the next leaf in the parser tree.
        Returns None if this is the last element in the parser tree.
        Nr   r   )r   r    r*   lenr+   r,   s       r   get_next_leafzNodeOrLeaf.get_next_leafn   s    
 ;;$$AACFQJ{{;;&Qx  }}Q'  " s   .A> >BBr   c                      y)z
        Returns the starting position of the prefix as a tuple, e.g. `(3, 4)`.

        :return tuple of int: (line, column)
        N r   s    r   	start_poszNodeOrLeaf.start_pos       r   c                      y)z
        Returns the end position of the prefix as a tuple, e.g. `(3, 4)`.

        :return tuple of int: (line, column)
        Nr3   r4   s    r   end_poszNodeOrLeaf.end_pos   r6   r   c                      y)a-  
        Returns the start_pos of the prefix. This means basically it returns
        the end_pos of the last prefix. The `get_start_pos_of_prefix()` of the
        prefix `+` in `2 + 1` would be `(1, 1)`, while the start_pos is
        `(1, 2)`.

        :return tuple of int: (line, column)
        Nr3   r4   s    r   get_start_pos_of_prefixz"NodeOrLeaf.get_start_pos_of_prefix   r6   r   c                      y)zO
        Returns the first leaf of a node or itself if this is a leaf.
        Nr3   r4   s    r   get_first_leafzNodeOrLeaf.get_first_leaf   r6   r   c                      y)zN
        Returns the last leaf of a node or itself if this is a leaf.
        Nr3   r4   s    r   get_last_leafzNodeOrLeaf.get_last_leaf   r6   r   c                      y)z
        Returns the code that was the input for the parser for this node.

        :param include_prefix: Removes the prefix (whitespace and comments) of
            e.g. a statement.
        Nr3   r   include_prefixs     r   get_codezNodeOrLeaf.get_code   r6   r   r   c                 ^    | j                   }||j                  |v r|S |j                   }|y)a  
        Recursively looks at the parents of this node or leaf and returns the
        first found node that matches ``node_types``. Returns ``None`` if no
        matching node is found.

        :param node_types: type names that are searched for.
        Nr   )r   r   r
   s      r   r   zNodeOrLeaf.search_ancestor   s:     {{yyJ&;;D  r      )indentrE   c          	          |ddn;t        |t              rdd|z  n#t        |t              rd|nt        d|      ddt        dt        dt
        d	t        ffd
 |       S )a  
        Returns a formatted dump of the parser tree rooted at this node or leaf. This is
        mainly useful for debugging purposes.

        The ``indent`` parameter is interpreted in a similar way as :py:func:`ast.dump`.
        If ``indent`` is a non-negative integer or string, then the tree will be
        pretty-printed with that indent level. An indent level of 0, negative, or ``""``
        will only insert newlines. ``None`` selects the single line representation.
        Using a positive integer indent indents that many spaces per level. If
        ``indent`` is a string (such as ``"\t"``), that string is used to indent each
        level.

        :param indent: Indentation style as described above. The default indentation is
            4 spaces, which yields a pretty-printed dump.

        >>> import parso
        >>> print(parso.parse("lambda x, y: x + y").dump())
        Module([
            Lambda([
                Keyword('lambda', (1, 0)),
                Param([
                    Name('x', (1, 7), prefix=' '),
                    Operator(',', (1, 8)),
                ]),
                Param([
                    Name('y', (1, 10), prefix=' '),
                ]),
                Operator(':', (1, 11)),
                PythonNode('arith_expr', [
                    Name('x', (1, 13), prefix=' '),
                    Operator('+', (1, 15), prefix=' '),
                    Name('y', (1, 17), prefix=' '),
                ]),
            ]),
            EndMarker('', (1, 18)),
        ])
        F T z,expect 'indent' to be int, str or None, got r
   rE   	top_levelr   c                    d}t        |       j                  }t        | t              r|| | dz  }t        | t              r|| j
                  dz  }n"t        | t              r|| j                   dz  }|| j                  d| j                  z  }| j                  r|d| j                  z  }|dz  }nt        | t              rc|| | dz  }t        | t              r|| j                   dz  }|dz  }r|dz  }| j                  D ]  }| ||z   d	      z  } || d
z  }nt        d|       |sr|dz  }|S |dz  }|S )NrG   (, z	, prefix=)[
F)rE   rI   z])zunsupported node encountered: z,
)r   __name__
isinstanceLeaf	ErrorLeaf
token_type	TypedLeafvaluer5   prefixBaseNodeNoder    	TypeError)	r
   rE   rI   result	node_typer$   _format_dumpindent_stringnewlines	         r   r]   z%NodeOrLeaf.dump.<locals>._format_dump   s   FT
++I$%VHYKq11dI. 3266Fi0R00FTZZN"T^^,>??;;	$++99F#D(+VHYKq11dD)R00F#dNF!]] bEl5-9O[`aaFbVHB-'  "@ IJJeOF M dNFMr   )rG   T)rQ   intstrrZ   r   bool)r   rE   r]   r^   r_   s     @@@r   dumpzNodeOrLeaf.dump   s    L >GM$G&LM$G"MJ6*UVV"	z "	3 "	 "	X[ "	H D!!r   NT)rP   
__module____qualname____doc__	__slots__ra   __annotations__r   r%   r'   r.   r1   r   r   r`   r5   r8   r   r:   r<   r>   rB   r   r   r   rc   r3   r   r   r   r      s    I
I ! 
 "3"44 5c?   sCx      
  
  3 3G  ;< V"huS#X7 V" V"r   c            	           e Zd ZU dZdZeed<   ddedeeef   deddfdZ	e
deeef   fd	       Zej                  deeef   ddfd
       Zd Zd Zd ZddZe
deeef   fd       Zd Zy)rR   z
    Leafs are basically tokens with a better API. Leafs exactly know where they
    were defined and what text preceeds them.
    )rV   linecolumnrW   rW   rV   r5   r   Nc                 @    || _         	 || _        || _        	 d | _        y N)rV   r5   rW   r   )r   rV   r5   rW   s       r   __init__zLeaf.__init__(  s1    
	 #	 +/	r   c                 2    | j                   | j                  fS rn   rk   rl   r4   s    r   r5   zLeaf.start_pos8  s    yy$++%%r   c                 ,    |d   | _         |d   | _        y )Nr   r   rq   r   rV   s     r   r5   zLeaf.start_pos<  s    !H	Ahr   c                     | j                         }|2t        | j                        }| j                  t	        |      z
  dz   dfS |j
                  S )Nr   r   )r.   r	   rW   rk   r0   r8   )r   previous_leafliness      r   r:   zLeaf.get_start_pos_of_prefixA  sM    ..0 ,E99s5z)A-q00$$$r   c                     | S rn   r3   r4   s    r   r<   zLeaf.get_first_leafI      r   c                     | S rn   r3   r4   s    r   r>   zLeaf.get_last_leafL  rx   r   c                 P    |r| j                   | j                  z   S | j                  S rn   )rW   rV   r@   s     r   rB   zLeaf.get_codeO  s"    ;;++::r   c                     t        | j                        }| j                  t        |      z   dz
  }| j                  |k(  r| j                  t        |d         z   }||fS t        |d         }||fS )Nr   r)   )r	   rV   rk   r0   rl   )r   rv   end_pos_lineend_pos_columns       r   r8   zLeaf.end_posU  sp    DJJ'yy3u:-199$![[3uRy>9N ^++ !r^N^++r   c                 n    | j                   }|s| j                  }dt        |       j                  d|dS )N<: >)rV   r   rP   rs   s     r   __repr__zLeaf.__repr__`  s-    

IIE!$Z00%88r   rG   rd   )rP   re   rf   rg   rh   ra   ri   r   r`   ro   propertyr5   setterr:   r<   r>   rB   r8   r   r3   r   r   rR   rR      s     6IKc eCHo s TX   &5c? & & uS#X 4  % ,sCx , ,9r   rR   c                   $     e Zd ZdZd fd	Z xZS )rU   r   c                 6    t         |   |||       || _        y rn   superro   r   )r   r   rV   r5   rW   	__class__s        r   ro   zTypedLeaf.__init__j  s    	62	r   r   )rP   re   rf   rh   ro   __classcell__r   s   @r   rU   rU   g  s    I r   rU   c                       e Zd ZdZdZdee   ddfdZede	e
e
f   fd       Zd Zede	e
e
f   fd	       Zd
 ZddZddZd Zd Zd Zy)rX   zd
    The super class for all nodes.
    A node has children, a type and possibly a parent node.
    )r    r    r   Nc                 @    || _         	 d | _        	 |D ]	  }| |_         y rn   )r    r   )r   r    r$   s      r   ro   zBaseNode.__init__v  s4     	 +/	  	 EEL	 r   c                 4    | j                   d   j                  S Nr   )r    r5   r4   s    r   r5   zBaseNode.start_pos  s    }}Q)))r   c                 <    | j                   d   j                         S r   )r    r:   r4   s    r   r:   z BaseNode.get_start_pos_of_prefix  s    }}Q7799r   c                 4    | j                   d   j                  S Nr)   )r    r8   r4   s    r   r8   zBaseNode.end_pos  s    }}R (((r   c                     |rdj                  d |D              S |d   j                  d      }|dj                  d |dd  D              z   S )NrG   c              3   <   K   | ]  }|j                           y wrn   rB   .0r-   s     r   	<genexpr>z2BaseNode._get_code_for_children.<locals>.<genexpr>  s     :A1::<:   r   F)rA   c              3   <   K   | ]  }|j                           y wrn   r   r   s     r   r   z2BaseNode._get_code_for_children.<locals>.<genexpr>  s     "FA1::<"Fr   r   )joinrB   )r   r    rA   firsts       r   _get_code_for_childrenzBaseNode._get_code_for_children  sQ    77::::QK(((>E277"F!""FFFFr   c                 :    | j                  | j                  |      S rn   )r   r    r@   s     r   rB   zBaseNode.get_code  s    **4==.IIr   c                       fddcxk  r& j                   d   j                  k  st        d       t        d       dt         j                         dz
        S )ax  
        Get the :py:class:`parso.tree.Leaf` at ``position``

        :param tuple position: A position tuple, row, column. Rows start from 1
        :param bool include_prefixes: If ``False``, ``None`` will be returned if ``position`` falls
            on whitespace or comments before a leaf
        :return: :py:class:`parso.tree.Leaf` at ``position``, or ``None``
        c                     | |k(  r4j                   |    }s|j                  k  ry 	 |j                        S t	        | |z   dz        }j                   |   }|j
                  k  r	 | |      S  |dz   |      S # t        $ r |cY S w xY w)N   r   )r    r5   get_leaf_for_positionr+   r`   r8   )lowerupperelementr*   binary_searchinclude_prefixespositionr   s       r   r   z5BaseNode.get_leaf_for_position.<locals>.binary_search  s    ~--.'Hw7H7H,H#"88CSTT !+,EmmE*G7??*$UE22$UQY66 & #"N#s   A? ?BB)r   r   r)   z7Please provide a position that exists within this node.r   r   )r    r8   
ValueErrorr0   )r   r   r   r   s   ```@r   r   zBaseNode.get_leaf_for_position  s_    	7& (?dmmB&7&?&??VWW @VWWQDMM 2Q 677r   c                 <    | j                   d   j                         S r   )r    r<   r4   s    r   r<   zBaseNode.get_first_leaf  s    }}Q..00r   c                 <    | j                   d   j                         S r   )r    r>   r4   s    r   r>   zBaseNode.get_last_leaf  s    }}R ..00r   c           	          | j                         j                  dd      j                  dd      j                         }dt        |       j                  d|d| j
                  d   d| j
                  d	   d
	S )NrO   rH   r   r   @r   ,r   r   )rB   replacestripr   rP   r5   )r   codes     r   r   zBaseNode.__repr__  sa    }}&&tS199$DJJL$Z  $q(94>>!;LN 	Nr   rd   )F)rP   re   rf   rg   rh   r   r   ro   r   r   r`   r5   r:   r8   r   rB   r   r<   r>   r   r3   r   r   rX   rX   o  s     I j!1  d   *5c? * *: )sCx ) )GJ8@11Nr   rX   c                   ,     e Zd ZdZdZ fdZd Z xZS )rY   z+Concrete implementation for interior nodes.r   c                 2    t         |   |       || _        y rn   r   )r   r   r    r   s      r   ro   zNode.__init__  s    "	r   c                 h    | j                   j                  d| j                  d| j                  dS )NrK   rL   rM   )r   rP   r   r    r4   s    r   r   zNode.__repr__  s!    #~~66		4==QQr   )rP   re   rf   rg   rh   ro   r   r   r   s   @r   rY   rY     s    5IRr   rY   c                       e Zd ZdZdZdZy)	ErrorNodez
    A node that contains valid nodes/leaves that we're follow by a token that
    was invalid. This basically means that the leaf after this node is where
    Python would mark a syntax error.
    r3   
error_nodeN)rP   re   rf   rg   rh   r   r3   r   r   r   r     s    
 IDr   r   c                   2     e Zd ZdZdZdZd fd	Zd Z xZS )rS   z
    A leaf that is either completely invalid in a language (like `$` in Python)
    or is invalid at that position. Like the star in `1 +* 1`.
    )rT   
error_leafc                 6    t         |   |||       || _        y rn   )r   ro   rT   )r   rT   rV   r5   rW   r   s        r   ro   zErrorLeaf.__init__  s    	62$r   c           	          dt        |       j                  d| j                  dt        | j                        d| j
                  d	S )Nr   r   :rL   r   )r   rP   rT   reprrV   r5   r4   s    r   r   zErrorLeaf.__repr__  s2    $Z  $//4

3CT^^U 	Ur   r   )	rP   re   rf   rg   rh   r   ro   r   r   r   s   @r   rS   rS     s      ID%Ur   rS   N)abcr   r   typingr   r   r   r   parso.utilsr	   ra   r   r   rR   rU   rX   rY   r   rS   r3   r   r   <module>r      s    0 / / #, S =Q $D" D"ND9: D9N RNz RNj	R8 	R U Ur   