
    j>                        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dS )    )abstractmethodabstractproperty)ListOptionalTupleUnion)split_linesnode
NodeOrLeaf
node_typesreturnOptional[BaseNode]c                      | j         | S )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.
    )search_ancestor)r
   r   s     Q/home/ubuntu/.hermes/hermes-agent/venv/lib/python3.11/site-packages/parso/tree.pyr   r      s      4,,    c                   B   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dS )r   z.
    The base class for nodes and leaves.
    parenttyper   r   c                 4    | }|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'    
 l&LE l&r   c                     | j         }|dS t          |j                  D ]3\  }}|| u r*	 | j         j        |dz            c S # t          $ r Y  dS w xY w4dS )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_sibling-   s    
 >4 "&/22 	  	 HAu}} ;/A6666!      444  	  	 s   A
AAc                     | j         }|dS t          |j                  D ])\  }}|| u r |dk    r dS | j         j        |dz
           c S *dS )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_sibling>   sv     >4 "&/22 	3 	3HAu}}6644{+AE2222 	3 	3r   c                     | j         dS | }	 |j         j        }|                    |          }|dk    r|j         }|j         dS n||dz
           }nE	 	 |j        d         }n# 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.
        NTr   r   )r   r   indexAttributeErrorr   r
   cr!   s       r   get_previous_leafzNodeOrLeaf.get_previous_leafO   s    
 ;4		$AAAvv{;&4 ' Qx			}R(!   	s   A" "A10A1c                 
   | j         dS | }	 |j         j        }|                    |          }|t          |          dz
  k    r|j         }|j         dS n||dz            }nU	 	 |j        d         }n# 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.
        NTr   r   )r   r   r(   lenr)   r*   s       r   get_next_leafzNodeOrLeaf.get_next_leafi   s    
 ;4		$AACFFQJ{;&4 ' Qx			}Q'!   	s   $A2 2B Br   c                     dS )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                     dS )z
        Returns the end position of the prefix as a tuple, e.g. `(3, 4)`.

        :return tuple of int: (line, column)
        Nr1   r2   s    r   end_poszNodeOrLeaf.end_pos   r4   r   c                     dS )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)
        Nr1   r2   s    r   get_start_pos_of_prefixz"NodeOrLeaf.get_start_pos_of_prefix   r4   r   c                     dS )zO
        Returns the first leaf of a node or itself if this is a leaf.
        Nr1   r2   s    r   get_first_leafzNodeOrLeaf.get_first_leaf   r4   r   c                     dS )zN
        Returns the last leaf of a node or itself if this is a leaf.
        Nr1   r2   s    r   get_last_leafzNodeOrLeaf.get_last_leaf   r4   r   Tc                     dS )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.
        Nr1   r   include_prefixs     r   get_codezNodeOrLeaf.get_code   r4   r   r   c                 @    | j         }||j        |v r|S |j         }|dS )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.
        N)r   r   )r   r   r
   s      r   r   zNodeOrLeaf.search_ancestor   s9     {yJ&&;D  tr      )indentrC   c          	         |ddnIt          |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)),
        ])
        NF T z,expect 'indent' to be int, str or None, got r
   rC   	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                    r_|| | 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  }n|dz  }|S )NrE   (, z	, prefix=)[
F)rC   rG   z])zunsupported node encountered: z,
)r   __name__
isinstanceLeaf	ErrorLeaf
token_type	TypedLeafvaluer3   prefixBaseNodeNoder   	TypeError)	r
   rC   rG   result	node_typer"   _format_dumpindent_stringnewlines	         r   r[   z%NodeOrLeaf.dump.<locals>._format_dump   s   FT

+I$%% KV1Y1111dI.. 16666FFi00 10000FTZ??T^???; :9$+999F#D(++ KV1Y1111dD)) 10000F# #dNF!] b bEll5-9O[`aaaaFFV---'   I I IJJJ # #eOFFdNFMr   )rE   T)rO   intstrrX   r   bool)r   rC   r[   r\   r]   s     @@@r   dumpzNodeOrLeaf.dump   s    L >GMM$$ 	WG&LMM$$ 	WG"MMU6UUVVV"	 "	z "	3 "	 "	X[ "	 "	 "	 "	 "	 "	 "	 "	H |D!!!r   NT)rN   
__module____qualname____doc__	__slots__r_   __annotations__r   r#   r%   r,   r/   r   r   r^   r3   r6   r   r8   r:   r<   r@   r   r   r   ra   r1   r   r   r   r      s          I
III !   
       "3 3 3"  4  4 5c?     sCx       ^   ^
   ^
    ^3 3G     ;< V" V" V"huS#X7 V" V" V" V" V" 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dS )rP   z
    Leafs are basically tokens with a better API. Leafs exactly know where they
    were defined and what text preceeds them.
    )rT   linecolumnrU   rU   rE   rT   r3   r   Nc                 B    || _         	 || _        || _        	 d | _        d S N)rT   r3   rU   r   )r   rT   r3   rU   s       r   __init__zLeaf.__init__#  s6    
	 #	 +/	 	r   c                     | j         | j        fS rl   ri   rj   r2   s    r   r3   zLeaf.start_pos3  s    y$+%%r   c                 :    |d         | _         |d         | _        d S )Nr   r   ro   r   rT   s     r   r3   zLeaf.start_pos7  s    !H	Ahr   c                     |                                  }|0t          | j                  }| j        t	          |          z
  dz   dfS |j        S )Nr   r   )r,   r	   rU   ri   r.   r6   )r   previous_leafliness      r   r8   zLeaf.get_start_pos_of_prefix<  sN    ..00 ,,E9s5zz)A-q00$$r   c                     | S rl   r1   r2   s    r   r:   zLeaf.get_first_leafD      r   c                     | S rl   r1   r2   s    r   r<   zLeaf.get_last_leafG  rv   r   Tc                 2    |r| j         | j        z   S | j        S rl   )rU   rT   r>   s     r   r@   zLeaf.get_codeJ  s!     	;++:r   c                     t          | j                  }| j        t          |          z   dz
  }| j        |k    r| j        t          |d                   z   }nt          |d                   }||fS )Nr   r'   )r	   rT   ri   r.   rj   )r   rt   end_pos_lineend_pos_columns       r   r6   zLeaf.end_posP  sg    DJ''y3u::-19$$![3uRy>>9NN r^^N^++r   c                 X    | j         }|s| j        }dt          |           j        d|dS )N<: >)rT   r   rN   rq   s     r   __repr__zLeaf.__repr__[  s7    
 	IE!$ZZ000%%%88r   rE   rb   )rN   rc   rd   re   rf   r_   rg   r   r^   rm   propertyr3   setterr8   r:   r<   r@   r6   r   r1   r   r   rP   rP     sV          6IKKK c eCHo s TX      &5c? & & & X& uS#X 4    % % %        ,sCx , , , X,9 9 9 9 9r   rP   c                   $     e Zd ZdZd fd	Z xZS )rS   r   rE   c                 \    t                                          |||           || _        d S rl   superrm   r   )r   r   rT   r3   rU   	__class__s        r   rm   zTypedLeaf.__init__e  s*    	6222			r   r   )rN   rc   rd   rf   rm   __classcell__r   s   @r   rS   rS   b  sB        I         r   rS   c                       e Zd ZdZdZd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dS )rV   zd
    The super class for all nodes.
    A node has children, a type and possibly a parent node.
    )r   r   Nc                 >    || _         	 d | _        	 |D ]	}| |_        
d S rl   )r   r   )r   r   r"   s      r   rm   zBaseNode.__init__q  s@     	 +/	  	  	 EELL	  	 r   c                 &    | j         d         j        S Nr   )r   r3   r2   s    r   r3   zBaseNode.start_pos~  s    }Q))r   c                 @    | j         d                                         S r   )r   r8   r2   s    r   r8   z BaseNode.get_start_pos_of_prefix  s    }Q77999r   c                 &    | j         d         j        S Nr'   )r   r6   r2   s    r   r6   zBaseNode.end_pos  s    }R ((r   c                     |rd                     d |D                       S |d                             d          }|d                     d |dd          D                       z   S )NrE   c              3   >   K   | ]}|                                 V  d S rl   r@   .0r+   s     r   	<genexpr>z2BaseNode._get_code_for_children.<locals>.<genexpr>  s*      ::A1::<<::::::r   r   F)r?   c              3   >   K   | ]}|                                 V  d S rl   r   r   s     r   r   z2BaseNode._get_code_for_children.<locals>.<genexpr>  s*      "F"FA1::<<"F"F"F"F"F"Fr   r   )joinr@   )r   r   r?   firsts       r   _get_code_for_childrenzBaseNode._get_code_for_children  st     	G77::::::::QK(((>>E277"F"F!"""F"F"FFFFFr   Tc                 8    |                      | j        |          S rl   )r   r   r>   s     r   r@   zBaseNode.get_code  s    **4=.IIIr   Fc                       fddcxk    r j         d         j        k    sn 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    rEj         |          }s|j        k     rd S 	 |                              S # t          $ r |cY S w xY wt	          | |z   dz            }j         |         }|j        k    r | |          S  |dz   |          S )N   r   )r   r3   get_leaf_for_positionr)   r^   r6   )lowerupperelementr(   binary_searchinclude_prefixespositionr   s       r   r   z5BaseNode.get_leaf_for_position.<locals>.binary_search  s    ~~-.'  Hw7H,H,H4#"88CSTTT% # # #"NNN# !+,,EmE*G7?**$}UE222$}UQY666s   ; A
	A
)r   r   r'   z7Please provide a position that exists within this node.r   r   )r   r6   
ValueErrorr.   )r   r   r   r   s   ```@r   r   zBaseNode.get_leaf_for_position  s    	7 	7 	7 	7 	7 	7 	7 	7& (????dmB&7&?????VWWW}QDM 2 2Q 6777r   c                 @    | j         d                                         S r   )r   r:   r2   s    r   r:   zBaseNode.get_first_leaf  s    }Q..000r   c                 @    | j         d                                         S r   )r   r<   r2   s    r   r<   zBaseNode.get_last_leaf  s    }R ..000r   c           	         |                                                      dd                              dd                                          }dt          |           j        d|d| j        d         d| j        d	         d
	S )NrM   rF   r}   r~   @r   ,r   r   )r@   replacestripr   rN   r3   )r   codes     r   r   zBaseNode.__repr__  s    }}&&tS1199$DDJJLL$ZZ   $$$q(9(9(94>!;L;L;LN 	Nr   )r   Nrb   )F)rN   rc   rd   re   rf   rm   r   r   r^   r3   r8   r6   r   r@   r   r:   r<   r   r1   r   r   rV   rV   j  s         I        *5c? * * * X*: : : )sCx ) ) ) X)G G GJ J J J8 8 8 8@1 1 11 1 1N N N N Nr   rV   c                   ,     e Zd ZdZdZ fdZd Z xZS )rW   z+Concrete implementation for interior nodes.r   c                 X    t                                          |           || _        d S rl   r   )r   r   r   r   s      r   rm   zNode.__init__  s&    """			r   c                 @    | j         j        d| j        d| j        dS )NrI   rJ   rK   )r   rN   r   r   r2   s    r   r   zNode.__repr__  s&    #~666			4===QQr   )rN   rc   rd   re   rf   rm   r   r   r   s   @r   rW   rW     sY        55I    R R R R R R Rr   rW   c                       e Zd ZdZdZdZdS )	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.
    r1   
error_nodeN)rN   rc   rd   re   rf   r   r1   r   r   r   r     s$         
 IDDDr   r   c                   2     e Zd ZdZdZdZd fd	Zd Z xZS )rQ   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`.
    )rR   
error_leafrE   c                 \    t                                          |||           || _        d S rl   )r   rm   rR   )r   rR   rT   r3   rU   r   s        r   rm   zErrorLeaf.__init__  s*    	6222$r   c           	      |    dt          |           j        d| j        dt          | j                  d| j        d	S )Nr}   r~   :rJ   r   )r   rN   rR   reprrT   r3   r2   s    r   r   zErrorLeaf.__repr__  sD     $ZZ   $///4
3C3C3C3CT^^^U 	Ur   r   )	rN   rc   rd   re   rf   r   rm   r   r   r   s   @r   rQ   rQ     si           ID% % % % % %U U U U U U Ur   rQ   N)abcr   r   typingr   r   r   r   parso.utilsr	   r_   r   r   rP   rS   rV   rW   r   rQ   r1   r   r   <module>r      s   0 0 0 0 0 0 0 0 / / / / / / / / / / / / # # # # # #
-, 
-S 
-=Q 
- 
- 
- 
-D" D" D" D" D" D" D" D"ND9 D9 D9 D9 D9: D9 D9 D9N       RN RN RN RN RNz RN RN RNj	R 	R 	R 	R 	R8 	R 	R 	R       U U U U U U U U U Ur   