a 9êdg‘3ã@sÄddlZddlZddlZddlZddlmZddlmZdZdd„Z dd„Z e  e ƒej ¡Z e  d ej ¡Zd d „ZGd d „d eƒZdd„ZedkrÀddlmZeddddddlmZeeƒdS)éN)ÚidleConf)Ú DelegatorFcCsd|d |¡dS)z9Return a named group pattern matching list of alternates.z(?P<%s>ú|ú))Újoin)ÚnameZ alternates©rú-/usr/local/lib/python3.9/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|tjvrt|ƒ‘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|dddS)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&Ks  zColorDelegator.__init__cCsd|_d|_d|_d|_dS)z1Initialize variables that track colorizing state.NTF)Úafter_idÚallow_colorizingÚstop_colorizingÚ colorizingr+rrr r'RszColorDelegator.init_statecCs\|jdur| d¡t ||¡|durL| ¡| 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<>ú1.0ÚendTF) ÚdelegateZunbindrÚ setdelegateÚ config_colorsÚbindÚtoggle_colorize_eventÚ notify_ranger/r.)r,r3rrr r4Ys   zColorDelegator.setdelegatecCs4|j ¡D]\}}|j|fi|¤Žq | d¡dS)z4Configure text widget tags with colors from tagdefs.ZselN)ÚtagdefsÚitemsZ tag_configureZ tag_raise)r,ÚtagZcnfrrr r5pszColorDelegator.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ÚTODOÚERRORr=r9)rr r!r9ÚDEBUGÚprint)r,r#rrr r*vs       ózColorDelegator.LoadTagDefsNcCs6| |¡}|j |||¡| ||dt|ƒ¡dS)z:Insert chars into widget at index and mark for colorizing.ú+%dcN)Úindexr3Úinsertr8Úlen)r,rDÚcharsÚtagsrrr rE‹s zColorDelegator.insertcCs&| |¡}|j ||¡| |¡dS)z5Delete chars between indexes and mark for colorizing.N)rDr3Údeleter8©r,Zindex1Úindex2rrr rI‘s zColorDelegator.deletecCsb| d||¡|jr$tr tdƒdS|jrzcolorizing stopped)rYÚ tag_removeZ tag_prevrangerDÚminZ tag_namesÚgetr9r(ÚsearchÚ groupdictr:ÚspanrNr)Úmatchr2Úupdater/rArB)r,ÚnextÚitemÚheadÚtailrGZ lines_to_getÚokZmarkÚliner;ÚmÚkeyÚvalueÚaÚbZm1rrr rXèsj  ÿ     þ  þ zColorDelegator.recolorize_maincCs|jD]}| |dd¡qdS)zRemove all colorizing tags.r1r2N)r9ra)r,r;rrr Ú removecolors's zColorDelegator.removecolors)N)N)N)N)Ú__name__Ú __module__Ú __qualname__Ú__doc__r&r'r4r5r*rErIr8rSr7rPrXrtrrrr r%;s    "?r%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ú+rMz 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 keyword-string 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)ÚexpandÚfillrE)ÚtkinterryrzZidlelib.percolatorr{ÚtitleÚmapÚintZgeometryÚsplitÚpackrEZ focus_setr$r%Z insertfilter) Úparentryrzr{ÚtopÚxÚyÚsourcer"ÚpÚdrrr Ú_color_delegator-s    ÿ  rŽÚ__main__)Úmainz idlelib.idle_test.test_colorizerr])Ú verbosityÚexit)Úrun)rrÚrerVZidlelib.configrZidlelib.delegatorrrAr rÚcompileÚSr(r)r$r%rŽruZunittestrZidlelib.idle_test.htestr“rrrr Ús&  s"