a
    zeM                     @   s  d dl Z ed\ZZZZZe de je j	B j
Ze de jjZe de je jB jZe de jjZe de jjZe de jjZG d	d
 d
eZeeddZedd dD  edd dD  edd dD  G dd dZedkrd dlmZ eddd dS )    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                   @   s   e Zd Zdd ZdS )ParseMapc                 C   s   dS )Nx    )selfkeyr   r   %/usr/lib/python3.9/idlelib/pyparse.py__missing__r   s    zParseMap.__missing__N)__name__
__module____qualname__r	   r   r   r   r   r   f   s   r      r   c                 c   s   | ]}t |t d fV  qdS )(Nord.0cr   r   r   	<genexpr>x       r   z({[c                 c   s   | ]}t |t d fV  qdS ))Nr   r   r   r   r   r   y   r   z)}]c                 c   s   | ]}t |t |fV  qd S Nr   r   r   r   r   r   z   r   z"'\
#c                   @   s|   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd ZdS )Parserc                 C   s   || _ || _d S r   )indentwidthtabwidth)r   r   r   r   r   r   __init__   s    zParser.__init__c                 C   s   || _ d| _d S Nr   )codestudy_level)r   sr   r   r   set_code   s    zParser.set_codec           	      C   s   | j d  }}t|}tdD ]\}|dd|}|dk r: qz|dd|d }t|||}|rt|| st| } qz|}q|d u rt|}|r|| s| }|S |d }t|| }r| \}}||s|}q|S )Nr   z:
r   
   )r   lenrangerfind_synchrestartspan)	r   Zis_char_in_stringr   poslimitZtriesimr   r   r   r   find_good_parse_start   s.    	zParser.find_good_parse_startc                 C   s   |dkr| j |d  | _ d S r   )r   )r   lor   r   r   set_lo   s    zParser.set_loc                 C   s  | j dkrd S d| _ | j}|t}|dd}|dd}|dd}|dd}|dd}t}d }}dg | _}|j}dt| }}||k rd|| }	|d }|	dkrq|	dkr|d }|dkr|| q|	d	kr|d }q|	d
kr|r|d }q|	dks|	dkr|	}
||d |d  |
d kr8|
d }
|}t|
d }|| }||k r || }	|d }|	dkrxqP||d ||  |
kr|| }q|	dkr|d }|dkrP|dkr|| qqP|	dkrP|| dkr|d }|d }qPqP|d |krt	}qt
}q|	dkr2|d|}q|| dkrZ|d }|d |krZt}|d }q|t	kr|t
kr|dkrt}|| _|d |kr|| d S )Nr"   ZxxxxxxxxxZxxxxxxz
xr!   r   r   r   "'      \#)r   r   	translatetransreplaceC_NONE	goodlinesappendr#   C_STRING_FIRST_LINEC_STRING_NEXT_LINESfindC_BACKSLASH	C_BRACKETcontinuation)r   r   rD   levellnor=   Z	push_goodr+   nchquoteZfirstlnowr   r   r   _study1   s    











zParser._study1c                 C   s   |    | jS r   )rK   rD   r   r   r   r   get_continuation_typeK  s    zParser.get_continuation_typec                 C   s  | j dkrd S |   d| _ | j| j }}t|d }t|}|r|}t||d  || D ]}|dd|d d }q\t||r|d }q>qq>|dkr|}|| | _| _	d}g }|j
}	|dfg}
||k rht|||}|r4| }|d }||kr|| dv r|d }q||kr"|| }|}||kr4qh|| }|dv rn|	| |

|t|f |}|d }q|dv r|r|d	= |}|d }|

|t|f q|d
ks|dkr|

|t|d f |}t||| }|

|t|f q|dkr<|

|t|d f |d||d }|

|t|f q|d }|| dkr^|||  }|d }q|| _|r||d	 nd | _t|
| _d S )Nr4   r"   r!   r     	
([{)]}r8   r2   r3   r7   )r   rK   r   r=   r#   r$   r%   _junkre
stmt_startstmt_endr>   _chew_ordinaryreend_match_stringrerA   lastchlastopenbracketpostuplestmt_bracketing)r   r   r=   r+   pqZnothingrX   stackZ
push_stackZ
bracketingr,   ZnewprH   r   r   r   _study2O  s    











zParser._study2c                 C   s   |    | j}| j}t|}|dd|d  }}|d }||k rzt||}|rd| d }d}qq:|d|d  }}q:| }}|| dv r|d }q| j}t||| 	| j
| S )Nr!   r   r"    	)r_   rY   r   r#   r%   _itemrerV   rA   r   
expandtabsr   )r   jr   rG   Zorigir+   r,   extrar   r   r   compute_bracket_indent  s$    

zParser.compute_bracket_indentc                 C   s   |    | j}|d |d  S )Nr8   )rK   r=   )r   r=   r   r   r   get_num_lines_in_stmt  s    zParser.get_num_lines_in_stmtc                 C   s|  |    | j}| j}|| dv r*|d }q|}|d|d }d }}||k r|| }|dv rr|d }|d }qF|dv r|r|d }|d }qF|dks|dkrt||| }qF|d	krqqF|dkr
|d
kr
|dks||d  dvr
||d  d
kr
d}qqF|d }qF|r:|d }td||| d u }|s^|}|| dvr^|d }qDt|| j| 	| j
d S )Nr`   r"   r!   r   rP   rQ   r2   r3   r7   =z=<>!z\s*\\rO   )r_   r   rS   rA   rW   rV   rematchr#   rb   r   )r   r   r+   startposendposfoundrE   rH   r   r   r   compute_backslash_indent  sV    




zParser.compute_backslash_indentc                 C   sJ   |    | j| j }}|}| j}||k r>|| dv r>|d }q ||| S )Nr`   r"   )r_   rS   rT   r   )r   r+   rG   rc   r   r   r   r   get_base_indent_string,  s    
zParser.get_base_indent_stringc                 C   s   |    | jdkS )N:)r_   rX   rL   r   r   r   is_block_opener8  s    zParser.is_block_openerc                 C   s   |    t| j| jd uS r   )r_   _closerer   rS   rL   r   r   r   is_block_closer=  s    zParser.is_block_closerc                 C   s   |    | jS r   )r_   r[   rL   r   r   r   get_last_stmt_bracketingB  s    zParser.get_last_stmt_bracketingN)r
   r   r   r   r    r-   r/   rK   rM   r_   re   rg   rn   ro   rq   rs   rt   r   r   r   r   r   }   s   4	 {
9r   __main__)mainzidlelib.idle_test.test_pyparser4   )	verbosity)ri   r$   r<   rB   r?   r@   rC   compileVERBOSE	MULTILINEsearchr&   rj   rR   DOTALLrW   ra   rr   rU   dictr   fromkeysr:   updater   r
   Zunittestrv   r   r   r   r   <module>   sB   
	
	   Q
