B „ fëMã@sdZddlZedƒ\ZZZZZe dej ej B¡j Z e dej ¡j Ze dej ejB¡j Ze dej ¡j Ze dej ¡j Ze d ej ¡j ZGd d „d eƒZe ed ƒd ¡Ze dd„dDƒ¡e dd„dDƒ¡e dd„dDƒ¡Gdd„dƒZedk�rddlmZeddd�dS)aÄDefine partial Python code Parser used by editor and hyperparser. Instances of ParseMap are used with str.translate. The following bound search and match functions are defined: _synchre - start of popular statement; _junkre - whitespace or comment line; _match_stringre: string, possibly without closer; _itemre - line that may have bracket structure start; _closere - line that must be followed by dedent. _chew_ordinaryre - non-special characters. éNézä ^ [ \t]* (?: while | else | def | return | assert | break | class | continue | elif | try | except | raise | import | yield ) \b z' [ \t]* (?: \# \S .* )? \n aK \""" [^"\\]* (?: (?: \\. | "(?!"") ) [^"\\]* )* (?: \""" )? | " [^"\\\n]* (?: \\. [^"\\\n]* )* "? | ''' [^'\\]* (?: (?: \\. | '(?!'') ) [^'\\]* )* (?: ''' )? | ' [^'\\\n]* (?: \\. [^'\\\n]* )* '? zM [ \t]* [^\s#\\] # if we match, m.end()-1 is the interesting char z_ \s* (?: return | break | continue | raise | pass ) \b z [^[\](){}#'"\\]+ c@seZdZdZdd„ZdS)ÚParseMapapDict subclass that maps anything not in dict to 'x'. This is designed to be used with str.translate in study1. Anything not specifically mapped otherwise becomes 'x'. Example: replace everything except whitespace with 'x'. >>> keepwhite = ParseMap((ord(c), ord(c)) for c in ' \t\n\r') >>> "a + b\tc\nd".translate(keepwhite) 'x x x\tx\nx' cCsdS)Néx©)ÚselfÚkeyrrú4/opt/alt/python37/lib64/python3.7/idlelib/pyparse.pyÚ __missing__rszParseMap.__missing__N)Ú__name__Ú __module__Ú __qualname__Ú__doc__r rrrrrfs ré€rccs|]}t|ƒtdƒfVqdS)ú(N)Úord)Ú.0Úcrrrú xsrz({[ccs|]}t|ƒtdƒfVqdS)ú)N)r)rrrrrrysz)}]ccs|]}t|ƒt|ƒfVqdS)N)r)rrrrrrzsz"'\ #c@s|eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„ZdS)ÚParsercCs||_||_dS)N)Ú indentwidthÚtabwidth)rrrrrrÚ__init__szParser.__init__cCs,t|ƒdks|ddkst‚||_d|_dS)NréÿÿÿÿÚ )ÚlenÚAssertionErrorÚcodeÚ study_level)rÚsrrrÚset_codeƒszParser.set_codec Csâ|jd}}t|ƒ}xdtdƒD]X}| dd|¡}|dkr:P| dd|¡d}t|||ƒ}|rr|| ¡ƒsr| ¡}P|}qW|dkr¦t|ƒ}|r¢|| ¡ƒs¢| ¡}|S|d}x.t||ƒ}|rØ| ¡\}}||ƒsÚ|}q°Pq°W|S)a^ Return index of a good place to begin parsing, as close to the end of the string as possible. This will be the start of some popular stmt like "if" or "def". Return None if none found: the caller should pass more prior context then, if possible, or if not (the entire program text up until the point of interest has already been tried) pass 0 to set_lo(). This will be reliable iff given a reliable is_char_in_string() function, meaning that when it says "no", it's absolutely guaranteed that the char is not in a string. Nrz: rré)rrÚrangeÚrfindÚ_synchreÚstartÚspan) rZis_char_in_stringrÚposÚlimitZtriesÚiÚmrrrrÚfind_good_parse_startˆs4     zParser.find_good_parse_startcCs:|dks|j|ddkst‚|dkr6|j|d…|_dS)zx Throw away the start of the string. Intended to be called with the result of find_good_parse_start(). rr!rN)rr)rÚlorrrÚset_loÀsz Parser.set_loc Cs|jdkrdSd|_|j}| t¡}| dd¡}| dd¡}| dd¡}| dd¡}| dd¡}t}d }}d g|_}|j}d t|ƒ}}�x||k�r¤||} |d}| dkr´q�| dkrÖ|d}|d kr�||ƒq�| d krè|d}q�| d k�r|r�|d}q�| d k�s| d k�r2| } ||d|d…| dk�r>| d} |} t| ƒd} || }xØ||k�r||} |d}| dk�r€�qX||d|| …| k�r¤|| }P| dk�rØ|d}| d k�rX|d k�rÒ||ƒP�qX| dk�rX||k�sðt ‚||dk�r|d}|d}�qX�qXW|d| k�r,t }q�t }q�| dk�rV|  d|¡}|d ks�t ‚q�| dk�sdt ‚||k�srt ‚||dk�rš|d}|d|k�ršt }|d}q�W|t k�rÈ|t k�rÈ|d k�rÈt}||_|tk|d|kk�sèt ‚|d|k�rþ||ƒdS)záFind the line numbers of non-continuation lines. As quickly as humanly possible , find the line numbers (0- based) of the non-continuation lines. Creates self.{goodlines, continuation}. r!NZxxxxxxxxÚxZxxxxZxxz xrrrrú"ú'ééú\ú#r)rrÚ translateÚtransÚreplaceÚC_NONEÚ goodlinesÚappendrrÚC_STRING_FIRST_LINEÚC_STRING_NEXT_LINESÚfindÚ C_BACKSLASHÚ C_BRACKETÚ continuation) rrr@ÚlevelZlnor9Z push_goodr)ÚnÚchZquoteZfirstlnoÚwrrrÚ_study1És¤                      zParser._study1cCs| ¡|jS)N)rEr@)rrrrÚget_continuation_typeOszParser.get_continuation_typecCsà|jdkrdS| ¡d|_|j|j}}t|ƒd}t|ƒ}x`|rž|sLt‚|}x4t||d||ƒD]}| dd|d¡d}qhWt||ƒrš|d}q@Pq@W|dkr¸|dks´t‚|}|||_ |_ d}g}|j } |dfg} �xÖ||k�r¶t |||ƒ} | �rX|   ¡} | d}x&||k�r4||dk�r4|d}�qW||k�rH||}| }||k�rXP||} | dk�r’| |ƒ|   |t|ƒf¡| }|d}qâ| d k�rÈ|�r¨|d =| }|d}|   |t|ƒf¡qâ| d k�sÜ| d k�r|   |t|ƒdf¡| }t|||ƒ  ¡}|   |t|ƒf¡qâ| d k�rn|   |t|ƒdf¡| d||¡d}|dk�sZt‚|   |t|ƒf¡qâ| dk�s|t‚|d}||k�s’t‚||dk�r¬| ||}|d}qâW||_|�rÌ|d nd|_t| ƒ|_dS)am study1 was sufficient to determine the continuation status, but doing more requires looking at every character. study2 does this for the last interesting statement in the block. Creates: self.stmt_start, stmt_end slice indices of last interesting stmt self.stmt_bracketing the bracketing structure of the last interesting stmt; for example, for the statement "say(boo) or die", stmt_bracketing will be ((0, 0), (0, 1), (2, 0), (2, 1), (4, 0)). Strings and comments are treated as brackets, for the matter. self.lastch last interesting character before optional trailing comment self.lastopenbracketpos if continuation is C_BRACKET, index of last open bracket r1Nr!rrÚz z([{z)]}rr/r0r4r3)rrErr9rrr"r#Ú_junkreÚ stmt_startÚstmt_endr:Ú_chew_ordinaryreÚendÚ_match_stringrer=ÚlastchÚlastopenbracketposÚtupleÚstmt_bracketing)rrr9r)ÚpÚqZnothingrNÚstackZ push_stackZ bracketingr*ZnewprCrrrÚ_study2SsŒ              zParser._study2cCsÐ| ¡|jtkst‚|j}|j}t|ƒ}| dd|¡d}}|d}xj||krŠt||ƒ}|rt|  ¡d}d}PqJ|  d|¡d}}qJW|}}x||dkr¬|d}q–W|j }t|||…  |j ¡ƒ|S)zpReturn number of spaces the next line should be indented. Line continuation must be C_BRACKET. rrr!z )rUr@r?rrOrrr#Ú_itemrerLr=rÚ expandtabsr)rÚjrrBZorigir)r*ZextrarrrÚcompute_bracket_indentÎs&    zParser.compute_bracket_indentcCs| ¡|j}|d|dS)zÃReturn number of physical lines in last stmt. The statement doesn't have to be an interesting statement. This is intended to be called when continuation is C_BACKSLASH. réþÿÿÿ)rEr9)rr9rrrÚget_num_lines_in_stmtíszParser.get_num_lines_in_stmtcCs”| ¡|jtkst‚|j}|j}x||dkr:|d}q$W|}| d|¡d}d}}xÎ||k�r&||}|dkr†|d}|d}qZ|dkr¤|rš|d}|d}qZ|dks´|dkrÆt|||ƒ ¡}qZ|d krÒPqZ|dk�r|d k�r|dk�s||dd k�r||dd k�rd}PqZ|d}qZW|�rN|d}t   d |||…¡d k}|�sv|}x||dk�rt|d}�qZWt ||j|…  |j ¡ƒdS)zÒReturn number of spaces the next line should be indented. Line continuation must be C_BACKSLASH. Also assume that the new line is the first one following the initial line of the stmt. z r!rrz([{z)]}r/r0r4ú=z=<>!z\s*\\Nz )rUr@r>rrrIr=rMrLÚreÚmatchrrWr)rrr)ÚstartposÚendposÚfoundrArCrrrÚcompute_backslash_indent÷sJ     zParser.compute_backslash_indentcCsN| ¡|j|j}}|}|j}x ||kr@||dkr@|d}q"W|||…S)z`Return the leading whitespace on the initial line of the last interesting stmt. z r!)rUrIrJr)rr)rBrXrrrrÚget_base_indent_string0s zParser.get_base_indent_stringcCs| ¡|jdkS)zr;r<r?ÚcompileÚVERBOSEÚ MULTILINEÚsearchr$r^rHÚDOTALLrMrVrfrKÚdictrÚfromkeysr6Úupdaterr ZunittestrjrrrrÚ s4    U