bBFj>ddlmZmZddlmZmZmZmZddlm Z ddde ddfd Z Gd dZ Gd d e Z Gd de ZGdde ZGddeZGddeZGdde ZdS))abstractmethodabstractproperty)ListOptionalTupleUnion) split_linesnode NodeOrLeaf node_typesreturnOptional[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 8C:\PYTHON\_runtimes\venv\Lib\site-packages\parso/tree.pyrrs 4  ,,cBeZdZUdZdZeed< ded< dZdZdZ d Z d Z e d e eeffd Ze d e eeffd ZedZedZedZeddZded dfdZdddeeeefd efdZdS)r z. The base class for nodes and leaves. parenttyperrc4|}|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' l&LEl& rc|j}|dSt|jD]3\}}||ur* |jj|dzcS#t$rYdSwxYw4dS)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_sibling-s  >4"&/22  HAu}} ;/A6666!   444   sA AAc|j}|dSt|jD])\}}||ur |dkrdS|jj|dz cS*dS)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)rrrr s rget_previous_siblingzNodeOrLeaf.get_previous_sibling>sv  >4"&/22 3 3HAu}}6644{+AE2222 3 3rc|jdS|} |jj}||}|dkr|j}|jdSn ||dz }nE |jd}n#t$r|cYSwxYw")z Returns the previous leaf in the parser tree. Returns `None` if this is the first element in the parser tree. NTrr)rrindexAttributeErrorrr cr!s rget_previous_leafzNodeOrLeaf.get_previous_leafOs ; 4  $A AAvv{;&4'Qx   }R(!      s A"" A10A1c |jdS|} |jj}||}|t|dz kr|j}|jdSn ||dz}nU |jd}n#t$r|cYSwxYw")z Returns the next leaf in the parser tree. Returns None if this is the last element in the parser tree. NTrr)rrr(lenr)r*s r get_next_leafzNodeOrLeaf.get_next_leafis ; 4  $A ACFFQJ{;&4'Qx   }Q'!      s$ A22 BBr cdS)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_posrcdS)z Returns the end position of the prefix as a tuple, e.g. `(3, 4)`. :return tuple of int: (line, column) Nr1r2s rend_poszNodeOrLeaf.end_posr4rcdS)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) Nr1r2s rget_start_pos_of_prefixz"NodeOrLeaf.get_start_pos_of_prefixr4rcdS)zO Returns the first leaf of a node or itself if this is a leaf. Nr1r2s rget_first_leafzNodeOrLeaf.get_first_leafr4rcdS)zN Returns the last leaf of a node or itself if this is a leaf. Nr1r2s r get_last_leafzNodeOrLeaf.get_last_leafr4rTcdS)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. Nr1rinclude_prefixs rget_codezNodeOrLeaf.get_coder4rr c@|j}||j|vr|S|j}|dS)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)rr)rr r s rrzNodeOrLeaf.search_ancestors9{yJ&& ;Dtr)indentrCc |ddnIt|trdd|zn,t|trd|ntd|d dtdtd t 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)), ]) NFT z,expect 'indent' to be int, str or None, got r rC top_levelr cd}t|j}t|tr}|||dz }t|tr||jdz }n"t|t r ||jdz }||jd|jz }|j r |d|j z }|dz }nt|tr_|||dz }t|tr ||jdz }|dz }r|dz }|j D]}|||zd z }||d z }ntd ||s r|d z }n|dz }|S) NrE(, z , prefix=)[ F)rCrGz])zunsupported node encountered: z, )r__name__ isinstanceLeaf ErrorLeaf token_type TypedLeafvaluer3prefixBaseNodeNoder TypeError) r rCrGresult node_typer" _format_dump indent_stringnewlines rr[z%NodeOrLeaf.dump.._format_dumpsFT +I$%% KV1Y1111dI..16666FFi0010000FTZ??T^???;:9$+999F# D(++ KV1Y1111dD))10000F# #dNF!]bbEll5-9O[`aaaaFFV---'  I I IJJJ ##eOFFdNFMr)rET)rOintstrrXr bool)rrCr[r\r]s @@@rdumpzNodeOrLeaf.dumpsL >GMM  $ $ WG&LMM  $ $ WG"MMU6UUVV V" " z" 3" " X[" " " " " " " " H|D!!!rNT)rN __module__ __qualname____doc__ __slots__r___annotations__rr#r%r,r/rrr^r3r6rr8r:r<r@rrrrar1rrr r sI III !       "333"44 5c?     sCx      ^   ^   ^    ^  3 3G    ;<V"V"V"huS#X7V"V"V"V"V"V"V"rc eZdZUdZdZeed<ddedeeefdeddfd Z e deeeffd Z e j deeefddfd Z d Z d ZdZddZe deeeffdZdZdS)rPz Leafs are basically tokens with a better API. Leafs exactly know where they were defined and what text preceeds them. )rTlinecolumnrUrUrErTr3r NcB||_ ||_||_ d|_dSN)rTr3rUr)rrTr3rUs r__init__z Leaf.__init__#s6  #  +/   rc|j|jfSrlrirjr2s rr3zLeaf.start_pos3sy$+%%rc:|d|_|d|_dS)NrrrorrTs rr3zLeaf.start_pos7s!H Ah rc|}|0t|j}|jt |z dzdfS|jS)Nrr)r,r rUrir.r6)r previous_leafliness rr8zLeaf.get_start_pos_of_prefix<sN..00   ,,E9s5zz)A-q0 0$$rc|Srlr1r2s rr:zLeaf.get_first_leafD rc|Srlr1r2s rr<zLeaf.get_last_leafGrvrTc2|r|j|jzS|jSrl)rUrTr>s rr@z Leaf.get_codeJs!  ;+ +: rct|j}|jt|zdz }|j|kr|jt|dz}nt|d}||fS)Nrr')r rTrir.rj)rrt end_pos_lineend_pos_columns rr6z Leaf.end_posPsgDJ''y3u::-1 9 $ $![3uRy>>9NN r^^N^++rcX|j}|s|j}dt|jd|dS)N<: >)rTrrNrqs r__repr__z Leaf.__repr__[s7  IE!$ZZ000%%%88rrErb)rNrcrdrerfr_rgrr^rmpropertyr3setterr8r:r<r@r6rr1rrrPrPsV6I KKK  c eCHo s TX    &5c?&&&X&uS#X4%%% ,sCx,,,X,99999rrPc$eZdZdZdfd ZxZS)rSrrEc\t|||||_dSrlsuperrmr)rrrTr3rU __class__s rrmzTypedLeaf.__init__es*  6222 rr)rNrcrdrfrm __classcell__rs@rrSrSbsBIrrSceZdZdZdZddZedeeeffdZ dZ edeeeffdZ d Z dd Z dd ZdZdZdZdS)rVzd The super class for all nodes. A node has children, a type and possibly a parent node. )rr Nc>||_ d|_ |D] }||_ dSrl)rr)rrr"s rrmzBaseNode.__init__qs@   +/    EELL  rc&|jdjSNr)rr3r2s rr3zBaseNode.start_pos~s}Q))rc@|jdSr)rr8r2s rr8z BaseNode.get_start_pos_of_prefixs}Q77999rc&|jdjSNr')rr6r2s rr6zBaseNode.end_poss}R ((rc|rdd|DS|dd}|dd|ddDzS)NrEc3>K|]}|VdSrlr@.0r+s r z2BaseNode._get_code_for_children..s*::A1::<<::::::rrF)r?c3>K|]}|VdSrlrrs rrz2BaseNode._get_code_for_children..s*"F"FA1::<<"F"F"F"F"F"Frr)joinr@)rrr?firsts r_get_code_for_childrenzBaseNode._get_code_for_childrenst  G77::::::: :QK(((>>E277"F"F!"""F"F"FFFF FrTc8||j|Srl)rrr>s rr@zBaseNode.get_codes**4=.IIIrFcfddcxkrjdjksntddtjdz 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*||krEj|}s |jkrdS |S#t$r|cYSwxYwt ||zdz }j|}|jkr ||S|dz|S)Nr)rr3get_leaf_for_positionr)r^r6)lowerupperelementr( binary_searchinclude_prefixespositionrs rrz5BaseNode.get_leaf_for_position..binary_searchs~~-.' Hw7H,H,H4#"88CSTTT%###"NNN#!+,,EmE*G7?**$}UE222$}UQY666s; A  A )rrr'z7Please provide a position that exists within this node.rr)rr6 ValueErrorr.)rrrrs```@rrzBaseNode.get_leaf_for_positions 7 7 7 7 7 7 7 7&(????dmB&7&?????VWW W}QDM 2 2Q 6777rc@|jdSr)rr:r2s rr:zBaseNode.get_first_leafs}Q..000rc@|jdSr)rr<r2s rr<zBaseNode.get_last_leafs}R ..000rc  |dddd}dt|jd|d|jdd|jd d S) NrMrF r}r~@r,rr)r@replacestriprrNr3)rcodes rrzBaseNode.__repr__s}}&&tS1199$DDJJLL $ZZ $$$q(9(9(94>!;L;L;LN Nr)r Nrb)F)rNrcrdrerfrmrrr^r3r8r6rr@rr:r<rr1rrrVrVjsI     *5c?***X*:::)sCx)))X)GGGJJJJ8888@111111NNNNNrrVc,eZdZdZdZfdZdZxZS)rWz+Concrete implementation for interior nodes.rcXt|||_dSrlr)rrrrs rrmz Node.__init__s& """ rc@|jjd|jd|jdS)NrIrJrK)rrNrrr2s rrz Node.__repr__s&#~666 4===QQr)rNrcrdrerfrmrrrs@rrWrWsY55IRRRRRRRrrWceZdZdZdZdZdS) 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)rNrcrdrerfrr1rrrrs$ I DDDrrc2eZdZdZdZdZdfd ZdZxZS)rQz 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_leafrEc\t|||||_dSrl)rrmrR)rrRrTr3rUrs rrmzErrorLeaf.__init__s*  6222$rc |dt|jd|jdt|jd|jd S)Nr}r~:rJr)rrNrRreprrTr3r2s rrzErrorLeaf.__repr__sD $ZZ $///4 3C3C3C3CT^^^U Urr) rNrcrdrerfrrmrrrs@rrQrQsi I D%%%%%%UUUUUUUrrQN)abcrrtypingrrrr parso.utilsr r_rr rPrSrVrWrrQr1rrrs00000000////////////###### -, -S -=Q - - - -D"D"D"D"D"D"D"D"ND9D9D9D9D9:D9D9D9NRNRNRNRNRNzRNRNRNj R R R R R8 R R RUUUUUUUUUUr