U
    ouf-	                     @  s   d Z ddlmZ ddlmZmZ ddlmZmZ ddl	m
Z
 ddlmZ ddd	gZG d
d dedZG dd deZG dd	 d	eZdS )z)
Base classes for prompt_toolkit lexers.
    )annotations)ABCMetaabstractmethod)CallableHashable)Document)StyleAndTextTuplesLexerSimpleLexerDynamicLexerc                   @  s2   e Zd ZdZedddddZddd	d
ZdS )r	   z$
    Base class for all lexers.
    r   #Callable[[int], StyleAndTextTuples]documentreturnc                 C  s   dS )aT  
        Takes a :class:`~prompt_toolkit.document.Document` and returns a
        callable that takes a line number and returns a list of
        ``(style_str, text)`` tuples for that line.

        XXX: Note that in the past, this was supposed to return a list
             of ``(Token, text)`` tuples, just like a Pygments lexer.
        N )selfr   r   r   >/tmp/pip-unpacked-wheel-8milen2s/prompt_toolkit/lexers/base.pylex_document   s    zLexer.lex_documentr   r   c                 C  s   t | S )zz
        When this changes, `lex_document` could give a different output.
        (Only used for `DynamicLexer`.)
        )id)r   r   r   r   invalidation_hash#   s    zLexer.invalidation_hashN)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r	      s   
)	metaclassc                   @  s2   e Zd ZdZddddddZdd	d
ddZdS )r
   z
    Lexer that doesn't do any tokenizing and returns the whole input as one
    token.

    :param style: The style string for this lexer.
     strNone)styler   c                 C  s
   || _ d S N)r   )r   r   r   r   r   __init__3   s    zSimpleLexer.__init__r   r   r   c                   s    |j  ddd fdd}|S )Nintr   )linenor   c                   s0   zj  |  fgW S  tk
r*   g  Y S X dS )z%Return the tokens for the given line.N)r   
IndexError)r#   linesr   r   r   get_line9   s    z*SimpleLexer.lex_document.<locals>.get_line)r&   )r   r   r'   r   r%   r   r   6   s    zSimpleLexer.lex_documentN)r   )r   r   r   r   r!   r   r   r   r   r   r
   +   s   c                   @  s>   e Zd ZdZdddddZddd	d
dZddddZdS )r   z
    Lexer class that can dynamically returns any Lexer.

    :param get_lexer: Callable that returns a :class:`.Lexer` instance.
    zCallable[[], Lexer | None]r   )	get_lexerr   c                 C  s   || _ t | _d S r    )r(   r
   _dummy)r   r(   r   r   r   r!   J   s    zDynamicLexer.__init__r   r   r   c                 C  s   |   p| j}||S r    )r(   r)   r   )r   r   lexerr   r   r   r   N   s    zDynamicLexer.lex_documentr   r   c                 C  s   |   p| j}t|S r    )r(   r)   r   )r   r*   r   r   r   r   R   s    zDynamicLexer.invalidation_hashN)r   r   r   r   r!   r   r   r   r   r   r   r   C   s   N)r   
__future__r   abcr   r   typingr   r   Zprompt_toolkit.documentr   Z"prompt_toolkit.formatted_text.baser   __all__r	   r
   r   r   r   r   r   <module>   s   