}BFjdZddlmZddlZddlZddlmZddlmZddlm Z ddl m Z m Z ddl mZGd d e ZddZ dddZdddZdddZdS) zToken-related utilities) annotationsN)StringIO) iskeyword) TokenInfo)Callable NamedTuple) GeneratorcBeZdZUded<ded<ded<ded<ded<dS) TokeninttokenstrtextstartendlineN)__name__ __module__ __qualname____annotations__EC:\PYTHON\_runtimes\venv\Lib\site-packages\IPython/utils/tokenutil.pyr r s=JJJ IIIJJJ HHH IIIIIrr readlinerreturn Generator[TokenInfo, None, None]c#lK tj|Ed{VdS#tj$rYdSwxYw)z'wrap generate_tkens to catch EOF errorsN)tokenizegenerate_tokens TokenError)rs rrrsY+H55555555555  s  33extra_errors_to_catchlist[str] | Nonec# Kgd}|t|tsJ||pgz}g} tj|D]}|||VdS#tj$r t fd|Dr^|r6|djd|djdf}|}|dj }ndx}}d}ttj d|||VnYd dSd wwxYw)N)zunterminated string literalzinvalid non-printable characterz!after line continuation characterc36K|]}|jdvVdS)rN)args).0errorexcs r z/generate_tokens_catch_errors..2s.AAu #AAAAAArr)r) isinstancelistrrappendr anyrrrr ERRORTOKEN) rr!default_errors_to_catcherrors_to_catchtokensr rrrr(s @rgenerate_tokens_catch_errorsr5!sa ! (J7Ld,S,S ( ( S-1F1L"MO F-h77  E MM% KKKK        AAAAAAA A A  r (+VBZ^A->>bz$$H/UCFF F F F F  G F F F F F s0AC1,A:C,,C1cellr cursor_posr tuple[str, int]cd}|d}|D]8}|t|z}|ds|dz }||krn|}9d}||fS)aReturn 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. rT r+r,) splitlineslenendswith)r6r7offsetlinesr next_offsets rline_at_cursorrA@s"F OOD ! !E  s4yy( }}T""  1 K  # # E <rcg}g}d}d}ddi}d}d}dtt|jD} | sdStdg| zt j| dgzD]\} \} } | j\} }| j\}}|dz|vrU| j d}t|| dzD]'\}}||vr||dz t|z||<(d}|| }||z|krnJ| j tjkot| j x}r|r8| r6| j tjkr!| jdkr|d d| j|d <n|| j| 7| j tjkr"| jd kr|d d}|s |r|d nd}n`| j tjkrK| jd kr|r||d n"| jd kr|r|d }|||z|kr|| |z|k}n|r |r|d S|r|S|r|d S|r|S|r|d SdS) avGet 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 Nr+rFc g|] }t| Sr)r )r&tups r z#token_at_cursor..ys)"""s """rr,T.r*=())rrrzip itertoolspairwiserrrr; enumerater<r rNAMErrOPr/pop)r6r7names call_namesclosing_call_namemost_recent_outer_nameoffsetsintersects_with_cursorcur_token_is_namer4prev_toktoknext_tok start_line start_colend_lineend_colr?linenorr>s rtoken_at_cursorr`bs0EJ$()-!fG""".x~~/FGG"""F r%( +FdVO<<&&55!/3!$  IG' args4#"""""''''''''%%%%%%J9=>Dfffffffr