K i?ddlmZmZddlmZmZmZmZddlm Z ddde ddfd Z Gd dZ Gd d e Z Gd de ZGdde ZGddeZGddeZGdde Zy))abstractmethodabstractproperty)ListOptionalTupleUnion) split_linesnode NodeOrLeaf node_typesreturnOptional[BaseNode]c^|j}||j|vr|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. Nparenttype)r r ns P/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/parso/tree.pysearch_ancestorrs8 A - 66Z H HH - ceZdZUdZdZeed< ded< dZdZdZ d Z d Z e d e eeffd Ze d e eeffd ZedZedZedZeddZded dfdZdddeeeefd efdZy)r z. The base class for nodes and leaves. rrrrcT|}|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)selfscopes r get_root_nodezNodeOrLeaf.get_root_node(s- ll&LLEll& rc|j}|yt|jD](\}}||us |jj|dzcSy#t$rYywxYw)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 enumeratechildren IndexErrorrrichilds rget_next_siblingzNodeOrLeaf.get_next_sibling2sl  >"&//2 HAu} ;;//A66 "  sA AAc|j}|yt|jD].\}}||us |dk(ry|jj|dz cSy)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. Nrr)rrr r"s rget_previous_siblingzNodeOrLeaf.get_previous_siblingCs]  >"&//2 3HAu}6{{++AE22  3rc|jy|} |jj}|j|}|dk(r|j}|j y||dz }nO |jd}#t$r|cYSwxYw)z Returns the previous leaf in the parser tree. Returns `None` if this is the first element in the parser tree. Nrr)rr indexAttributeErrorrr cr#s rget_previous_leafzNodeOrLeaf.get_previous_leafTs ;;  $$A AAv{{;;&Qx }}R("   s"A22 B?Bc|jy|} |jj}|j|}|t|dz k(r|j}|j y||dz}n[ |jd}#t$r|cYSwxYw)z Returns the next leaf in the parser tree. Returns None if this is the last element in the parser tree. Nrr)rr r*lenr+r,s r get_next_leafzNodeOrLeaf.get_next_leafns ;;  $$A ACFQJ{{;;&Qx }}Q'"   s.A>> B  B r cy)z Returns the starting position of the prefix as a tuple, e.g. `(3, 4)`. :return tuple of int: (line, column) Nrs r start_poszNodeOrLeaf.start_posrcy)z Returns the end position of the prefix as a tuple, e.g. `(3, 4)`. :return tuple of int: (line, column) Nr3r4s rend_poszNodeOrLeaf.end_posr6rcy)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) Nr3r4s rget_start_pos_of_prefixz"NodeOrLeaf.get_start_pos_of_prefixr6rcy)zO Returns the first leaf of a node or itself if this is a leaf. Nr3r4s rget_first_leafzNodeOrLeaf.get_first_leafr6rcy)zN Returns the last leaf of a node or itself if this is a leaf. Nr3r4s r get_last_leafzNodeOrLeaf.get_last_leafr6rcy)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. Nr3rinclude_prefixs rget_codezNodeOrLeaf.get_coder6rr c^|j}||j|vr|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)rr r s rrzNodeOrLeaf.search_ancestors:{{yyJ& ;;Dr)indentrEc |ddn;t|trdd|zn#t|trd|ntd|d dtdtdt d tffd |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)), ]) FT z,expect 'indent' to be int, str or None, got r rE top_levelr cd}t|j}t|tr|||dz }t|tr||j dz }n"t|t r||jdz }||jd|jz }|jr|d|jz }|dz }nt|trc|||dz }t|tr||jdz }|dz }r|dz }|jD]}|||zd z }||d z }ntd ||sr|d z }|S|dz }|S) NrG(, z , prefix=)[ F)rErIz])zunsupported node encountered: z, )r__name__ isinstanceLeaf ErrorLeaf token_type TypedLeafvaluer5prefixBaseNodeNoder TypeError) r rErIresult node_typer$ _format_dump indent_stringnewlines rr]z%NodeOrLeaf.dump.._format_dumpsFT ++I$%VHYKq11dI. 3266Fi0 R00FTZZN"T^^,>??;; $++99F# D(+VHYKq11dD) R00F# dNF!]]bEl5-9O[`aaFbVHB-'  "@ IJJeOFMdNFMr)rGT)rQintstrrZr bool)rrEr]r^r_s @@@rdumpzNodeOrLeaf.dumpsL >GM  $G&LM  $G"MJ6*UV V" z" 3" " X[" HD!!rNT)rP __module__ __qualname____doc__ __slots__ra__annotations__rr%r'r.r1rrr`r5r8rr:r<r>rBrrrrcr3rrr r sI I !   "3"44 5c?   sCx           3 3G ;<V"huS#X7V"V"rc eZdZUdZdZeed<ddedeeefdeddfdZ e deeeffd Z e jdeeefddfd Z d Z d Zd ZddZe deeeffdZdZy)rRz Leafs are basically tokens with a better API. Leafs exactly know where they were defined and what text preceeds them. )rVlinecolumnrWrWrVr5r Nc@||_ ||_||_ d|_yN)rVr5rWr)rrVr5rWs r__init__z Leaf.__init__(s1  #  +/  rc2|j|jfSrnrkrlr4s rr5zLeaf.start_pos8syy$++%%rc,|d|_|d|_y)NrrrqrrVs rr5zLeaf.start_pos<s!H Ah rc|j}|2t|j}|jt |z dzdfS|j S)Nrr)r.r rWrkr0r8)r previous_leafliness rr:zLeaf.get_start_pos_of_prefixAsM..0   ,E99s5z)A-q0 0$$$rc|Srnr3r4s rr<zLeaf.get_first_leafI rc|Srnr3r4s rr>zLeaf.get_last_leafLrxrcP|r|j|jzS|jSrn)rWrVr@s rrBz Leaf.get_codeOs" ;;+ +:: rct|j}|jt|zdz }|j|k(r|jt|dz}||fSt|d}||fS)Nrr))r rVrkr0rl)rrv end_pos_lineend_pos_columns rr8z Leaf.end_posUspDJJ'yy3u:-1 99 $![[3uRy>9N^++!r^N^++rcn|j}|s |j}dt|jd|dS)N<: >)rVrrPrss r__repr__z Leaf.__repr__`s- IIE!$Z00%88rrGrd)rPrerfrgrhrarirr`ropropertyr5setterr:r<r>rBr8rr3rrrRrR s6I K c eCHo s TX &5c?&&uS#X4% ,sCx,,9rrRc$eZdZdZdfd ZxZS)rUrc6t||||||_yrnsuperror)rrrVr5rW __class__s rrozTypedLeaf.__init__js  62 rr)rPrerfrhro __classcell__rs@rrUrUgsIrrUceZdZdZdZdeeddfdZede e e ffdZ dZ ede e e ffd Z d Zdd Zdd Zd ZdZdZy)rXzd The super class for all nodes. A node has children, a type and possibly a parent node. )r r r Nc@||_ d|_ |D] }||_ yrn)r r)rr r$s rrozBaseNode.__init__vs4   +/   EEL rc4|jdjSNr)r r5r4s rr5zBaseNode.start_poss}}Q)))rc<|jdjSr)r r:r4s rr:z BaseNode.get_start_pos_of_prefixs}}Q7799rc4|jdjSNr))r r8r4s rr8zBaseNode.end_poss}}R (((rc|rdjd|DS|djd}|djd|ddDzS)NrGc3<K|]}|jywrnrB.0r-s r z2BaseNode._get_code_for_children..s:A1::<:rF)rAc3<K|]}|jywrnrrs rrz2BaseNode._get_code_for_children..s"FA1::<"Frr)joinrB)rr rAfirsts r_get_code_for_childrenzBaseNode._get_code_for_childrensQ 77::: :QK(((>E277"F!""FFF Frc:|j|j|Srn)rr r@s rrBzBaseNode.get_codes**4==.IIrcfddcxkr&jdjkstdtddtjdz 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(r4j|}s|jkry |jSt ||zdz }j|}|j kr ||S|dz|S#t$r|cYSwxYw)Nr)r r5get_leaf_for_positionr+r`r8)lowerupperelementr* binary_searchinclude_prefixespositionrs rrz5BaseNode.get_leaf_for_position..binary_searchs~--.'Hw7H7H,H#"88CSTT!+,EmmE*G7??*$UE22$UQY66&#"N#sA?? B  B )rrr)z7Please provide a position that exists within this node.rr)r r8 ValueErrorr0)rrrrs```@rrzBaseNode.get_leaf_for_positions_ 7&(?dmmB&7&?&??VW W@VW WQDMM 2Q 677rc<|jdjSr)r r<r4s rr<zBaseNode.get_first_leafs}}Q..00rc<|jdjSr)r r>r4s rr>zBaseNode.get_last_leafs}}R ..00rc |jjddjddj}dt|jd|d|j dd|j d d S) NrOrH rr@r,rr)rBreplacestriprrPr5)rcodes rrzBaseNode.__repr__sa}}&&tS199$DJJL $Z $q(94>>!;LN Nrrd)F)rPrerfrgrhrr rorrr`r5r:r8rrBrr<r>rr3rrrXrXosI  j!1  d  *5c?**:)sCx))GJ8@11NrrXc,eZdZdZdZfdZdZxZS)rYz+Concrete implementation for interior nodes.rc2t||||_yrnr)rrr rs rroz Node.__init__s " rch|jjd|jd|jdS)NrKrLrM)rrPrr r4s rrz Node.__repr__s!#~~66 4==QQr)rPrerfrgrhrorrrs@rrYrYs5IRrrYceZdZdZdZdZy) 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)rPrerfrgrhrr3rrrrs I Drrc2eZdZdZdZdZdfd ZdZxZS)rSz 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_leafc6t||||||_yrn)rrorT)rrTrVr5rWrs rrozErrorLeaf.__init__s  62$rc dt|jd|jdt|jd|j d S)Nrr:rLr)rrPrTreprrVr5r4s rrzErrorLeaf.__repr__s2 $Z $//4 3CT^^U Urr) rPrerfrgrhrrorrrs@rrSrSs I D%UrrSN)abcrrtypingrrrr parso.utilsr rarr rRrUrXrYrrSr3rrrs0//#,S=Q$D"D"ND9:D9NRNzRNj R8 RUUr