
    |tf                         d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddl	m
Z
mZ  edg d	      Zd
 Z	 ddee
e      fdZddZddedefdZy)zToken-related utilities    )
namedtuple)StringIO)	iskeywordN)	TokenInfo)ListOptionalToken)tokentextstartendlinec              #   |   K   	 t        j                  |       D ]  }|  y# t         j                  $ r Y yw xY ww)z'wrap generate_tkens to catch EOF errorsN)tokenizegenerate_tokens
TokenError)readliner
   s     a/var/www/html/software/conda/envs/higlass/lib/python3.12/site-packages/IPython/utils/tokenutil.pyr   r      sA     --h7 	EK	 s   <# <9<9<extra_errors_to_catchc              #     	K   g d}|t        |t              sJ ||xs g z   }g }	 t        j                  |       D ]  }|j	                  |       |  y # t        j
                  $ r	t        	fd|D              rh|r6|d   j                  d   |d   j                  d   f}|}|d   j                  }ndx}}d}t        j                  t        j                  d|||       n Y d 		y d 		ww xY ww)N)zunterminated string literalzinvalid non-printable characterz!after line continuation characterc              3   @   K   | ]  }|j                   d    v   yw)r   N)args).0errorexcs     r   	<genexpr>z/generate_tokens_catch_errors.<locals>.<genexpr>,   s     Au#As   r   )   r    )
isinstancelistr   r   appendr   anyr   r   r   r   
ERRORTOKEN)
r   r   default_errors_to_catcherrors_to_catchtokensr
   r   r   r   r   s
            @r   generate_tokens_catch_errorsr(      s    
 !(J7Ld,SSS-1F1L"MO F--h7 	EMM% K	  AAAr
((+VBZ^^A->>bz$$$$X%8%8"eS$OO  Ps/   $C5/A C5C2+A=C-(C5-C22C5c                     d}| j                  d      }|D ]2  }|t        |      z   }|j                  d      s|dz  }||kD  r ||fS |}4 d}||fS )a  Return the line in a cell at a given cursor position

    Used for calling line-based APIs that don't support multi-line input, yet.

    Parameters
    ----------
    cell : str
        multiline block of text
    cursor_pos : integer
        the cursor position

    Returns
    -------
    (line, offset): (string, integer)
        The line with the current cursor, and the character offset of the start of the line.
    r   T
r   r   )
splitlineslenendswith)cell
cursor_posoffsetlinesr   next_offsets         r   line_at_cursorr3   :   s{    " FOOD!E s4y(}}T" 1K# &>  &>    r.   r/   c                 .   g }g }g }ddi}t        t        |       j                        D ]  }t        | }|j                  \  }}	|j
                  \  }
}|
dz   |vrN|j                  j                  d      }t        ||dz         D ]!  \  }}||vs||dz
     t        |      z   ||<   # ||   }|	dk(  r|dz   n|}||	z   |k\  r nD|j                  t        j                  k(  rt        |j                        sj|rL|rJ|d   j                  t        j                  k(  r*|d   j                  dk(  r|d   d|j                  |d<   n|j!                  |j                         n|j                  t        j                  k(  rj|j                  dk(  r|r|j#                  d       |j                  dk(  r|r|j!                  |d          n"|j                  dk(  r|r|j#                  d       |j!                  |       ||
   |z   |kD  s n |r|d   S |r|d   S y	)
av  Get the token at a given cursor

    Used for introspection.

    Function calls are prioritized, so the token for the callable will be returned
    if the cursor is anywhere inside the call.

    Parameters
    ----------
    cell : str
        A block of Python code
    cursor_pos : int
        The location of the cursor in the block where the token should be found
    r   r   Tr   .=()r   )r   r   r   r	   r   r   r   r+   	enumerater,   r
   r   NAMEr   r   OPr"   pop)r.   r/   namesr'   
call_namesoffsetstuptok
start_line	start_colend_lineend_colr1   linenor   r0   boundarys                    r   token_at_cursorrI   \   s     EFJ!fGx~667 )Sk !$		
IGG'a<w&HH''-E )%a @ D(&-fQh&7#d)&CGFOD $%.!^:>I) 99%i.AF2J$4$4$Cr
[^H^',Ry#((;b	SXX&YY(++%xx35		"xx35!!%),SZr"c8w&3S)V "~	Ryr4   )N)r   )__doc__collectionsr   ior   keywordr   r   r   typingr   r   r	   r   strr(   r3   intrI    r4   r   <module>rR      sh    
 #     ! 	7EF <@%-d3i%8>DD# D3 Dr4   