<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
B
    „ fÀ2  ã               @   sÄ   d dl Z d dlZd dlZd dlZd dlmZ d dlmZ dZdd„ Z	dd„ Z
e e
ƒ ej¡Ze d	ej¡Zd
d„ ZG dd„ deƒZdd„ ZedkrÀd dlmZ edddd d dlmZ eeƒ dS )é    N)ÚidleConf)Ú	DelegatorFc             C   s   d|  d  |¡ d S )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   s    r
   c        
      C   s¦   dt dtjƒ d } dd„ ttƒD ƒ}dt d|ƒ d }t ddgƒ}d	}|d
 }|d }|d }|d }t d||||gƒ}	| d | d | d |	 d t ddgƒ S )Nz\bÚKEYWORDc             S   s(   g | ] }|  d ¡s|tjkrt|ƒ‘qS )Ú_)Ú
startswithÚkeywordÚkwlistÚstr)Ú.0r   r   r   r	   ú
<listcomp>   s    
zmake_pat.<locals>.<listcomp>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
   r   r   ÚdirÚbuiltins)
ÚkwZbuiltinlistÚbuiltinÚcommentZstringprefixZsqstringZdqstringZ	sq3stringZ	dq3stringÚstringr   r   r	   Úmake_pat   s    r   z\s+(\w+)c             C   s^   t  ¡ }t  |d¡}t  |d¡d }t  |d¡}| j|d |d ||d |d |d d dS )zcSet color options of Text widget.

    If ColorDelegator is used, this should be called first.
    ZnormalZcursorÚ
foregroundZhiliteÚ
background)r   r   ZinsertbackgroundZselectforegroundZselectbackgroundZinactiveselectbackgroundN)r   ÚCurrentThemeÚGetHighlightZconfig)ÚtextÚthemeZnormal_colorsZcursor_colorZselect_colorsr   r   r	   Úcolor_config"   s    r$   c               @   s€   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zddd„Z	ddd„Z
ddd„Zdd„ Zd dd„Zdd„ Zdd„ Zdd„ Zd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.
    c             C   s*   t  | ¡ |  ¡  t| _t| _|  ¡  d S )N)r   Ú__init__Ú
init_stateÚprogÚidprogÚLoadTagDefs)Úselfr   r   r	   r&   G   s
    
zColorDelegator.__init__c             C   s   d| _ d| _d| _d| _dS )z1Initialize variables that track colorizing state.NTF)Úafter_idÚallow_colorizingÚstop_colorizingÚ
colorizing)r+   r   r   r	   r'   N   s    zColorDelegator.init_statec             C   s\   | j dk	r|  d¡ t | |¡ |dk	rL|  ¡  |  d| j¡ |  dd¡ nd| _d| _	dS )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<<toggle-auto-coloring>>z1.0ÚendTF)
ÚdelegateZunbindr   ÚsetdelegateÚconfig_colorsZbindÚtoggle_colorize_eventÚnotify_ranger.   r-   )r+   r1   r   r   r	   r2   U   s    

zColorDelegator.setdelegatec             C   s4   x$| j  ¡ D ]\}}| j|f|Ž qW |  d¡ dS )z4Configure text widget tags with colors from tagdefs.ZselN)ÚtagdefsÚitemsZtag_configureZ	tag_raise)r+   ÚtagZcnfr   r   r	   r3   l   s    zColorDelegator.config_colorsc             C   sz   t  ¡ }t  |d¡t  |d¡t  |d¡t  |d¡t  |d¡dddœdddœt  |d¡t  |d	¡d
œ	| _trvtd| jƒ dS )z.Create dictionary of tag names to text colors.r   r   r   r   Z
definitionN)r   r   ÚerrorÚhit)	r   r   r   r   Ú
DEFINITIONr   ÚTODOZERRORr:   r6   )r   r    r!   r6   ÚDEBUGÚprint)r+   r#   r   r   r	   r*   r   s    





 zColorDelegator.LoadTagDefsNc             C   s6   |   |¡}| j |||¡ |  ||dt|ƒ  ¡ dS )z:Insert chars into widget at index and mark for colorizing.z+%dcN)Úindexr1   Úinsertr5   Úlen)r+   r?   ÚcharsZtagsr   r   r	   r@   „   s    
zColorDelegator.insertc             C   s&   |   |¡}| j ||¡ |  |¡ dS )z5Delete chars between indexes and mark for colorizing.N)r?   r1   Údeleter5   )r+   Úindex1Úindex2r   r   r	   rC   Š   s    
zColorDelegator.deletec             C   sb   |   d||¡ | jr$tr tdƒ dS | jr<d| _tr<tdƒ | jr^trNtdƒ |  d| j¡| _dS )zCMark text changes for processing and restart colorizing, if active.r<   zcolorizing already scheduledNTzstop colorizingzschedule colorizingé   )	Útag_addr,   r=   r>   r/   r.   r-   ÚafterÚ
recolorize)r+   rD   rE   r   r   r	   r5      s       zColorDelegator.notify_rangec             C   s8   | j r(| j }d | _ trtdƒ |  |¡ d| _d| _d S )Nzcancel scheduled recolorizerFT)r,   r=   r>   Úafter_cancelr-   r.   )r+   r,   r   r   r	   Úclosež   s     
zColorDelegator.closec             C   sˆ   | j r(| j }d| _ trtdƒ |  |¡ | jrF| jrFtr@tdƒ d| _| j | _| jrl| jsl|  d| j¡| _ tr„td| jr~dp€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.
        Nzcancel scheduled recolorizerzstop colorizingTrF   zauto colorizing turnedZonZoffÚbreak)	r,   r=   r>   rJ   r-   r/   r.   rH   rI   )r+   Zeventr,   r   r   r	   r4   §   s"     
 
z$ColorDelegator.toggle_colorize_eventc             C   sÌ   d| _ | jstrtdƒ dS | js2tr.tdƒ dS | jrHtrDtdƒ dS zHd| _d| _trbtdƒ t ¡ }|  	¡  t ¡ }trŽtd||  ƒ W dd| _X | jrÈ|  
d	d
¡rÈtr¸tdƒ |  d| j¡| _ dS )aS  Timer 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 delegatezauto colorizing is offzalready colorizingFTzcolorizing...z%.3f secondsr<   z1.0zreschedule colorizingrF   )r,   r1   r=   r>   r-   r/   r.   ÚtimeZperf_counterÚrecolorize_mainÚtag_nextrangerH   rI   )r+   Zt0Zt1r   r   r	   rI   ¿   s8    
      zColorDelegator.recolorizec             C   sò  d}xæ|   d|¡}|sP |\}}|  d||¡ |  d|¡}|rJ|d }nd}d}|}d}d}xˆ|sè|}|  |d|  ¡}t|d d	ƒ}d|  |d
 ¡k}|  ||¡}	|	s²dS x| jD ]}
|  |
||¡ qºW ||	 }| j 	|¡}x¬|rxŽ| 
¡  ¡ D ]~\}}|rú| |¡\}}|  ||d|  |d|  ¡ |dkrú| j ||¡}|rú| d¡\}}|  d|d|  |d|  ¡ qúW | j 	|| ¡ ¡}qæW d|  |d
 ¡kr°|}d}nd}|sÆ|  d|¡ |  ¡  | jrbtrâtdƒ dS qbW qW dS )z(Evaluate text and apply colorizing tags.z1.0r<   r   rF   Ú Fz+%d lines linestarté   éd   z-1cNz+%dc)ÚdefÚclassr;   zcolorizing stopped)rO   Ú
tag_removeZtag_prevranger?   ÚminZ	tag_namesÚgetr6   r(   ÚsearchÚ	groupdictr7   ÚspanrG   r)   Úmatchr0   Úupdater.   r=   r>   )r+   ÚnextÚitemÚheadÚtailrB   Zlines_to_getÚokZmarkÚliner8   ÚmÚkeyÚvalueÚaÚbZm1r   r   r	   rN   á   sl    




 zColorDelegator.recolorize_mainc             C   s"   x| j D ]}|  |dd¡ qW dS )zRemove all colorizing tags.z1.0r0   N)r6   rU   )r+   r8   r   r   r	   Úremovecolors#  s    zColorDelegator.removecolors)N)N)N)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r&   r'   r2   r3   r*   r@   rC   r5   rK   r4   rI   rN   rh   r   r   r   r	   r%   7   s   


	
"Br%   c             C   s¾   ddl m}m} ddlm} || ƒ}| d¡ tt|  ¡  	d¡dd … ƒ\}}| d|d |d	 f ¡ d
}||dd}|j
ddd | d|¡ | ¡  t|ƒ ||ƒ}	tƒ }
|	 |
¡ d S )Nr   )ÚToplevelÚText)Ú
PercolatorzTest ColorDelegatorú+rF   z700x250+%d+%dé   é¯   ab  if 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'
Zwhite)r   Zboth)ÚexpandZfillr@   )Ztkinterrm   rn   Zidlelib.percolatorro   ÚtitleÚmapÚintZgeometryÚsplitZpackr@   Z	focus_setr$   r%   Zinsertfilter)Úparentrm   rn   ro   ÚtopÚxÚyÚsourcer"   ÚpÚdr   r   r	   Ú_color_delegator)  s    
 r   Ú__main__)Úmainz idlelib.idle_test.test_colorizerrQ   )Ú	verbosityÚexit)Úrun)r   r   ÚrerM   Zidlelib.configr   Zidlelib.delegatorr   r=   r
   r   ÚcompileÚSr(   r)   r$   r%   r   ri   Zunittestr   Zidlelib.idle_test.htestr„   r   r   r   r	   Ú<module>   s&    s"