Ë
    #´˜j˜M  ã                   óJ  — d Z ddlZ ed«      \  ZZZZZ ej                  dej                  ej                  z  «      j                  Z ej                  dej                  «      j                  Z ej                  dej                  ej                  z  «      j                  Z ej                  dej                  «      j                  Z ej                  dej                  «      j                  Z ej                  d	ej                  «      j                  Z G d
„ de«      Zej-                   ed«      d«      Zej1                  d„ dD «       «       ej1                  d„ dD «       «       ej1                  d„ dD «       «        G d„ d«      Zedk(  rddlmZ  edd¬«       yy)aÄ  Define partial Python code Parser used by editor and hyperparser.

Instances of ParseMap are used with str.translate.

The following bound search and match functions are defined:
_synchre - start of popular statement;
_junkre - whitespace or comment line;
_match_stringre: string, possibly without closer;
_itemre - line that may have bracket structure start;
_closere - line that must be followed by dedent.
_chew_ordinaryre - non-special characters.
é    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                   ó   — e Zd ZdZd„ Zy)ÚParseMapap  Dict subclass that maps anything not in dict to 'x'.

    This is designed to be used with str.translate in study1.
    Anything not specifically mapped otherwise becomes 'x'.
    Example: replace everything except whitespace with 'x'.

    >>> keepwhite = ParseMap((ord(c), ord(c)) for c in ' \t\n\r')
    >>> "a + b\tc\nd".translate(keepwhite)
    'x x x\tx\nx'
    c                  ó   — y)Néx   © )ÚselfÚkeys     ú!lib/python3.12/idlelib/pyparse.pyÚ__missing__zParseMap.__missing__r   s   € Øó    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   f   s   „ ñ	ór   r   é€   r   c              #   óH   K  — | ]  }t        |«      t        d «      f–— Œ y­w)Ú(N©Úord©Ú.0Úcs     r   Ú	<genexpr>r   x   ó   è ø€ Ð/© AŒc�!‹f”c˜#“hÔ©ùó   ‚ "z({[c              #   óH   K  — | ]  }t        |«      t        d «      f–— Œ y­w)Ú)Nr   r   s     r   r   r   y   r   r   z)}]c              #   óH   K  — | ]  }t        |«      t        |«      f–— Œ y ­w©Nr   r   s     r   r   r   z   s   è ø€ Ð2¡z !Œc�!‹f”c˜!“fÔ¡zùr   z"'\
#c                   ó`   — e Zd Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zy)ÚParserc                 ó    — || _         || _        y r    )ÚindentwidthÚtabwidth)r	   r$   r%   s      r   Ú__init__zParser.__init__   s   € Ø&ˆÔØ ˆ�r   c                 óP   — t        |«      dk(  s
|d   dk(  sJ ‚|| _        d| _        y )Nr   éÿÿÿÿÚ
)ÚlenÚcodeÚstudy_level)r	   Úss     r   Úset_codezParser.set_codeƒ   s,   € Ü�1‹v˜Š{˜a ™e tšmÐ+Ð+ØˆŒ	ØˆÕr   c                 ó  — | j                   d}}t        |«      }t        d«      D ]k  }|j                  dd|«      }|dk  r nQ|j                  dd|«      dz   }t	        |||«      }|r( ||j                  «       «      s|j                  «       } n|}Œm |€5t	        |«      }|r& ||j                  «       «      s|j                  «       }|S |dz   }t	        ||«      x}r,|j                  «       \  }} ||«      s|}t	        ||«      x}rŒ,|S )a^  
        Return index of a good place to begin parsing, as close to the
        end of the string as possible.  This will be the start of some
        popular stmt like "if" or "def".  Return None if none found:
        the caller should pass more prior context then, if possible, or
        if not (the entire program text up until the point of interest
        has already been tried) pass 0 to set_lo().

        This will be reliable iff given a reliable is_char_in_string()
        function, meaning that when it says "no", it's absolutely
        guaranteed that the char is not in a string.
        Nr   z:
r   r)   é   )r+   r*   ÚrangeÚrfindÚ_synchreÚstartÚspan)	r	   Úis_char_in_stringr+   ÚposÚlimitÚtriesÚiÚmr-   s	            r   Úfind_good_parse_startzParser.find_good_parse_startˆ   s  € ð —I‘I˜tˆcˆô
 �D“	ˆÜ˜1–XˆEØ—
‘
˜5 ! UÓ+ˆAØ�1ŠuÙØ—
‘
˜4  AÓ&¨Ñ*ˆAÜ˜˜q %Ó(ˆAÙÑ*¨1¯7©7«9Ô5Ø—g‘g“i�ÙØ‰Eð ð ˆ;ô ˜“ˆAÙÑ*¨1¯7©7«9Ô5Ø—g‘g“i�ØˆJð �!‰GˆÜ˜D !Ó$Ð$ˆaÐ$Ø—6‘6“8‰DˆAˆqÙ$ QÔ'Ø�ô ˜D !Ó$Ð$ˆaÑ$ð ˆ
r   c                 óp   — |dk(  s| j                   |dz
     dk(  sJ ‚|dkD  r| j                   |d | _         yy)zx Throw away the start of the string.

        Intended to be called with the result of find_good_parse_start().
        r   r0   r)   N)r+   )r	   Úlos     r   Úset_lozParser.set_lo¼   sA   € ð
 �QŠw˜$Ÿ)™) B q¡D™/¨TÒ1Ð1Ð1Ø�Š6ØŸ	™	 " #˜ˆD�Ið r   c                 ó¼  — | j                   dk\  ryd| _         | j                  }|j                  t        «      }|j	                  dd«      }|j	                  dd«      }|j	                  dd«      }|j	                  dd«      }|j	                  dd«      }t
        }d	x}}d	gx| _        }|j                  }d	t        |«      }}||k  �rN||   }	|dz   }|	dk(  rŒ|	dk(  r|dz   }|d	k(  r ||«       Œ.|	d
k(  r|dz   }Œ9|	dk(  r|r|dz
  }ŒF|	dk(  s|	dk(  r¯|	}
||dz
  |dz    |
dz  k(  r|
dz  }
|}t        |
«      dz
  }||z   }||k  rg||   }	|dz   }|	dk(  rŒ||dz
  ||z    |
k(  r||z   }nX|	dk(  r|dz   }|d	k(  r|d	k(  r ||«       n;ŒG|	dk(  r||k  sJ ‚||   dk(  r|dz   }|dz   }Œf||k  rŒg|dz
  |k(  rt        }nt        }Œÿ|	dk(  r|j                  d|«      }|d	k\  sJ ‚�Œ|	dk(  sJ ‚||k  sJ ‚||   dk(  r|dz   }|dz   |k(  rt        }|dz   }||k  r�ŒN|t        k7  r|t        k7  r|d	kD  rt        }|| _        |t
        k(  |d   |k(  k(  sJ ‚|d   |k7  r	 ||«       yy)záFind the line numbers of non-continuation lines.

        As quickly as humanly possible <wink>, find the line numbers (0-
        based) of the non-continuation lines.
        Creates self.{goodlines, continuation}.
        r0   NÚxxxxxxxxÚxÚxxxxÚxxz
xr)   r   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+   rV   ÚlevelÚlnorO   Ú	push_goodr:   ÚnÚchÚquoteÚfirstlnoÚws                r   Ú_study1zParser._study1Å   s  € ð ×Ñ˜qÒ ØØˆÔð �y‰yˆØ�~‰~œeÓ$ˆØ�|‰|˜J¨Ó,ˆØ�|‰|˜F CÓ(ˆØ�|‰|˜D #Ó&ˆØ�|‰|˜D #Ó&ˆØ�|‰|˜E 4Ó(ˆô ˆØˆˆ�Ø&' SÐ(ˆŒ˜Ø×$Ñ$ˆ	Ø”#�d“)ˆ1ˆØ�!‹eØ�a‘ˆBØ�!‘ˆAð �SŠyØà�TŠzØ˜A‘g�Ø˜A’:Ù˜c”Nàà�SŠyØ ™	�Øà�SŠyÙØ! A™I�Eàà�SŠy˜B #šIà�Ø˜˜!™˜A˜a™C�= E¨A¡IÒ-Ø! A™I�EØ�Ü˜“J ‘N�Ø�a‘C�Ø˜!’eØ˜a™�BØ˜!™�Aà˜S’yØ à˜A˜a™C  !¡�}¨Ò-Ø˜a™C˜Øà˜T’zØ! A™g˜Ø š6à$¨šzÙ )¨#¤Ø!Ø à˜T’zØ  1šu˜˜uØ ™7 dš?Ø"%¨¡'˜CØ˜a™C˜Ø ð3 ˜!“eð@ ˜a™ HÒ,ô (;™ä':˜Øà�SŠyà—I‘I˜d AÓ&�Ø˜A’v��vÙà˜’:Ð�:Ø�q’5ˆL�5Ø�A‰w˜$ŠØ˜A‘g�Ø�Q‘3˜!’8Ü#.�LØ�!‘ˆAðk �!Œeðt Ô/Ò/ØÔ 3Ò3¸Àº	Ü$ˆLØ(ˆÔð ¤Ñ&¨I°b©M¸SÑ,@ÒAÐAÐAØ�R‰=˜CÒÙ�c�Nð  r   c                 ó:   — | j                  «        | j                  S r    )r_   rV   ©r	   s    r   Úget_continuation_typezParser.get_continuation_typeK  s   € Ø�‰ŒØ× Ñ Ð r   c                 ób  — | j                   dk\  ry| j                  «        d| _         | j                  | j                  }}t	        |«      dz
  }t	        |«      }|rO|sJ ‚|}t        ||dz
     ||   «      D ]  }|j                  dd|dz
  «      dz   }Œ t        ||«      r|dz
  }nn|rŒO|dk(  r	|dk(  sJ ‚|}|c| _        | _	        d}g }|j                  }	|dfg}
||k  �r©t        |||«      }|rF|j                  «       }|dz
  }||k\  r||   dv r|dz
  }||k\  r||   dv rŒ||k\  r||   }|}||k\  r�nT||   }|dv r, |	|«       |
j                  |t	        |«      f«       |}|dz   }Œ�|d	v r)|r|d
= |}|dz   }|
j                  |t	        |«      f«       Œ½|dk(  s|dk(  rZ|
j                  |t	        |«      dz   f«       |}t        |||«      j                  «       }|
j                  |t	        |«      f«       �Œ!|dk(  rZ|
j                  |t	        |«      dz   f«       |j                  d||«      dz   }|dkD  sJ ‚|
j                  |t	        |«      f«       �Œ€|dk(  sJ ‚|dz   }||k  sJ ‚||   dk7  r|||   z   }|dz   }||k  r�Œ©|| _        |r|d
   nd| _        t#        |
«      | _        y)am  
        study1 was sufficient to determine the continuation status,
        but doing more requires looking at every character.  study2
        does this for the last interesting statement in the block.
        Creates:
            self.stmt_start, stmt_end
                slice indices of last interesting stmt
            self.stmt_bracketing
                the bracketing structure of the last interesting stmt; for
                example, for the statement "say(boo) or die",
                stmt_bracketing will be ((0, 0), (0, 1), (2, 0), (2, 1),
                (4, 0)). Strings and comments are treated as brackets, for
                the matter.
            self.lastch
                last interesting character before optional trailing comment
            self.lastopenbracketpos
                if continuation is C_BRACKET, index of last open bracket
        rG   Nr0   r)   r   Ú ú 	
ú([{ú)]}r(   rE   rF   rJ   rI   )r,   r_   r+   rO   r*   r1   r2   Ú_junkreÚ
stmt_startÚstmt_endrP   Ú_chew_ordinaryreÚendÚ_match_stringrerS   ÚlastchÚlastopenbracketposÚtupleÚstmt_bracketing)r	   r+   rO   r:   ÚpÚqÚnothingrn   ÚstackÚ
push_stackÚ
bracketingr;   Únewpr[   s                 r   Ú_study2zParser._study2O  s  € ð& ×Ñ˜qÒ ØØ�‰ŒØˆÔð Ÿ)™) T§^¡^ˆiˆÜ�	‹N˜QÑˆÜ�‹IˆÙÙˆH�1ð ˆAÜ  ¨1¨Q©3¡°¸1±Ö>�à—J‘J˜t Q¨¨!©Ó,¨qÑ0‘ð ?ô
 ˜˜aÔ Ø�a‘C‘àò ð �Š6à˜’6ˆM�6ØˆAØ)*¨AÐ&ˆŒ˜œð ˆØˆØ—\‘\ˆ
Ø˜!�f�Xˆ
Ø�!‹eä   q¨!Ó,ˆAÙà—u‘u“w�à˜1‘H�Ø˜1’f  a¡¨GÑ!3Ø˜!™�Að ˜1’f  a¡¨GÒ!3à˜’6Ø! !™W�FØ�Ø˜’6Ùà�a‘ˆBà�U‰{Ù˜1”Ø×!Ñ! 1¤c¨%£j /Ô2Ø�Ø�a‘C�Øà�U‰{ÙØ˜b˜	Ø�Ø�a‘C�Ø×!Ñ! 1¤c¨%£j /Ô2Øà�SŠy˜B #šIð ×!Ñ! 1¤c¨%£j°¡lÐ"3Ô4Ø�Ü# D¨!¨QÓ/×3Ñ3Ó5�Ø×!Ñ! 1¤c¨%£j /Ô2Ùà�SŠyà×!Ñ! 1¤c¨%£j°¡lÐ"3Ô4Ø—I‘I˜d A qÓ)¨AÑ-�Ø˜1’u��uØ×!Ñ! 1¤c¨%£j /Ô2Ùà˜’:Ð�:Ø�!‘ˆAØ�q’5ˆL�5Ø�A‰w˜$Šà˜d 1™g™�Ø�!‘ˆAð{ �!ŒeðB ˆŒÙ/4 %¨¢)¸$ˆÔÜ$ ZÓ0ˆÕr   c                 óô  — | j                  «        | j                  t        k(  sJ ‚| j                  }| j                  }t        |«      }|j                  dd|«      dz   x}}|dz   }||k  rAt        ||«      }|r|j                  «       dz
  }d}nA|j                  d|«      dz   x}}||k  rŒA|x}}||   dv r|dz   }||   dv rŒ| j                  }t        ||| j                  | j                  «      «      |z   S )zpReturn number of spaces the next line should be indented.

        Line continuation must be C_BRACKET.
        r)   r   r0   ú 	)ry   rV   rU   ro   r+   r*   r2   Ú_itemrerl   rS   r$   Ú
expandtabsr%   )r	   Újr+   rZ   Úorigir:   r;   Úextras           r   Úcompute_bracket_indentzParser.compute_bracket_indentÊ  s  € ð
 	�‰ŒØ× Ñ ¤IÒ-Ð-Ð-Ø×#Ñ#ˆØ�y‰yˆÜ�‹IˆØ—J‘J˜t Q¨Ó*¨QÑ.Ð.ˆ�Øˆa‰Cˆà�!ŠeÜ˜˜aÓ ˆAÙØ—E‘E“G˜a‘K�Ø�Øð Ÿ	™	 $¨Ó*¨QÑ.Ð.��Að �!‹eð ˆMˆA�Ø�q‘'˜UÑ"Ø�a‘C�ð �q‘'˜UÒ"à×$Ñ$ˆEÜ�4˜˜!�9×'Ñ'¨¯©Ó6Ó7¸%Ñ?Ð?r   c                 óP   — | j                  «        | j                  }|d   |d   z
  S )zÃReturn number of physical lines in last stmt.

        The statement doesn't have to be an interesting statement.  This is
        intended to be called when continuation is C_BACKSLASH.
        r(   éþÿÿÿ)r_   rO   )r	   rO   s     r   Úget_num_lines_in_stmtzParser.get_num_lines_in_stmté  s)   € ð 	�‰ŒØ—N‘Nˆ	Ø˜‰}˜y¨™}Ñ,Ð,r   c                 óÆ  — | j                  «        | j                  t        k(  sJ ‚| j                  }| j                  }||   dv r|dz   }||   dv rŒ|}|j                  d|«      dz   }dx}}||k  rƒ||   }|dv r|dz   }|dz   }ni|dv r|r|dz
  }|dz   }nX|dk(  s|dk(  rt        |||«      j                  «       }n2|d	k(  rn2|dk(  r"|d
k(  r|dk(  s
||dz
     dvr||dz      d
k7  rd}n|dz   }||k  rŒƒ|r |dz   }t        j                  d||| «      du }|s|}||   dvr|dz   }||   dvrŒt        || j                  | j                  | j                  «      «      dz   S )zÒReturn number of spaces the next line should be indented.

        Line continuation must be C_BACKSLASH.  Also assume that the new
        line is the first one following the initial line of the stmt.
        r{   r0   r)   r   rf   rg   rE   rF   rJ   Ú=z=<>!z\s*\\Nre   )ry   rV   rT   r+   ri   rS   rm   rl   ÚreÚmatchr*   r}   r%   )r	   r+   r:   ÚstartposÚendposÚfoundrW   r[   s           r   Úcompute_backslash_indentzParser.compute_backslash_indentó  sÌ  € ð 	�‰ŒØ× Ñ ¤KÒ/Ð/Ð/Ø�y‰yˆØ�O‰OˆØ�1‰g˜ÑØ�!‘ˆAð �1‰g˜Òàˆð —‘˜4 Ó*¨QÑ.ˆØÐˆ�Ø�&ŠjØ�a‘ˆBØ�U‰{Ø ™	�Ø�a‘C‘Ø�u‘ÙØ! A™I�EØ�a‘C‘Ø�s’˜b CšiÜ# D¨!¨VÓ4×8Ñ8Ó:‘Ø�s’ð Ø˜!’  c¢	Ø˜’F˜d 1 Q¡3™i¨vÑ5Ø˜˜!™‘9 Ò#Ø�Øà�a‘C�ð+ �&‹jñ. ð �!‘ˆAÜ—H‘H˜X t¨A¨f ~Ó6¸$Ð>ˆEáð ˆAØ�q‘' Ñ(Ø�a‘C�ð �q‘' Ò(ô �4˜Ÿ™¨Ð*×5Ñ5Ø%)§]¡]ó4ó 5Ø78ñ9ð 	9r   c                 ó´   — | j                  «        | j                  | j                  }}|}| j                  }||k  r||   dv r|dz   }||k  r||   dv rŒ||| S )z`Return the leading whitespace on the initial line of the last
        interesting stmt.
        r{   r0   )ry   ri   rj   r+   )r	   r:   rZ   r~   r+   s        r   Úget_base_indent_stringzParser.get_base_indent_string,  sg   € ð 	�‰ŒØ�‰ §¡ˆ1ˆØˆØ�y‰yˆØ�!Še˜˜Q™ 5Ñ(Ø�A‘ˆAð �!Še˜˜Q™ 5Ò(à�A�aˆyÐr   c                 ó@   — | j                  «        | j                  dk(  S )z<Return True if the last interesting statement opens a block.Ú:)ry   rn   ra   s    r   Úis_block_openerzParser.is_block_opener8  s   € à�‰ŒØ�{‰{˜cÑ!Ð!r   c                 óf   — | j                  «        t        | j                  | j                  «      duS )z=Return True if the last interesting statement closes a block.N)ry   Ú_closerer+   ri   ra   s    r   Úis_block_closerzParser.is_block_closer=  s%   € à�‰ŒÜ˜Ÿ	™	 4§?¡?Ó3¸4Ð?Ð?r   c                 ó:   — | j                  «        | j                  S )zŠReturn bracketing structure of the last interesting statement.

        The returned tuple is in the format defined in _study2().
        )ry   rq   ra   s    r   Úget_last_stmt_bracketingzParser.get_last_stmt_bracketingB  s   € ð
 	�‰ŒØ×#Ñ#Ð#r   N)r   r   r   r&   r.   r<   r?   r_   rb   ry   r�   r„   rŒ   rŽ   r‘   r”   r–   r   r   r   r"   r"   }   sP   „ ò!òò
2òh'òDòL!òy1òv@ò>-ò79òr
ò"ò
@ó
$r   r"   Ú__main__)Úmainzidlelib.idle_test.test_pyparserG   )Ú	verbosity)r   r‡   r1   rN   rT   rQ   rR   rU   ÚcompileÚVERBOSEÚ	MULTILINEÚsearchr3   rˆ   rh   ÚDOTALLrm   r|   r“   rk   Údictr   ÚfromkeysrL   Úupdater"   r   Úunittestr˜   r   r   r   Ú<module>r£      s·  ðñó 
ñ $)¨£8ñ!€ˆÐ)Ø�ið ˆ2�:‰:ð ð& ‡Z�Z�"—,‘,Ñó' ÷& !'¡ð' 	ð. ˆ"�*‰*ð ð ‡Z�Zó	÷ ‘ð	 ð �"—*‘*ð ð  ‡Z�Z�"—)‘)Ñó!÷  #™Uð! ð* ˆ"�*‰*ð ð ‡Z�Zó÷ ‘ð ð ˆ2�:‰:ð 	ð ‡Z�Zó	÷ ‘ð 	ð  �2—:‘:ð à‡Z�Zóç‘ð ô
ˆtô ð" 	×Ñ™% ›* cÓ*€Ø ‡�Ñ/©Ó/Ô /Ø ‡�Ñ/©Ó/Ô /Ø ‡�Ñ2¡zÓ2Ô 2÷K$ñ K$ð\ ˆzÒÝÙÐ	)°QÖ7ð r   