
    ^h                         S r SSKJr  SSKJr  SSKJr  SSKrSSKJr  SSK	J
r
Jr  \" S/ S	Q5      rS
 r SS\\
\      4S jjrSS jrSS\S\4S jjrg)zToken-related utilities    )
namedtuple)StringIO)	iskeywordN)	TokenInfo)ListOptionalToken)tokentextstartendlinec              #      #     [         R                  " U 5       H  nUv   M	     g! [         R                   a     gf = f7f)z'wrap generate_tkens to catch EOF errorsN)tokenizegenerate_tokens
TokenError)readliner
   s     Q/home/james-whalen/.local/lib/python3.13/site-packages/IPython/utils/tokenutil.pyr   r      s;     --h7EK 8 s    A !& A =A =A extra_errors_to_catchc              #     ^	#    / SQnUb  [        U[        5      (       d   eX!=(       d    / -   n/ n [        R                  " U 5       H  nUR	                  U5        Uv   M     g ! [        R
                   a  m	[        U	4S jU 5       5      (       ap  U(       a6  US   R                  S   US   R                  S   4nUnUS   R                  nOS=pgSn[        R                  " [        R                  SXgU5      v    S m	@	g e S m	@	ff = f7f)N)zunterminated string literalzinvalid non-printable characterz!after line continuation characterc              3   F   >#    U  H  oTR                   S    ;   v   M     g7f)r   N)args).0errorexcs     r   	<genexpr>/generate_tokens_catch_errors.<locals>.<genexpr>,   s     A#s   !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S-1L"MO F--h7EMM% K 8  AAAAr
((+VBZ^^A->>bz$$$$X%8%8"e$OO s5   .D2A% $D%D	9BD>DDD		Dc                     SnU R                  S5      nU H7  nU[        U5      -   nUR                  S5      (       d  US-  nXQ:  a    XB4$ UnM9     SnXB4$ )ax  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_cursorr4   :   ss    " FOOD!Es4y(}}T"" 1K# >   >    r/   r0   c                    / n/ n/ nSS0n[        [        U 5      R                  5       GH  n[        U6 nUR                  u  pUR
                  u  pU
S-   U;  aN  UR                  R                  S5      n[        XS-   5       H!  u  pX;  d  M  X]S-
     [        U5      -   X]'   M#     XX   nU	S:X  a  US-   OUnX-   U:  a    GOmUR                  [        R                  :X  a  [        UR                  5      (       dx  U(       aU  U(       aN  US   R                  [        R                  :X  a-  US   R                  S:X  a  US   < SUR                  < 3US'   OUR!                  UR                  5        OUR                  [        R                  :X  a|  UR                  S:X  a  U(       a  UR#                  S5        UR                  S:X  a  U(       a  UR!                  US   5        O(UR                  S:X  a  U(       a  UR#                  S5        UR!                  U5        XZ   U-   U:  d  GM    O   U(       a  US   $ U(       a  US   $ g	)
aN  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/   r0   namesr(   
call_namesoffsetstuptok
start_line	start_colend_lineend_colr2   linenor   r1   boundarys                    r   token_at_cursorrJ   \   s    EFJ!fGx~667Sk !$		
GGa<w&HH''-E )%a @(&-Qh&7#d)&CGO !A $%.!^:>) 99%i.A.AF2J$4$4$Cr
[^H^',Ry#((;b	SXX&YY(++%xx35		"xx35!!%),SZr"cw&3S 8V "~	Ryr5   )N)r   )__doc__collectionsr   ior   keywordr   r   r   typingr   r   r	   r   strr)   r4   intrJ    r5   r   <module>rS      sh    
 #     ! 	7EF <@%-d3i%8>DD# D3 Dr5   