B „ fS2ã@sœdZddlmZddlZddlmZeejejdƒZ eejdƒZ dd„e dƒDƒZ d d„e dƒDƒZ Gd d „d ƒZed kr˜dd lmZeddd�dS)zîProvide advanced parsing abilities for ParenMatch and other extensions. HyperParser uses PyParser. PyParser mostly gives information on the proper indentation of code. HyperParser gives additional information on the structure of code. é)Ú iskeywordN)ÚpyparseÚ_cCsg|]}t|ƒtk‘qS©)ÚchrÚ_ASCII_ID_CHARS)Ú.0Úxrrú8/opt/alt/python37/lib64/python3.7/idlelib/hyperparser.pyú sr é€cCsg|]}t|ƒtk‘qSr)rÚ_ASCII_ID_FIRST_CHARS)rr rrr r sc@s\eZdZdd„Zdd„Zdd„Zdd„Zdd d „Zed ddhƒZ e dd„ƒZ dZ dd„Z dS)Ú HyperParserc sJ|ˆ_|jˆ_}t |j|j¡}dd„}|| |¡ƒ}|js¸xh|jD]^}t ||dƒ}t |ƒd} d|} |  |  | | ¡d¡|  | | ¡¡} | dk s¢|dkrFPqFW| | p²d¡nF| d |¡} | rÒ| d} nd } d|} |  |  | | ¡d¡| d¡|jdd …ˆ_| ˆ_| ¡ˆ_‡fd d „ttˆjƒƒDƒˆ_ˆ |¡dS)z;To initialize, analyze the surroundings of the given index.cSs tt|ƒƒS)N)ÚintÚfloat)Úindexrrr Ú index2line"sz(HyperParser.__init__..index2lineéz.0z%d.endz NrZconsolez1.0éþÿÿÿcs4g|],}|dko.ˆj|dˆj|ddk‘qS)rr)Ú bracketing)rÚi)Úselfrr r Ksz(HyperParser.__init__..)ÚeditwinÚtextrZParserZ indentwidthZtabwidthrZprompt_last_lineZnum_context_linesÚmaxÚreprZset_codeÚgetZfind_good_parse_startZ_build_char_in_string_funcZset_loZ tag_prevrangeÚcodeÚrawtextÚ stopatindexZget_last_stmt_bracketingrÚrangeÚlenÚisopenerÚ set_index) rrrrÚparserrZlnoÚcontextZstartatZ startatindexrZbodÚrr)rr Ú__init__s:         zHyperParser.__init__cCsÐt|jƒt|j ||j¡ƒ}|dkr2td|ƒ‚||_d|_x@|jt|jƒdkr~|j|jdd|jkr~|jd7_q@W|jt|jƒdkrÌ|j|jdd|jkrÌ|j |jdsÌ|jd7_dS)zgSet the index to which the functions relate. The index must be in the same statement. rz(Index %s precedes the analyzed statementrN) r!rrrrÚ ValueErrorÚindexinrawtextÚ indexbracketrr")rrr)rrr r#QszHyperParser.set_indexcCs&|j|jo$|j|j|jddkS)z2Is the index given to the HyperParser in a string?r)ú"ú')r"r*rr)rrrr Ú is_in_stringfs zHyperParser.is_in_stringcCs(|j|j p&|j|j|jddkS)z5Is the index given to the HyperParser in normal code?r)ú#r+r,)r"r*rr)rrrr Ú is_in_codenszHyperParser.is_in_codeú([{FcCsL|j|jd}|j}x`|j|rL|j|j|d|ksL|j|d|krv|d8}|dkr`dSt||j|dƒ}qW|jd}x,|t|jƒkr®|j|d|kr®|d7}q„W|j d|jt|jƒ|j|df¡}|t|jƒk�s|j|dt|jƒk�r|�rdS|j}n.|j d|jt|jƒ|j|ddf¡}||fS)a¼Return bracket indexes or None. If the index given to the HyperParser is surrounded by a bracket defined in openers (or at least has one before it), return the indices of the opening bracket and the closing bracket (or the end of line, whichever comes first). If it is not surrounded by brackets, or the end of line comes before the closing bracket and mustclose is True, returns None. rrNz%s-%dc) rr*r"rÚminr!rrr)rZopenersZ mustcloseZbracketinglevelZbeforeZafterZ beforeindexZ afterindexrrr Úget_surrounding_bracketsts0    ""z$HyperParser.get_surrounding_bracketsÚTrueÚFalseÚNonecCsdt}|}x<||krDt||dƒdkrD|t||dƒrD|d8}q W||k�rt||dƒdk�rx0|d|kr–d||d|… ¡r–|d8}qhW|d|krÄd||d|… ¡rÄ|d8}|d|krðd||d|… ¡rð|d8}|||… ¡�s(dSn ||k�r(tt||ƒ�s(dS||k�r\t|||…ƒ�r\|||…|jk�r\dS||S)zÈGiven a string and pos, return the number of chars in the identifier which ends at pos, or 0 if there is no such one. This ignores non-identifier eywords are not identifiers. rr éÚaér)Ú_IS_ASCII_ID_CHARÚordÚ isidentifierÚ_IS_ASCII_ID_FIRST_CHARrÚ _ID_KEYWORDS)ÚclsÚstrÚlimitÚposZis_ascii_id_charrrrr Ú_eat_identifier¢s.   & $$  zHyperParser._eat_identifierz \c Csô| ¡stdƒ‚|j}|j}|j}||d}|j}|}d}�x¦x¢||krf||d|jkrf|d8}qB|s�||kr�||ddkr�|d8}d}qB||krÞ|dkrÞ|||dddkrÞ|d8}||d}||dd}qBPqBW|sêP| |||¡}|�r||}|}d}q@||k�rà||d} x.|dk�rT||dd| k�rT|d8}�q(W||d|k�rjP||d}|d8}||d}|}||d k�ržn@||d k�rÜx*|dk�rÖ||dd k�rÖ|d8}�q®W|}Pq@Pq@W|||j…S) z‚Return a string with the Python expression which ends at the given index, which is empty if there is no real one. z?get_expression should only be called if index is inside a code.rTrÚ.r.r8Fz([z'"ZrRbBuU)r/r(rrr*r)Ú_whitespace_charsrB) rrrZ brck_indexZ brck_limitrAZlast_identifier_posZ postdot_phaseZretÚlevelrrr Úget_expressionÞsb     "  zHyperParser.get_expressionN)r0F)Ú__name__Ú __module__Ú __qualname__r'r#r-r/r2Ú frozensetr=Ú classmethodrBrDrFrrrr rs7 , :rÚ__main__)Úmainz"idlelib.idle_test.test_hyperparserr8)Ú verbosity)Ú__doc__ÚkeywordrÚstringZidlelibrrJZ ascii_lettersZdigitsrr r r9r<rrGZunittestrMrrrr Ús