
    h?                         S SK JrJr  S SKJrJrJrJr  S SKJ	r	  SSS\
SS4S	 jr " S
 S5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rg)    )abstractmethodabstractproperty)ListOptionalTupleUnion)split_linesnode
NodeOrLeaf
node_typesreturnOptional[BaseNode]c                 h    U R                   nUb#  UR                  U;   a  U$ UR                   nUb  M#  g)aV  
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      ]C:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\parso/tree.pysearch_ancestorr      s8     	A
-66ZHHH -     c                      \ rS rSr% SrSr\\S'    S\S'    S rS r	S	 r
S
 rS r\S\\\4   4S j5       r\S\\\4   4S j5       r\S 5       r\S 5       r\S 5       r\SS j5       rS\SS4S jrSS.S\\\\4      S\4S jjrSrg)r      z&
The base class for nodes and leaves.
r   r   r   r   c                 Z    U nUR                   b  UR                   nUR                   b  M  U$ )zw
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_nodeNodeOrLeaf.get_root_node(   s-    
 ll&LLE ll&r   c                     U R                   nUc  g[        UR                  5       H(  u  p#X0L d  M   U R                   R                  US-      s  $    g! [         a       gf = f)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_siblingNodeOrLeaf.get_next_sibling2   sc    
 > "&//2HA} ;;//A66 3 "   s   A
A! A!c                     U R                   nUc  g[        UR                  5       H/  u  p#X0L d  M  US:X  a    gU R                   R                  US-
     s  $    g)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_siblingNodeOrLeaf.get_previous_siblingC   sT     > "&//2HA}6{{++AE22	 3r   c                    U R                   c  gU n UR                   R                  nUR                  U5      nUS:X  a  UR                   nUR                   c  gOX#S-
     nOMR    UR                  S   nM  ! [         a    Us $ f = f)zo
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_leafNodeOrLeaf.get_previous_leafT   s    
 ;;$$AAAv{{;;& ' Qx  }}R(  " s   &A7 7BBc                 *   U R                   c  gU n UR                   R                  nUR                  U5      nU[        U5      S-
  :X  a  UR                   nUR                   c  gOX#S-      nOM^    UR                  S   nM  ! [         a    Us $ f = f)zh
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/   r0   s       r   get_next_leafNodeOrLeaf.get_next_leafn   s    
 ;;$$AACFQJ{{;;& ' Qx  }}Q'  " s   2B BBr   c                     g)zn
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_posNodeOrLeaf.start_pos       r   c                     g)zi
Returns the end position of the prefix as a tuple, e.g. `(3, 4)`.

:return tuple of int: (line, column)
Nr9   r:   s    r   end_posNodeOrLeaf.end_pos   r=   r   c                     g)z
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)
Nr9   r:   s    r   get_start_pos_of_prefix"NodeOrLeaf.get_start_pos_of_prefix   r=   r   c                     g)z?
Returns the first leaf of a node or itself if this is a leaf.
Nr9   r:   s    r   get_first_leafNodeOrLeaf.get_first_leaf   r=   r   c                     g)z>
Returns the last leaf of a node or itself if this is a leaf.
Nr9   r:   s    r   get_last_leafNodeOrLeaf.get_last_leaf   r=   r   c                     g)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.
Nr9   r   include_prefixs     r   get_codeNodeOrLeaf.get_code   r=   r   r   c                 h    U R                   nUb#  UR                  U;   a  U$ UR                   nUb  M#  g)z
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   NodeOrLeaf.search_ancestor   s:     {{yyJ&;;D  r      )indentrR   c          	         ^^^ Uc  SmSmOF[        U[        5      (       a  SmSU-  mO)[        U[        5      (       a  SmUmO[        SU< 35      eSS[        S[        S[
        S	[        4UUU4S
 jjjmT" U 5      $ )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
   rR   	top_levelr   c                   > Sn[        U 5      R                  n[        U [        5      (       a  X1 U S3-  n[        U [        5      (       a  X0R
                  < S3-  nO'[        U [        5      (       a  X0R                   < S3-  nX0R                  < SU R                  < 3-  nU R                  (       a  USU R                  < 3-  nUS-  nO[        U [        5      (       ai  X1 U S3-  n[        U [        5      (       a  X0R                   < S3-  nUS-  nT(       a  US-  nU R                   H  nUT" XQT-   SS	9-  nM     X1 S
3-  nO[        SU < 35      eU(       d  T(       a  US-  nU$ US-  nU$ )NrT   (, z	, prefix=)[
F)rR   rV   z])zunsupported node encountered: z,
)r   __name__
isinstanceLeaf	ErrorLeaf
token_type	TypedLeafvaluer;   prefixBaseNodeNoder"   	TypeError)	r
   rR   rV   result	node_typer&   _format_dumpindent_stringnewlines	         r   rj   %NodeOrLeaf.dump.<locals>._format_dump   s|   FT
++I$%%HYKq11dI.. 3266Fi00R00FZZN"T^^,>??;;	$++99F#D(++HYKq11dD))R00F#dNF!]]El5-9O[`aaF +HB-'  "@ IJJeOF M dNFMr   )rT   T)r^   intstrrg   r   bool)r   rR   rj   rk   rl   s     @@@r   dumpNodeOrLeaf.dump   s    L >GM$$G&LM$$G"MJ6*UVV"	z "	3 "	 "	X[ "	 "	H D!!r   r9   NT)r]   
__module____qualname____firstlineno____doc__	__slots__ro   __annotations__r   r'   r*   r2   r6   r   r   rn   r;   r?   r   rB   rE   rH   rM   r   r   r   rq   __static_attributes__r9   r   r   r   r      s    I
I ! 
 "3"44 5c?   sCx      
  
  3 3G  ;< V"huS#X7 V" V" V"r   c            	           \ rS rSr% SrSr\\S'   SS\S\\	\	4   S\SS4S	 jjr
\S\\	\	4   4S
 j5       r\R                  S\\	\	4   SS4S j5       rS rS rS rSS jr\S\\	\	4   4S j5       rS rSrg)r_   i   zw
Leafs are basically tokens with a better API. Leafs exactly know where they
were defined and what text preceeds them.
)rc   linecolumnrd   rd   rc   r;   r   Nc                 :    Xl          X l        X0l         S U l        g N)rc   r;   rd   r   )r   rc   r;   rd   s       r   __init__Leaf.__init__(  s+    
	 #	 +/	r   c                 2    U R                   U R                  4$ r   r|   r}   r:   s    r   r;   Leaf.start_pos8  s    yy$++%%r   c                 ,    US   U l         US   U l        g )Nr   r    r   r   rc   s     r   r;   r   <  s    !H	Ahr   c                     U R                  5       nUc2  [        U R                  5      nU R                  [	        U5      -
  S-   S4$ UR
                  $ )Nr    r   )r2   r	   rd   r|   r5   r?   )r   previous_leafliness      r   rB   Leaf.get_start_pos_of_prefixA  sM    ..0 ,E99s5z)A-q00$$$r   c                     U $ r   r9   r:   s    r   rE   Leaf.get_first_leafI      r   c                     U $ r   r9   r:   s    r   rH   Leaf.get_last_leafL  r   r   c                 Z    U(       a  U R                   U R                  -   $ U R                  $ r   )rd   rc   rK   s     r   rM   Leaf.get_codeO  s"    ;;++::r   c                     [        U R                  5      nU R                  [        U5      -   S-
  nU R                  U:X  a  U R                  [        US   5      -   nX#4$ [        US   5      nX#4$ )Nr    r-   )r	   rc   r|   r5   r}   )r   r   end_pos_lineend_pos_columns       r   r?   Leaf.end_posU  sl    DJJ'yy3u:-199$![[3uRy>9N ++ !r^N++r   c                 |    U R                   nU(       d  U R                  nS[        U 5      R                  < SU< S3$ )N<: >)rc   r   r]   r   s     r   __repr__Leaf.__repr__`  s-    

IIE!$Z00%88r   )r}   r|   r   rd   r;   rc   rT   rs   )r]   rt   ru   rv   rw   rx   ro   ry   r   rn   r   propertyr;   setterrB   rE   rH   rM   r?   r   rz   r9   r   r   r_   r_      s     6IKc eCHo s TX   &5c? & & uS#X 4  % ,sCx , ,9r   r_   c                   0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )rb   ig  r   c                 2   > [         TU ]  X#U5        Xl        g r   superr   r   )r   r   rc   r;   rd   	__class__s        r   r   TypedLeaf.__init__j  s    62	r   r   )r]   rt   ru   rv   rx   r   rz   __classcell__r   s   @r   rb   rb   g  s    I r   rb   c                       \ rS rSrSrSrS\\   SS4S jr\	S\
\\4   4S j5       rS	 r\	S\
\\4   4S
 j5       rS rSS jrSS jrS rS rS rSrg)re   io  zX
The super class for all nodes.
A node has children, a type and possibly a parent node.
)r"   r"   r   Nc                 @    Xl          S U l         U H	  nXl        M     g r   r"   r   )r   r"   r&   s      r   r   BaseNode.__init__v  s+     	 +/	 EL r   c                 4    U R                   S   R                  $ Nr   )r"   r;   r:   s    r   r;   BaseNode.start_pos  s    }}Q)))r   c                 <    U R                   S   R                  5       $ r   )r"   rB   r:   s    r   rB    BaseNode.get_start_pos_of_prefix  s    }}Q7799r   c                 4    U R                   S   R                  $ Nr-   )r"   r?   r:   s    r   r?   BaseNode.end_pos  s    }}R (((r   c                     U(       a  SR                  S U 5       5      $ US   R                  SS9nUSR                  S USS   5       5      -   $ )NrT   c              3   @   #    U  H  oR                  5       v   M     g 7fr   rM   .0r1   s     r   	<genexpr>2BaseNode._get_code_for_children.<locals>.<genexpr>  s     :A::<<   r   F)rL   c              3   @   #    U  H  oR                  5       v   M     g 7fr   r   r   s     r   r   r     s     "FA::<<r   r    )joinrM   )r   r"   rL   firsts       r   _get_code_for_childrenBaseNode._get_code_for_children  sQ    77::::QK(((>E277"F!""FFFFr   c                 :    U R                  U R                  U5      $ r   )r   r"   rK   s     r   rM   BaseNode.get_code  s    **4==.IIr   c                    ^ ^^^ UUUU 4S jmSTs=::  a  T R                   S   R                  ::  d  O  [        S5      eT" S[        T R                   5      S-
  5      $ )aH  
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                 ,  > X:X  a:  TR                   U    nT(       d  TUR                  :  a  g  UR                  TT5      $ [	        X-   S-  5      nTR                   U   nTUR
                  ::  a  T" X5      $ T" US-   U5      $ ! [         a    Us $ f = f)N   r    )r"   r;   get_leaf_for_positionr/   rn   r?   )lowerupperelementr.   binary_searchinclude_prefixespositionr   s       r   r   5BaseNode.get_leaf_for_position.<locals>.binary_search  s    ~--.'Hw7H7H,H#"88CSTT !+,EmmE*G7??*$U22$UQY66 & #"N#s   B BB)r    r   r-   z7Please provide a position that exists within this node.r   r    )r"   r?   
ValueErrorr5   )r   r   r   r   s   ```@r   r   BaseNode.get_leaf_for_position  sR    	7 	7& (?dmmB&7&?&??VWWQDMM 2Q 677r   c                 <    U R                   S   R                  5       $ r   )r"   rE   r:   s    r   rE   BaseNode.get_first_leaf  s    }}Q..00r   c                 <    U R                   S   R                  5       $ r   )r"   rH   r:   s    r   rH   BaseNode.get_last_leaf  s    }}R ..00r   c           	          U R                  5       R                  SS5      R                  SS5      R                  5       nS[        U 5      R                  < SU< SU R
                  S   < SU R
                  S	   < S
3	$ )Nr\   rU   r   r   @r   ,r    r   )rM   replacestripr   r]   r;   )r   codes     r   r   BaseNode.__repr__  sa    }}&&tS199$DJJL$Z  $q(94>>!;LN 	Nr   r   rs   )F)r]   rt   ru   rv   rw   rx   r   r   r   r   r   rn   r;   rB   r?   r   rM   r   rE   rH   r   rz   r9   r   r   re   re   o  s     I j!1  d   *5c? * *: )sCx ) )GJ8@11Nr   re   c                   6   ^  \ rS rSrSrSrU 4S jrS rSrU =r	$ )rf   i  z+Concrete implementation for interior nodes.r   c                 0   > [         TU ]  U5        Xl        g r   r   )r   r   r"   r   s      r   r   Node.__init__  s    "	r   c                 n    U R                   R                  < SU R                  < SU R                  < S3$ )NrX   rY   rZ   )r   r]   r   r"   r:   s    r   r   Node.__repr__  s!    #~~66		4==QQr   )
r]   rt   ru   rv   rw   rx   r   r   rz   r   r   s   @r   rf   rf     s    5IR Rr   rf   c                        \ rS rSrSrSrSrSrg)	ErrorNodei  z
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.
r9   
error_nodeN)r]   rt   ru   rv   rw   rx   r   rz   r9   r   r   r   r     s    
 IDr   r   c                   >   ^  \ rS rSrSrSrSrSU 4S jjrS rSr	U =r
$ )r`   i  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`.
)ra   
error_leafc                 2   > [         TU ]  X#U5        Xl        g r   )r   r   ra   )r   ra   rc   r;   rd   r   s        r   r   ErrorLeaf.__init__  s    62$r   c           	          S[        U 5      R                  < SU R                  < S[        U R                  5      < SU R
                  < S3	$ )Nr   r   :rY   r   )r   r]   ra   reprrc   r;   r:   s    r   r   ErrorLeaf.__repr__  s2    $Z  $//4

3CT^^U 	Ur   r   )r]   rt   ru   rv   rw   rx   r   r   r   rz   r   r   s   @r   r`   r`     s%      ID%U Ur   r`   N)abcr   r   typingr   r   r   r   parso.utilsr	   ro   r   r   r_   rb   re   rf   r   r`   r9   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   