
    MhW                        d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ dd	lmZ d
gZ G d d
e          ZdS )z
`GrammarLexer` is compatible with other lexers and can be used to highlight
the input using a regular grammar with annotations.
    )annotations)Callable)Document)StyleAndTextTuples)split_lines)Lexer   )_CompiledGrammarGrammarLexerc                  0    e Zd ZdZ	 	 dddZddZddZdS )r   a  
    Lexer which can be used for highlighting of fragments according to variables in the grammar.

    (It does not actual lexing of the string, but it exposes an API, compatible
    with the Pygments lexer class.)

    :param compiled_grammar: Grammar as returned by the `compile()` function.
    :param lexers: Dictionary mapping variable names of the regular grammar to
                   the lexers that should be used for this part. (This can
                   call other lexers recursively.) If you wish a part of the
                   grammar to just get one fragment, use a
                   `prompt_toolkit.lexers.SimpleLexer`.
     Ncompiled_grammarr
   default_stylestrlexersdict[str, Lexer] | NonereturnNonec                4    || _         || _        |pi | _        d S N)r   r   r   )selfr   r   r   s       n/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/prompt_toolkit/contrib/regular_languages/lexer.py__init__zGrammarLexer.__init__%   s#     !1*l    textr   c                8     j                             |          }|rx fd|D             }|                                D ]} j                            |j                  }|rt          ||j        |j                           }|	                    |          }g }t          t          |j                            D ]5}	|                     ||	                     |                    d           6|r|                                 |j        }	|D ]9^}
}}|D ]1}||	         d          j        k    r|
||	         d         f||	<   |	dz  }	2:|                                }|r0t          |j        |j                  D ]}	d||	         d         f||	<   |S d|fgS )Nc                "    g | ]}j         |fS  )r   ).0cr   s     r   
<listcomp>z4GrammarLexer._get_text_fragments.<locals>.<listcomp>3   s!    -T-T-T!t/A1.E-T-T-Tr   )r   
r   r	   zclass:trailing-inputr   )r   match_prefix	variablesr   getvarnamer   startstoplex_documentrangelenlinesextendappendpopr   trailing_input)r   r   m
charactersvlexerdocumentlexer_tokens_for_linetext_fragmentsits_r    r0   s   `              r   _get_text_fragmentsz GrammarLexer._get_text_fragments/   s   !..t44 !	 -T-T-T-Tt-T-T-TJ[[]] # # 	22 #'QWqv-=(>??H,1,>,>x,H,H)9;N"3x~#6#677 : :&--.C.CA.F.FGGG&--j9999% -&**,,,A$2 # #1q!" # #A)!}Q/43EEE12JqM!4D0E
1FAA# --//N O~3^5HII O OA%;Z]1=M$NJqMMJ<r   r5   r   #Callable[[int], StyleAndTextTuples]c                |    t          t          |                     |j                                      dfd}|S )Nlinenointr   r   c                :    	 |          S # t           $ r g cY S w xY wr   )
IndexError)r?   r,   s    r   get_linez+GrammarLexer.lex_document.<locals>.get_lineX   s6    V}$   			s    )r?   r@   r   r   )listr   r<   r   )r   r5   rC   r,   s      @r   r)   zGrammarLexer.lex_documentU   sM    [!9!9(-!H!HIIJJ	 	 	 	 	 	 r   )r   N)r   r
   r   r   r   r   r   r   )r   r   r   r   )r5   r   r   r=   )__name__
__module____qualname____doc__r   r<   r)   r   r   r   r   r      sh         "  *.	# # # # #$  $  $  $ L	 	 	 	 	 	r   N)rH   
__future__r   typingr   prompt_toolkit.documentr   "prompt_toolkit.formatted_text.baser   #prompt_toolkit.formatted_text.utilsr   prompt_toolkit.lexersr   compilerr
   __all__r   r   r   r   <module>rQ      s    
 # " " " " "       , , , , , , A A A A A A ; ; ; ; ; ; ' ' ' ' ' ' & & & & & & 
H H H H H5 H H H H Hr   