ó
    ´OÂfít  ã                   ó   • S r SSKrSSKJrJrJrJrJrJrJ	r	J
r
JrJr  SSKJrJr  SSKJrJrJrJrJr  SSKJrJrJrJr  SSKJr   " S S	\5      rS
r " S S5      r " S S5      r S r!S r"S r#\$S:X  a  \"" 5         gg)z
Visualization tools for CFGs.
é    N)
ÚButtonÚCanvasÚEntryÚFrameÚIntVarÚLabelÚ	ScrollbarÚTextÚTkÚToplevel)ÚTreeSegmentWidgetÚtree_to_treesegment)ÚCanvasFrameÚColorizedListÚShowTextÚSymbolWidgetÚ
TextWidget)ÚCFGÚNonterminalÚ_read_cfg_productionÚnonterminals)ÚTreec                   ó>   • \ rS rSr\R
                  S   rS rS rSr	g)ÚProductionListéO   Ú
rightarrowc                 óh   • UR                  SSS9  UR                  SSSS9  UR                  SS	S
S9  g )NÚterminalú#006000©Ú
foregroundÚarrowÚsymbolÚ0)ÚfontÚ	underlineÚnonterminalÚblue©Ú	helveticaiôÿÿÿÚbold©r!   r%   ©Ú
tag_config)ÚselfÚ
textwidgetÚoptionss      Ú//usr/lib/python3/dist-packages/nltk/draw/cfg.pyÚ_init_colortagsÚProductionList._init_colortagsR   sE   € Ø×Ñ˜j°YÐÑ?Ø×Ñ˜g¨HÀÐÑDØ×ÑØ fÐ3Mð 	ò 	
ó    c                 ó\  • / nUR                  SUR                  5       -  S45        UR                  U R                  S45        UR                  5        HT  n[	        U[
        5      (       a&  UR                  SUR                  5       -  S45        M>  UR                  SU-  S45        MV     U$ )Nz%s	r'   r"   ú %sú %rr   )ÚappendÚlhsÚARROWÚrhsÚ
isinstancer   r#   )r/   ÚitemÚcontentsÚelts       r2   Ú
_item_reprÚProductionList._item_reprY   s�   € ØˆØ�‰˜ $§(¡(£*Ñ,¨mÐ<Ô=Ø�‰˜Ÿ™ WÐ-Ô.Ø—8‘8–:ˆCÜ˜#œ{×+Ñ+Ø—‘ ¨¯©«Ñ!5°}Ð EÖFà—‘ ¨¡¨jÐ 9Ö:ñ	 ð
 ˆr5   © N)
Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r   ÚSYMBOLSr;   r3   rA   Ú__static_attributes__rC   r5   r2   r   r   O   s   † Ø× Ñ  Ñ.€Eò
õ	r5   r   aM  

The CFG Editor can be used to create or modify context free grammars.
A context free grammar consists of a start symbol and a list of
productions.  The start symbol is specified by the text entry field in
the upper right hand corner of the editor; and the list of productions
are specified in the main text editing box.

Every non-blank line specifies a single production.  Each production
has the form "LHS -> RHS," where LHS is a single nonterminal, and RHS
is a list of nonterminals and terminals.

Nonterminals must be a single word, such as S or NP or NP_subj.
Currently, nonterminals must consists of alphanumeric characters and
underscores (_).  Nonterminals are colored blue.  If you place the
mouse over any nonterminal, then all occurrences of that nonterminal
will be highlighted.

Terminals must be surrounded by single quotes (') or double
quotes(").  For example, "dog" and "New York" are terminals.
Currently, the string within the quotes must consist of alphanumeric
characters, underscores, and spaces.

To enter a new production, go to a blank line, and type a nonterminal,
followed by an arrow (->), followed by a sequence of terminals and
nonterminals.  Note that "->" (dash + greater-than) is automatically
converted to an arrow symbol.  When you move your cursor to a
different line, your production will automatically be colorized.  If
there are any errors, they will be highlighted in red.

Note that the order of the productions is significant for some
algorithms.  To re-order the productions, use cut and paste to move
them.

Use the buttons at the bottom of the window when you are done editing
the CFG:
  - Ok: apply the new CFG, and exit the editor.
  - Apply: apply the new CFG, and do not exit the editor.
  - Reset: revert to the original CFG, and do not exit the editor.
  - Cancel: revert to the original CFG, and exit the editor.

c                   ó€  • \ rS rSrSr\R                  S   r\R                  " S\-   S-   5      r
\R                  " S\-   S-   5      r\R                  " S\-   S-   S-   5      r\R                  " S	\-   S
-   5      rSrS"S jrS rS rS rS rS rS rS rS rS#S jrS rS rS rS rS rS rS rS r S r!S  r"S!r#g)$Ú	CFGEditoré•   a  
A dialog window for creating and editing context free grammars.
``CFGEditor`` imposes the following restrictions:

- All nonterminals must be strings consisting of word
  characters.
- All terminals must be strings consisting of word characters
  and space characters.
r   z(^\s*\w+\s*)(->|(z))z\s*(->|(z))\s*z#((\w+|'[\w ]*'|\"[\w ]*\"|\|)\s*)*$z\w+|->|'[\w ]+'|"[\w ]+"|(Ú)r)   Nc                 óè  • Xl         Ub  X l        O[        [        S5      / 5      U l        X0l        SU l        [        U5      U l        U R                  5         U R                  5         U R                  R                  SSSS9  U R                  5         U R                  R                  SSSS9  U R                  5         U R                  R                  SSSS9  U R                   R#                  5         g )	NÚSé   ÚtopÚxr   ©ÚsideÚfillÚexpandÚbothÚbottom)Ú_parentÚ_cfgr   r   Ú_set_cfg_callbackÚ _highlight_matching_nonterminalsr   Ú_topÚ_init_bindingsÚ_init_startframeÚ_startframeÚpackÚ_init_prodframeÚ
_prodframeÚ_init_buttonsÚ_buttonframeÚ_textwidgetÚfocus)r/   ÚparentÚcfgÚset_cfg_callbacks       r2   Ú__init__ÚCFGEditor.__init__¯   sÑ   € ØŒØ‰?Ø�IäœK¨Ó,¨bÓ1ˆDŒIØ!1Ôà01ˆÔ-ô ˜VÓ$ˆŒ	Ø×ÑÔà×ÑÔØ×Ñ×Ñ 5¨s¸1ÐÑ=Ø×ÑÔØ�‰×Ñ %¨f¸QÐÑ?Ø×ÑÔØ×Ñ×Ñ H°3¸qÐÑAà×Ñ×ÑÕ r5   c                 ól  • [        U R                  5      =ol        [        U5      U l        U R                  R                  SS9  [        USS9R                  SS9  [        USS9R                  SS9  U R                  R                  SU R                  R                  5       R                  5       5        g )NÚright©rT   zStart Symbol:©ÚtextzProductions:Úleftr   )r   r]   r`   r   Ú_startra   r   ÚinsertrZ   Ústartr#   ©r/   Úframes     r2   r_   ÚCFGEditor._init_startframeÆ   sŽ   € Ü#(¨¯©Ó#3Ð3ˆÔ Ü˜E“lˆŒØ�‰×Ñ˜gÐÑ&Üˆe˜/Ñ*×/Ñ/°WÐ/Ñ=Üˆe˜.Ñ)×.Ñ.°FÐ.Ñ;Ø�‰×Ñ˜1˜dŸi™iŸo™oÓ/×6Ñ6Ó8Õ9r5   c                 ó¢  • [        U R                  5      =ol        [        USU R                  SSS9R                  SS9  [        USU R                  SSS9R                  SS9  [        USU R                  SSS9R                  SS9  [        USU R                  SSS9R                  SS9  [        US	U R                  SSS9R                  S
S9  g )NÚOkr   )rq   Úcommandr&   Ú	takefocusrr   ro   ÚApplyÚResetÚCancelÚHelprn   )
r   r]   re   r   Ú_okra   Ú_applyÚ_resetÚ_cancelÚ_helprv   s     r2   rd   ÚCFGEditor._init_buttonsÎ   sá   € Ü$)¨$¯)©)Ó$4Ð4ˆÔ!Üˆu˜4¨¯©¸QÈ!ÑL×QÑQØð 	Rñ 	
ô 	ˆu˜7¨D¯K©KÀ1ÐPQÑR×WÑWØð 	Xñ 	
ô 	ˆu˜7¨D¯K©KÀ1ÐPQÑR×WÑWØð 	Xñ 	
ô 	Ø˜¨$¯,©,À!Èqñ	
ç
‰$�Fˆ$Ñ
Üˆu˜6¨4¯:©:ÀÈaÑP×UÑUØð 	Vò 	
r5   c                 ó®  • U R                   R                  S5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  S	U R                  5        U R                   R                  S
U R
                  5        U R                   R                  SU R
                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        g )Nz
CFG Editorú<Control-q>z<Alt-q>z<Control-d>z<Alt-x>z<Escape>z<Alt-c>z<Control-o>z<Alt-o>z<Control-a>z<Alt-a>z<Control-r>z<Alt-r>z<Control-h>z<Alt-h>z<F1>)r]   ÚtitleÚbindr„   r�   r‚   rƒ   r…   )r/   s    r2   r^   ÚCFGEditor._init_bindingsà   s\  € Ø�	‰	�‰˜Ô%Ø�	‰	�‰�} d§l¡lÔ3Ø�	‰	�‰�y $§,¡,Ô/Ø�	‰	�‰�} d§l¡lÔ3à�	‰	�‰�y $§,¡,Ô/Ø�	‰	�‰�z 4§<¡<Ô0à�	‰	�‰�y $§,¡,Ô/à�	‰	�‰�} d§h¡hÔ/Ø�	‰	�‰�y $§(¡(Ô+Ø�	‰	�‰�} d§k¡kÔ2Ø�	‰	�‰�y $§+¡+Ô.Ø�	‰	�‰�} d§k¡kÔ2Ø�	‰	�‰�y $§+¡+Ô.Ø�	‰	�‰�} d§j¡jÔ1Ø�	‰	�‰�y $§*¡*Ô-Ø�	‰	�‰�v˜tŸz™zÕ*r5   c                 óÎ  • [        U R                  5      U l        [        U R                  SSS9U l        [        U R                  SSS9U l        U R                  R                  U R                  R                  S9  U R                  R                  U R                  R                  S9  U R                  R                  S	S
S9  U R                  R                  SSSS9  U R                  R                  SSS9  U R                  R                  SSS9  U R                  R                  SSS9  SU l        U R                  R                  SU R                  5        U R                  R                  SU R                  5        U R                  R                  SU R                   5        U R                  R                  SU R                   5        U R                  4S jnU R                  R                  SU5        U R"                  R%                  5        Vs/ s H#  o"R'                  5       UR)                  5       /4PM%     nn[+        [-        U5      S-
  SS5       Hx  nX4   S   X4S-
     S   :X  d  M  SX4   S   ;   a  M%  SX4S-
     S   ;   a  M5  [/        X4S-
     S   5        [/        X4   S   5        X4S-
     S   R1                  X4   S   5        X4	 Mz     U Hw  u  pV[/        XV5        S U-  nU H8  nU H*  n	[3        U	[4        5      (       a
  US!U	-  -  nM"  US"U	-  -  nM,     US#-  nM:     US S$ S%-   nU R                  R7                  S&U5        My     U R                  5         g s  snf )'Nz#e0e0e0rP   )Ú
backgroundÚexportselectionr   Úvertical)r|   Úorient)Úyscrollcommand)r{   rn   Úy©rT   rU   rW   rr   )rV   rU   rT   r   r   r    r"   r#   )r%   ÚerrorÚred©r�   Ú>z	<<Paste>>z
<KeyPress>z<ButtonPress>c                 ó@   • UR                  5       R                  5         g ©N)Útk_focusNextrg   )Úer0   s     r2   ÚcycleÚ(CFGEditor._init_prodframe.<locals>.cycle  s   € Ø×#Ñ#Ó%×+Ñ+Õ-r5   z<Tab>éÿÿÿÿrC   z%s ->r7   r8   z |éþÿÿÿÚ
Úend)r   r]   rc   r
   rf   r	   Ú_textscrollÚconfigÚsetÚyviewra   r.   Ú_linenumrŠ   Ú_replace_arrowsÚ_analyzeÚ_check_analyzerZ   Úproductionsr:   r<   ÚrangeÚlenÚprintÚextendr=   r   rt   )
r/   rœ   ÚpÚprod_tuplesÚir:   ÚrhssÚsr<   r@   s
             r2   rb   ÚCFGEditor._init_prodframeõ   s  € Ü §	¡	Ó*ˆŒô  Ø�O‰O¨	À1ñ
ˆÔô % T§_¡_ÀÈ*ÑUˆÔØ×Ñ×Ñ¨t×/?Ñ/?×/CÑ/CÐÑDØ×Ñ×Ñ¨×(8Ñ(8×(>Ñ(>ÐÑ?Ø×Ñ×Ñ 7°ÐÑ5Ø×Ñ×Ñ Q¨V¸&ÐÑAð 	×Ñ×#Ñ# J¸9Ð#ÑEØ×Ñ×#Ñ# G°(Ð#Ñ;Ø×Ñ×#Ñ# G¸Ð#Ñ>ð ˆŒð 	�	‰	�‰�s˜D×0Ñ0Ô1ð 	�	‰	�‰�{ D§M¡MÔ2Ø�	‰	�‰�| T×%8Ñ%8Ô9Ø�	‰	�‰�¨×(;Ñ(;Ô<ð !%× 0Ñ 0ô 	.ð 	×Ñ×Ñ˜g uÔ-à59·Y±Y×5JÑ5JÔ5LÓMÒ5L°Ÿ™› !§%¡%£' Ó+Ñ5LˆÐMÜ”s˜;Ó'¨!Ñ+¨Q°Ö3ˆAØ‰~˜aÑ  K°A±Ñ$6°qÑ$9Õ9Ø˜™¨Ñ*Ó*ÙØ˜¨¡UÑ+¨AÑ.Ó.ÙÜ�k a¡%Ñ(¨Ñ+Ô,Ü�k‘n QÑ'Ô(Ø ™EÑ" 1Ñ%×,Ñ,¨[©^¸AÑ->Ô?Ø’Nñ 4ó %‰IˆCÜ�#ÔØ˜#‘ˆAÛ�Û�CÜ! #¤{×3Ñ3Ø˜U S™[Ñ(šà˜U S™[Ñ(šñ	 ð
 �T‘	’ñ ð �#�2�˜‘ˆAØ×Ñ×#Ñ# E¨1Ö-ñ %ð 	�‰�ùò3 Ns   È*M"c                 ó¢   • SU-  nSU-  nU R                   R                  5        H'  nUS;  d  M  U R                   R                  XBU5        M)     g)zy
Remove all tags (except ``arrow`` and ``sel``) from the given
line of the text widget used for editing the productions.
ú%d.0ú%d.end)r"   ÚselN)rf   Ú	tag_namesÚ
tag_remove)r/   Úlinenumru   r¡   Útags        r2   Ú_clear_tagsÚCFGEditor._clear_tagsN  sP   € ð
 ˜Ñ ˆØ˜Ñ ˆØ×#Ñ#×-Ñ-Ö/ˆCØÐ*Õ*Ø× Ñ ×+Ñ+¨C¸Ö<ò 0r5   c                 óô   • [        U R                  R                  S5      R                  S5      S   5      nX R                  :w  a3  U R                  U5        U R                  U R                  5        X l        gg)z—
Check if we've moved to a new line.  If we have, then remove
all colorization from the line we moved to, and re-colorize
the line that we moved from.
rt   Ú.r   N)Úintrf   ÚindexÚsplitr¦   r½   Ú_analyze_line)r/   r›   r»   s      r2   r©   ÚCFGEditor._check_analyzeY  sc   € ô �d×&Ñ&×,Ñ,¨XÓ6×<Ñ<¸SÓAÀ!ÑDÓEˆØ—m‘mÓ#Ø×Ñ˜WÔ%Ø×Ñ˜tŸ}™}Ô-Ø#�Mð $r5   c                 ó¾  • Sn U R                   R                  SUS5      nUS:X  a  ObU R                   R                  X"S-   5        U R                   R                  X R                  S5        U R                   R                  US5        M†  Sn U R                   R                  U R                  US-   S5      nUS:X  a  g	U R                   R                  SX"S-   5        MR  )
z£
Replace any ``'->'`` text strings with arrows (char \256, in
symbol font).  This searches the whole buffer, but is fast
enough to be done anytime they press '>'.
ú1.0ú->z	end+1charÚ z+2charr"   Ú	z+1charN)rf   ÚsearchÚdeletert   r;   Útag_add)r/   r›   r"   s      r2   r§   ÚCFGEditor._replace_arrowse  sÕ   € ð ˆØØ×$Ñ$×+Ñ+¨D°%¸ÓEˆEØ˜‹{ØØ×Ñ×#Ñ# E°8Ñ+;Ô<Ø×Ñ×#Ñ# E¯:©:°wÔ?Ø×Ñ×#Ñ# E¨4Ô0ñ ð ˆØØ×$Ñ$×+Ñ+¨D¯J©J¸ÀÑ8HÈ+ÓVˆEØ˜‹{ØØ×Ñ×$Ñ$ W¨e¸XÑ5EÔFñ	 r5   c                 óˆ  • UR                  5       S   S;   a  SnOdUR                  5       SU R                  4;   a  SnOASUR                  5       -   nX0R                  R                  5       ;  a  U R	                  U5        SX!R                  5       4-  nSX!R                  5       4-  nU R                  R                  X4U5        g)	zÅ
Given a line number and a regexp match for a token on that
line, colorize the token.  Note that the regexp match gives us
the token's text, start index (on the line), and end index (on
the line).
r   z'"r   rÈ   r"   Únonterminal_ú%d.%dN)Úgroupr;   rf   r¹   Ú_init_nonterminal_tagru   r¡   rÍ   )r/   Úmatchr»   r¼   ru   r¡   s         r2   Ú_analyze_tokenÚCFGEditor._analyze_token{  s©   € ð �;‰;‹=˜Ñ˜uÓ$Ø‰CØ�[‰[‹]˜t T§Z¡ZÐ0Ó0Ø‰Cð
 ! 5§;¡;£=Ñ0ˆCØ×*Ñ*×4Ñ4Ó6Ó6Ø×*Ñ*¨3Ô/à˜7§K¡K£MÐ2Ñ2ˆØ˜§)¡)£+Ð.Ñ.ˆØ×Ñ× Ñ  ¨SÕ1r5   c                 ó0  • U R                   R                  X[        R                  S9  U R                  (       d  g U R                   U4S jnU R                   U4S jnU R                   R                  USU5        U R                   R                  USU5        g )Nr,   c                 ó$   • UR                  USS9  g )Nz#80ff80r–   r-   ©r›   r0   r¼   s      r2   ÚenterÚ.CFGEditor._init_nonterminal_tag.<locals>.enter˜  s   € Ø×!Ñ! #°)Ð!Ò<r5   c                 ó$   • UR                  USS9  g )NrÉ   r–   r-   rÙ   s      r2   ÚleaveÚ.CFGEditor._init_nonterminal_tag.<locals>.leave›  s   € Ø×!Ñ! #°"Ð!Ò5r5   z<Enter>z<Leave>)rf   r.   rK   Ú_BOLDr\   Útag_bind)r/   r¼   r!   rÚ   rÝ   s        r2   rÓ   ÚCFGEditor._init_nonterminal_tag“  s   € Ø×Ñ×#Ñ# CÄYÇ_Á_Ð#ÑUØ×4×4Øà $× 0Ñ 0°cô 	=ð !%× 0Ñ 0°cô 	6ð 	×Ñ×!Ñ! # y°%Ô8Ø×Ñ×!Ñ! # y°%Õ8r5   c                 ón  • U R                  U5        U R                  R                  [        U5      S-   [        U5      S-   5      n[        R
                  R                  U5      (       a&  X4S jn[        R                  R                  X25        gUR                  5       S:w  a  U R                  X5        gg)z
Colorize a given line.
z.0z.endc                 ó&   • UR                  X5        g)NrÉ   )rÕ   )rÔ   r/   r»   s      r2   Úanalyze_tokenÚ.CFGEditor._analyze_line.<locals>.analyze_token¯  s   € Ø×#Ñ# EÔ3Ør5   rÉ   N)r½   rf   ÚgetÚreprrK   Ú_PRODUCTION_RErÔ   Ú	_TOKEN_REÚsubÚstripÚ_mark_error)r/   r»   Úlinerä   s       r2   rÄ   ÚCFGEditor._analyze_line¡  s˜   € ð
 	×Ñ˜Ô!ð ×Ñ×#Ñ#¤D¨£M°DÑ$8¼$¸w»-È&Ñ:PÓQˆô ×#Ñ#×)Ñ)¨$×/Ñ/ð +/ô ô ×Ñ×#Ñ# MÕ8Ø�Z‰Z‹\˜RÓà×Ñ˜WÕ+ð  r5   c                 ó¤  • [         R                  R                  U5      nU(       d  SU-  nSU-  nOW[         R                  R	                  U5      (       d  SU-  nSXR                  5       4-  nOSXR                  5       4-  nSU-  nU R                  R                  USU5      (       a
  SU-  nSU-  nU R                  R                  SXE5        g)z*
Mark the location of an error in a line.
r¶   r·   rÑ   z==r”   N)
rK   Ú	_ARROW_RErË   Ú_LHS_RErÔ   ru   r¡   rf   ÚcomparerÍ   )r/   r»   rí   Ú
arrowmatchru   r¡   s         r2   rì   ÚCFGEditor._mark_error¸  sÏ   € ô ×(Ñ(×/Ñ/°Ó5ˆ
Þà˜WÑ$ˆEØ˜WÑ$‰CÜ×"Ñ"×(Ñ(¨×.Ñ.à˜WÑ$ˆEØ˜W×&6Ñ&6Ó&8Ð9Ñ9‰Cð ˜w¯©Ó(8Ð9Ñ9ˆEØ˜WÑ$ˆCð ×Ñ×#Ñ# E¨4°×5Ñ5Ø˜WÑ$ˆEØ˜WÑ$ˆCØ×Ñ× Ñ  ¨%Õ5r5   c                 óÞ   • U R                  5         [        U R                  R                  S5      R	                  S5      S   5      n[        SUS-   5       H  nU R                  U5        M     g)z=
Replace ``->`` with arrows, and colorize the entire buffer.
r¡   rÀ   r   rP   N)r§   rÁ   rf   rÂ   rÃ   r«   rÄ   )r/   r›   Únumlinesr»   s       r2   r¨   ÚCFGEditor._analyzeÐ  s^   € ð 	×ÑÔÜ�t×'Ñ'×-Ñ-¨eÓ4×:Ñ:¸3Ó?ÀÑBÓCˆÜ˜Q ¨1¡Ö-ˆGØ×Ñ˜wÖ'ò .r5   c                 ó6  • / nU R                   R                  SS5      n[        R                  " U R                  SU5      n[        R                  " SSU5      nUR                  S5      nU H)  nUR                  5       nUS:X  a  M  U[        U5      -  nM+     U$ )zW
Parse the current contents of the textwidget buffer, to create
a list of productions.
rÇ   r¡   rÈ   rÊ   Ú r    rÉ   )rf   ræ   Úrerê   r;   rÃ   rë   r   )r/   rª   rq   Úlinesrí   s        r2   Ú_parse_productionsÚCFGEditor._parse_productionsÙ  s’   € ð
 ˆð ×Ñ×#Ñ# E¨5Ó1ˆÜ�vŠv�d—j‘j $¨Ó-ˆÜ�vŠv�d˜C Ó&ˆØ—
‘
˜4Ó ˆó ˆDØ—:‘:“<ˆDØ�r‹zÙØÔ/°Ó5Ñ5ŠKñ	 ð* Ðr5   c                 ób   • U R                   c  g U R                   R                  5         S U l         g r™   ©r]   Údestroy©r/   r›   s     r2   Ú_destroyÚCFGEditor._destroyþ  s&   € Ø�9‰9ÑØØ�	‰	×ÑÔØˆ�	r5   c                 óD   • U R                  5         U R                  5         g r™   )r‚   r  r  s     r2   r�   ÚCFGEditor._ok  s   € Ø�‰ŒØ�‰�r5   c                 ó¾   • U R                  5       n[        U R                  R                  5       5      n[	        X25      nU R
                  b  U R                  U5        g g r™   )rü   r   rs   ræ   r   r[   )r/   r›   rª   ru   ri   s        r2   r‚   ÚCFGEditor._apply  sN   € Ø×-Ñ-Ó/ˆÜ˜DŸK™KŸO™OÓ-Ó.ˆÜ�%Ó%ˆØ×!Ñ!Ñ-Ø×"Ñ" 3Õ'ð .r5   c                 ó.  • U R                   R                  SS5        U R                  R                  5        H"  nU R                   R	                  SSU-  5        M$     U R                  5         U R                  b  U R                  U R                  5        g g )NrÇ   r¡   z%s
)rf   rÌ   rZ   rª   rt   r¨   r[   )r/   r›   Ú
productions      r2   rƒ   ÚCFGEditor._reset  sv   € Ø×Ñ×Ñ  uÔ-ØŸ)™)×/Ñ/Ö1ˆJØ×Ñ×#Ñ# E¨6°JÑ+>Ö?ñ 2à�‰ŒØ×!Ñ!Ñ-Ø×"Ñ" 4§9¡9Õ-ð .r5   c                 óT   •  U R                  5         U R                  5         g !    N= fr™   )rƒ   r  r  s     r2   r„   ÚCFGEditor._cancel  s%   € ð	Ø�K‰KŒMð 	�‰�øð	Ùús   ‚# £'c                 ó¶   •  [        U R                  S[        R                  5       SSS9  g !   [        U R                  S[        R                  5       SS9   g = f)NzHelp: Chart Parser DemoéK   Úfixed)Úwidthr%   ©r  )r   rY   Ú_CFGEditor_HELPrë   r  s     r2   r…   ÚCFGEditor._help  sS   € ð	ÜØ—‘Ø)Ü ×'Ñ'Ó)ØØóøð	ÜØ—‘Ø)Ü ×'Ñ'Ó)Øô	ús	   ‚), ¬*A)re   rZ   r\   r¦   rY   rc   r[   rs   r`   r¢   rf   r]   )NN)r(   )$rD   rE   rF   rG   Ú__doc__r   rH   r;   rú   Úcompilerñ   rð   rè   ré   rß   rk   r_   rd   r^   rb   r½   r©   r§   rÕ   rÓ   rÄ   rì   r¨   rü   r  r�   r‚   rƒ   r„   r…   rI   rC   r5   r2   rK   rK   •   s   † ñð × Ñ  Ñ.€EØ�jŠjÐ-°Ñ5¸Ñ<Ó=€GØ—
’
˜;¨Ñ.°Ñ9Ó:€IØ—Z’Zð	à
ñ	ð ñ	ð 1ñ		1ó€Nð —
’
Ð<¸uÑDÀsÑJÓK€IØ&€Eô!ò.:ò
ò$+ò*>òr	=ò
$òGò,2ô09ò,ò.6ò0(ò#òJòò(ò.òõr5   rK   c                   óf   • \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rSS jrS rS rS rSrg)ÚCFGDemoi6  c                 óB  • Xl         X l        [        5       U l        U R                  R	                  S5        [        U R                  5      U l        U R                  R                  S5        U R                  U R                  5        [        U R                  5      nUR                  SSSS9  U R                  U R                  5        U R                  U R                  5        U R                  U5        U R                  U5        U R                  U R                  5        g )NzContext Free Grammar Demoé   rr   r’   r   rS   )Ú_grammarÚ_textr   r]   r‰   r   Ú_sizer¤   r^   r   ra   Ú_init_menubarrd   Ú_init_grammarÚ_init_treeletÚ_init_workspace)r/   Úgrammarrq   Úframe1s       r2   rk   ÚCFGDemo.__init__7  sÒ   € ØŒØŒ
ô “DˆŒ	Ø�	‰	�‰Ð3Ô4ô ˜DŸI™IÓ&ˆŒ
Ø�
‰
�‰�rÔð 	×Ñ˜DŸI™IÔ&ô �t—y‘yÓ!ˆØ�‰˜ c°!ˆÑ4Ø×Ñ˜4Ÿ9™9Ô%Ø×Ñ˜4Ÿ9™9Ô%Ø×Ñ˜6Ô"Ø×Ñ˜6Ô"Ø×Ñ˜TŸY™YÕ'r5   c                 ó<   • UR                  SU R                  5        g )Nrˆ   )rŠ   r   )r/   rQ   s     r2   r^   ÚCFGDemo._init_bindingsS  s   € Ø�‰� §¡Õ-r5   c                 ó   • g r™   rC   ©r/   rh   s     r2   r  ÚCFGDemo._init_menubarV  ó   € Ør5   c                 ó   • g r™   rC   r'  s     r2   rd   ÚCFGDemo._init_buttonsY  r)  r5   c                 ó8  • [        XR                  SS9U l        U R                  R                  SSSS9  U R                  R	                  5         U R                  R                  SU R                  5        U R                  R                  SU R                  5        g )	Né   r  rQ   rW   rP   rS   ÚselectÚmove)r   r  Ú	_prodlistra   rg   Úadd_callbackÚ_selectprod_cbr'  s     r2   r  ÚCFGDemo._init_grammar\  sq   € Ü'¨·±ÀRÑHˆŒØ�‰×Ñ ¨V¸AÐÑ>Ø�‰×ÑÔØ�‰×#Ñ# H¨d×.AÑ.AÔBØ�‰×#Ñ# F¨D×,?Ñ,?Õ@r5   c                 ód   • [        USS9U l        U R                  R                  SSS9  S U l        g )NÚwhiter–   rX   rR   r“   )r   Ú_treelet_canvasra   Ú_treeletr'  s     r2   r  ÚCFGDemo._init_treeletc  s1   € Ü% f¸ÑAˆÔØ×Ñ×!Ñ! x°cÐ!Ñ:Øˆ�r5   c                 ó†   • [        USS9U l        U R                  R                  SSSS9  S U l        U R	                  5         g )Nr5  r–   rn   rW   rP   rS   )r   Ú
_workspacera   Ú_treeÚreset_workspacer'  s     r2   r   ÚCFGDemo._init_workspaceh  s<   € Ü% f¸ÑAˆŒØ�‰×Ñ '°¸qÐÑAØˆŒ
Ø×ÑÕr5   c           
      óh  • U R                   R                  5       n[        U R                  R	                  5       5      nSUS-   * S4nSUS-   * 4nU R
                  b%  U R                   R                  U R
                  5        U R                  R                  5       R                  5       n[        XUSS9n/ nU R                   H  nUR                  [        XUSS95        M     [        XUSS9U l        U R                   R                  U R
                  5        U H  n	U	R                  S	S
5        M     g )Nr*   é   r+   é   rP   )r%   Ú	draggabler5  )Úcolorr   éd   )r:  ÚcanvasrÁ   r  ræ   r;  Úremove_widgetr  ru   r#   r   r  r9   r   Ú
add_widgetr/  )
r/   ÚcÚfontsizeÚ	node_fontÚ	leaf_fontru   ÚrootnodeÚleavesÚwordÚleafs
             r2   r<  ÚCFGDemo.reset_workspacer  s  € Ø�O‰O×"Ñ"Ó$ˆÜ�t—z‘z—~‘~Ó'Ó(ˆØ  H¨q¡L /°6Ð:ˆ	Ø  H¨q¡L /Ð2ˆ	ð �:‰:Ñ!Ø�O‰O×)Ñ)¨$¯*©*Ô5ð —‘×#Ñ#Ó%×,Ñ,Ó.ˆÜ˜a¨YÀ!ÑDˆð ˆØ—J”JˆDØ�M‰Mœ* Q°9ÈÑJÖKñ ô ' q°FÀ'ÑJˆŒ
ð 	�‰×"Ñ" 4§:¡:Ô.ó ˆDØ�I‰I�a˜Öò r5   c                 ó   • g r™   rC   )r/   r	  s     r2   Úworkspace_markprodÚCFGDemo.workspace_markprod’  r)  r5   Nc                 óŒ  • Uc  U R                   n[        [        UR                  5       5      [        UR	                  5       5      -
  5       Hõ  nUSU4   S:X  a  U R
                    [        UR	                  5       5       H²  u  pEUR                  5       X4-      n[        U[        5      (       aC  [        U[        5      (       a.  UR                  UR                  5       R                  5       :X  a  Mr  [        U[        5      (       a*  [        U[        5      (       a  XVR                  5       :X  a  M±    Mç     [        SU5        M÷     g )NrB  r5  zMATCH AT)r;  r«   r¬   Úsubtreesr<   Ú_markproductionÚ	enumerater=   r   r   r#   Úlabelrq   Ústrr   r­   )r/   ÚprodÚtreer±   ÚjÚnodeÚwidgets          r2   rU  ÚCFGDemo._markproduction•  sí   € Ø‰<Ø—:‘:ˆDÜ”s˜4Ÿ=™=›?Ó+¬c°$·(±(³*«oÑ=Ö>ˆAØ�G˜Q�JÑ 7Ó*Ø×$Ò$ä$ T§X¡X£ZÖ0‘�ØŸ™›¨©Ñ/�ä˜t¤[×1Ñ1Ü" 6Ô+<×=Ñ=ØŸ™ v§|¡|£~×':Ñ':Ó'<Ó<áä˜t¤S×)Ñ)Ü" 6¬:×6Ñ6Ø§¡£Ó-áâñ 1ô$ �j !Ö$ò- ?r5   c                 ó
  • U R                   nU R                  R                  U5        U R                  b  U R                  R	                  5         UR                  5       n[        U5       H'  u  pE[        U[        5      (       d  M  [        U5      nM)     [        UR                  5       R                  5       /UQ76 n[        U R                  R                  5       5      nSUS-   * S4nSUS-   * 4n	[        X&X‰S9U l        SU R                  S'   U R                  R!                  5       u  p«pÍ[        US   5      [        US	   5      pþU R                  R#                  Xê-
  U-
  S-  Xû-
  U-
  S-  5        U R%                  U5        g )
Nr*   r?  r+   r@  )rI  rJ  rP   rA  r  Úheight)r6  r0  Ú	highlightr7  r   r<   rV  r=   r   r   r:   r#   rÁ   r  ræ   r   Úbboxr/  rU  )r/   r	  rD  r<   r±   r@   rZ  rH  rI  rJ  Úx1Úy1Úx2Úy2ÚwÚhs                   r2   r2  ÚCFGDemo._selectprod_cb´  sU  € Ø×%Ñ%ˆà�‰× Ñ  Ô,Ø�=‰=Ñ$Ø�M‰M×!Ñ!Ô#ð �n‰nÓˆÜ –n‰FˆAÜ˜#œ{×+Ó+Ü˜3“i’ñ %ô �J—N‘NÓ$×+Ñ+Ó-Ð4°Ò4ˆô �t—z‘z—~‘~Ó'Ó(ˆØ  H¨q¡L /°6Ð:ˆ	Ø  H¨q¡L /Ð2ˆ	Ü+Ø Iñ
ˆŒð &'ˆ�‰�kÑ"ð  Ÿ=™=×-Ñ-Ó/Ñˆ�Ü�6˜'‘?Ó#¤S¨°Ñ)9Ó%:ˆ1Ø�‰×Ñ˜A™F R™K¨1Ñ,¨q©v¸©{¸aÑ.?Ô@ð 	×Ñ˜ZÕ(r5   c                 ó8   • U R                   R                  5         g r™   rÿ   )r/   Úargss     r2   r   ÚCFGDemo.destroyÓ  s   € Ø�	‰	×ÑÕr5   c                 ó<   • U R                   R                  " U0 UD6  g r™   )r]   Úmainloop)r/   rk  Úkwargss      r2   rn  ÚCFGDemo.mainloopÖ  s   € Ø�	‰	×Ò˜DÐ+ FÓ+r5   )	r  r0  r  r  r]   r;  r7  r6  r:  r™   )rD   rE   rF   rG   rk   r^   r  rd   r  r  r   r<  rQ  rU  r2  r   rn  rI   rC   r5   r2   r  r  6  sE   † ò(ò8.òòòAòò
òò@ô%ò>)ò>õ,r5   r  c                  ó4  ^• SSK Jn JmJn  SnU4S jUR                  " 5        5       u	  p4pVpxpšnU" X5U/5      U" X[U/5      U" XUU/5      U" XDU/5      U" XJXV/5      U" XJU/5      U" XgU/5      U" U/ 5      U" USSU/5      U" US/5      U" US/5      U" US	/5      U" US
/5      U" U
S/5      U" US/5      U" US/5      U" US/5      U" US/5      U" US/5      U" US/5      4nU " X<5      nSR	                  5       n[        XÞ5      nUR                  5         g )Nr   )r   r   Ú
ProductionúS VP NP PP P N Name V Detc              3   ó4   >#   • U  H  nT" U5      v •  M     g 7fr™   rC   ©Ú.0r³   r   s     €r2   Ú	<genexpr>Údemo2.<locals>.<genexpr>Þ  ó   øé € Ð*XÒCW¸a©;°q¯>¨>ÒCWùó   ƒÚupÚoverÚIÚtheÚaÚmanÚsawÚinÚwithÚparkÚdogÚstatueÚmyzI saw a man in the park)Únltkr   r   rr  rÃ   r  rn  )r   rr  r   rO   ÚVPÚNPÚPPÚPÚNÚNameÚVÚDetrª   r!  rq   Údr   s                   @r2   Údemo2r’  Ú  sU  ø€ ß1Ñ1à.€LÜ*XÀ<×CUÒCUÔCWÓ*XÑ'€QˆB�A˜$ 3ñ 	�1˜2�hÓÙ�2˜Q�xÓ Ù�2˜B�xÓ Ù�2˜B�xÓ Ù�2˜2�{Ó#Ù�2˜2�wÓÙ�2˜2�wÓÙ�2�rÓÙ�2˜˜f bÐ)Ó*á�2˜�uÓÙ�3˜˜Ó Ù�3˜˜ÓÙ�1�u�gÓÙ�1�u�gÓÙ�1�t�fÓÙ�1�v�hÓÙ�1�v�hÓÙ�1�u�gÓÙ�1�x�jÓ!Ù�3˜˜Óð-€Kñ0 �!Ó!€Gà$×*Ñ*Ó,€DÜ�Ó€AØ‡J�J…Lr5   c            	      óH  ^• SSK Jn Jm  SnU4S jUR                  " 5        5       u	  p#pEpgp‰n
U R                  " S5      nS n[        5       n[        XÛU5      n[        USS9R                  5         [        US	UR                  S
9R                  5         UR                  5         g )Nr   )r   r   rs  c              3   ó4   >#   • U  H  nT" U5      v •  M     g 7fr™   rC   ru  s     €r2   rw  Údemo.<locals>.<genexpr>  ry  rz  a+  
    S -> NP VP
    PP -> P NP
    NP -> Det N
    NP -> NP PP
    VP -> V NP
    VP -> VP PP
    Det -> 'a'
    Det -> 'the'
    Det -> 'my'
    NP -> 'I'
    N -> 'dog'
    N -> 'man'
    N -> 'park'
    N -> 'statue'
    V -> 'saw'
    P -> 'in'
    P -> 'up'
    P -> 'over'
    P -> 'with'
    c                 ó   • [        U 5        g r™   )r­   )r!  s    r2   ÚcbÚdemo.<locals>.cb!  s	   € Üˆg�r5   z
Testing CFG Editor
rp   ÚQuit)rq   r{   )rˆ  r   r   rÃ   Ú
fromstringr   rK   r   ra   r   r   rn  )r   r   rO   r‰  rŠ  r‹  rŒ  r�  rŽ  r�  r�  r!  r—  rQ   Úeditorr   s                  @r2   Údemorœ    sŒ   ø€ ß%à.€LÜ*XÀ<×CUÒCUÔCWÓ*XÑ'€QˆB�A˜$ 3à�nŠnð	ó€Gò0ô ‹$€CÜ�s RÓ(€FÜ	ˆ#Ð,Ñ-×2Ñ2Ô4Ü
ˆ3�V S§[¡[Ñ1×6Ñ6Ô8Ø‡L�L…Nr5   c                  óú  • SSK Jn   [        S5      u	  pp4pVpxn	U " XU/5      U " X9U/5      U " X3U/5      U " X"U/5      U " X(X4/5      U " X(U/5      U " XEU/5      U " U/ 5      U " USSU/5      U " US/5      U " U	S/5      U " U	S/5      U " US	/5      U " US
/5      U " US/5      U " US/5      U " US/5      U " US/5      U " US/5      U " U	S/5      4n
[        5       nU4S jnUR	                  SU5        [        Xº5      nUR                  SSS9  UR                  SUR                  5        UR                  SUR                  5        UR                  5         UR                  U
S   5        UR                  U
S   5        g )Nr   )rr  z!S, VP, NP, PP, P, N, Name, V, Detr{  r|  r}  r~  r  r€  r�  r‚  rƒ  r„  r…  r†  r‡  c                 ó$   • UR                  5         g r™   )r   )r›   Úts     r2   r   Údemo3.<locals>.destroyM  s   € Ø	�	‰	�r5   ÚqrP   rW   )rV   rU   r.  r/  r@  é   )rˆ  rr  r   r   rŠ   r   ra   r1  Úmarkonlyrg   Úmark)rr  rO   r‰  rŠ  r‹  rŒ  r�  rŽ  r�  r�  rª   rŸ  r   r¯   s                 r2   Údemo3r¥  +  s¡  € Ýä*6Ø+ó+Ñ'€QˆB�A˜$ 3ñ 	�1˜2�hÓÙ�2˜Q�xÓ Ù�2˜B�xÓ Ù�2˜B�xÓ Ù�2˜2�{Ó#Ù�2˜2�wÓÙ�2˜2�wÓÙ�2�rÓÙ�2˜˜f bÐ)Ó*á�2˜�uÓÙ�3˜˜Ó Ù�3˜˜ÓÙ�1�u�gÓÙ�1�u�gÓÙ�1�t�fÓÙ�1�v�hÓÙ�1�v�hÓÙ�1�u�gÓÙ�1�x�jÓ!Ù�3˜˜Óð-€Kô2 	‹€Aàô ð ‡F�Fˆ3�ÔÜ�qÓ&€AØ‡F�F�!˜&€FÑ!Ø‡N�N�8˜QŸZ™ZÔ(Ø‡N�N�6˜1Ÿ:™:Ô&Ø‡G�G„IØ‡F�Fˆ;�q‰>ÔØ‡F�Fˆ;�q‰>Õr5   Ú__main__)%r  rú   Útkinterr   r   r   r   r   r   r	   r
   r   r   Únltk.draw.treer   r   Únltk.draw.utilr   r   r   r   r   Únltk.grammarr   r   r   r   Ú	nltk.treer   r   r  rK   r  r’  rœ  r¥  rD   rC   r5   r2   Ú<module>r¬     s�   ðñóR 
÷÷ ÷ ÷ B÷õ ÷ NÓ MÝ ô�]ô ð4)€÷XYñ Y÷Ba,ñ a,òH!òR%òP,ð^ ˆzÓÙ…Fð r5   