B � f�2�@s�ddlZddlZddlZddlZddlmZddlmZdZdd�Z dd�Z e� e �ej �Z e� d ej �Zd d �ZGd d �d e�Zdd�Zedkr�ddlmZedddd�ddlmZee�dS)�N)�idleConf)� DelegatorFcCsd|d�|�dS)z9Return a named group pattern matching list of alternates.z(?P<%s>�|�))�join)�nameZ alternates�r�6/opt/alt/python37/lib64/python3.7/idlelib/colorizer.py�any sr c Cs�dtdtj�d}dd�tt�D�}dtd|�d}tddg�}d }|d }|d }|d }|d }td||||g�} |d|d|d| dtddg�S)Nz\b�KEYWORDcSs(g|] }|�d�s|tjkrt|��qS)�_)� startswith�keyword�kwlist�str)�.0rrrr � s zmake_pat..z([^.'\"\\#]\b|^)�BUILTIN�COMMENTz#[^\n]*z(?i:r|u|f|fr|rf|b|br|rb)?z'[^'\\\n]*(\\.[^'\\\n]*)*'?z"[^"\\\n]*(\\.[^"\\\n]*)*"?z''''[^'\\]*((\\.|'(?!''))[^'\\]*)*(''')?z'"""[^"\\]*((\\.|"(?!""))[^"\\]*)*(""")?�STRINGr�SYNCz\n)r rr�dir�builtins) �kwZ builtinlist�builtin�commentZ stringprefixZsqstringZdqstringZ sq3stringZ dq3string�stringrrr �make_pats rz\s+(\w+)cCs^t��}t�|d�}t�|d�d}t�|d�}|j|d|d||d|d|dd�dS)zcSet color options of Text widget. If ColorDelegator is used, this should be called first. ZnormalZcursor� foregroundZhilite� background)rrZinsertbackgroundZselectforegroundZselectbackgroundZinactiveselectbackgroundN)r� CurrentTheme� GetHighlightZconfig)�text�themeZ normal_colorsZ cursor_colorZ select_colorsrrr � color_config"s  r$c@s�eZdZdZdd�Zdd�Zdd�Zdd �Zd d �Zdd d�Z ddd�Z ddd�Z dd�Z d dd�Z dd�Zdd�Zdd�Zd S)!�ColorDelegatora-Delegator for syntax highlighting (text coloring). Instance variables: delegate: Delegator below this one in the stack, meaning the one this one delegates to. Used to track state: after_id: Identifier for scheduled after event, which is a timer for colorizing the text. allow_colorizing: Boolean toggle for applying colorizing. colorizing: Boolean flag when colorizing is in process. stop_colorizing: Boolean flag to end an active colorizing process. cCs*t�|�|��t|_t|_|��dS)N)r�__init__� init_state�prog�idprog� LoadTagDefs)�selfrrr r&Gs  zColorDelegator.__init__cCsd|_d|_d|_d|_dS)z1Initialize variables that track colorizing state.NTF)�after_id�allow_colorizing�stop_colorizing� colorizing)r+rrr r'NszColorDelegator.init_statecCs\|jdk r|�d�t�||�|dk rL|��|�d|j�|�dd�n d|_d|_ dS)a�Set the delegate for this instance. A delegate is an instance of a Delegator class and each delegate points to the next delegator in the stack. This allows multiple delegators to be chained together for a widget. The bottom delegate for a colorizer is a Text widget. If there is a delegate, also start the colorizing process. Nz<>z1.0�endTF) �delegateZunbindr� setdelegate� config_colorsZbind�toggle_colorize_event� notify_ranger.r-)r+r1rrr r2Us   zColorDelegator.setdelegatecCs4x$|j��D]\}}|j|f|�q W|�d�dS)z4Configure text widget tags with colors from tagdefs.ZselN)�tagdefs�itemsZ tag_configureZ tag_raise)r+�tagZcnfrrr r3lszColorDelegator.config_colorsc Cszt��}t�|d�t�|d�t�|d�t�|d�t�|d�ddd�ddd�t�|d�t�|d �d � |_trvtd |j�dS) z.Create dictionary of tag names to text colors.rrrrZ definitionN)rr�error�hit) rr rr� DEFINITIONr�TODOZERRORr:r6)rr r!r6�DEBUG�print)r+r#rrr r*rs      zColorDelegator.LoadTagDefsNcCs6|�|�}|j�|||�|�||dt|��dS)z:Insert chars into widget at index and mark for colorizing.z+%dcN)�indexr1�insertr5�len)r+r?�charsZtagsrrr r@�s zColorDelegator.insertcCs&|�|�}|j�||�|�|�dS)z5Delete chars between indexes and mark for colorizing.N)r?r1�deleter5)r+�index1�index2rrr rC�s zColorDelegator.deletecCsb|�d||�|jr$tr td�dS|jrr/r.r-�after� recolorize)r+rDrErrr r5�szColorDelegator.notify_rangecCs8|jr(|j}d|_trtd�|�|�d|_d|_dS)Nzcancel scheduled recolorizerFT)r,r=r>� after_cancelr-r.)r+r,rrr �close�s zColorDelegator.closecCs�|jr(|j}d|_trtd�|�|�|jrF|jrFtr@td�d|_|j |_|jrl|jsl|�d|j�|_tr�td|jr~dp�d�d S) z�Toggle colorizing on and off. When toggling off, if colorizing is scheduled or is in process, it will be cancelled and/or stopped. When toggling on, colorizing will be scheduled. Nzcancel scheduled recolorizerzstop colorizingTrFzauto colorizing turnedZonZoff�break) r,r=r>rJr-r/r.rHrI)r+Zeventr,rrr r4�s"    z$ColorDelegator.toggle_colorize_eventcCs�d|_|jstrtd�dS|js2tr.td�dS|jrHtrDtd�dSzHd|_d|_trbtd�t��}|� �t��}tr�td||�Wdd|_X|jr�|� d d �r�tr�td �|� d |j �|_dS) aSTimer event (every 1ms) to colorize text. Colorizing is only attempted when the text widget exists, when colorizing is toggled on, and when the colorizing process is not already running. After colorizing is complete, some cleanup is done to make sure that all the text has been colorized. Nz no delegatezauto colorizing is offzalready colorizingFTz colorizing...z %.3f secondsr<z1.0zreschedule colorizingrF) r,r1r=r>r-r/r.�timeZ perf_counter�recolorize_main� tag_nextrangerHrI)r+Zt0Zt1rrr rI�s8 zColorDelegator.recolorizecCs�d}�x�|�d|�}|sP|\}}|�d||�|�d|�}|rJ|d}nd}d}|}d}d}�x�|�s�|}|�|d|�}t|dd �}d|�|d �k}|�||�} | s�d Sx|jD]} |�| ||�q�W|| }|j� |�} x�| �r�x�| � �� �D]~\} } | r�| � | �\}}|� | |d ||d |�| d kr�|j�||�}|r�|� d�\}}|� d|d ||d |�q�W|j� || ���} q�Wd|�|d �k�r�|}d}nd}|�s�|� d|�|��|jrbt�r�td�d SqbWqWd S)z(Evaluate text and apply colorizing tags.z1.0r<rrF�Fz+%d lines linestart��dz-1cNz+%dc)�def�classr;zcolorizing stopped)rO� tag_removeZ tag_prevranger?�minZ tag_names�getr6r(�search� groupdictr7�spanrGr)�matchr0�updater.r=r>)r+�next�item�head�tailrBZ lines_to_get�okZmark�liner8�m�key�value�a�bZm1rrr rN�sl           zColorDelegator.recolorize_maincCs"x|jD]}|�|dd�qWdS)zRemove all colorizing tags.z1.0r0N)r6rU)r+r8rrr � removecolors#s zColorDelegator.removecolors)N)N)N)N)�__name__� __module__� __qualname__�__doc__r&r'r2r3r*r@rCr5rKr4rIrNrhrrrr r%7s    "Br%c Cs�ddlm}m}ddlm}||�}|�d�tt|��� d�dd��\}}|�d|d|d f�d }||d d �}|j dd d�|� d|�|� �t |�||�} t�} | �| �dS)Nr)�Toplevel�Text)� PercolatorzTest ColorDelegator�+rFz 700x250+%d+%d��abif True: int ('1') # keyword, builtin, string, comment elif False: print(0) else: float(None) if iF + If + IF: 'keyword matching must respect case' if'': x or'' # valid string-keyword no-space combinations async def f(): await g() # All valid prefixes for unicode and byte strings should be colored. 'x', '''x''', "x", """x""" r'x', u'x', R'x', U'x', f'x', F'x' fr'x', Fr'x', fR'x', FR'x', rf'x', rF'x', Rf'x', RF'x' b'x',B'x', br'x',Br'x',bR'x',BR'x', rb'x', rB'x',Rb'x',RB'x' # Invalid combinations of legal characters should be half colored. ur'x', ru'x', uf'x', fu'x', UR'x', ufr'x', rfu'x', xf'x', fx'x' Zwhite)rZboth)�expandZfillr@)ZtkinterrmrnZidlelib.percolatorro�title�map�intZgeometry�splitZpackr@Z focus_setr$r%Z insertfilter) �parentrmrnro�top�x�y�sourcer"�p�drrr �_color_delegator)s     r�__main__)�mainz idlelib.idle_test.test_colorizerrQ)� verbosity�exit)�run)rr�rerMZidlelib.configrZidlelib.delegatorrr=r r�compile�Sr(r)r$r%rriZunittestr�Zidlelib.idle_test.htestr�rrrr �s&  s"