
    ^hW                    x    S r SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
  SSKJr  SS	KJr  S
/r " S S
\5      rg)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                  L    \ rS rSrSr  S       S	S jjrS
S jrSS jrSrg)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`.
Nc                <    Xl         X l        U=(       d    0 U l        g Ncompiled_grammardefault_stylelexers)selfr   r   r   s       h/home/james-whalen/.local/lib/python3.13/site-packages/prompt_toolkit/contrib/regular_languages/lexer.py__init__GrammarLexer.__init__%   s     !1*l    c                t   U R                   R                  U5      nU(       Ga  U Vs/ s H  o0R                  U4PM     nnUR                  5        GH  nU R                  R                  UR                  5      nU(       d  M2  [        XR                  UR                   5      nUR                  U5      n/ n	[        [        UR                  5      5       H+  n
U	R                  U" U
5      5        U	R                  S5        M-     U	(       a  U	R!                  5         UR                  n
U	 H3  tpnU H(  nXJ   S   U R                  :X  a  XU
   S   4XJ'   U
S-  n
M*     M5     GM     UR#                  5       nU(       a2  [        UR                  UR                  5       H  n
SXJ   S   4XJ'   M     U$ SU4/$ s  snf )N) 
r   r	   zclass:trailing-inputr   )r   match_prefixr   	variablesr   getvarnamer   startstoplex_documentrangelenlinesextendappendpoptrailing_input)r   textmc
charactersvlexerdocumentlexer_tokens_for_linetext_fragmentsits_r)   s                  r   _get_text_fragments GrammarLexer._get_text_fragments/   s   !!..t4OS-Tt!/A/A1.EtJ-T[[] 		25'WWqvv(>?H,1,>,>x,H)9;N"3x~~#67&--.CA.FG&--j9 8 &&**,A$2q!"A)}Q/43E3EE12qM!4D0E
FA "# %3! #. --/N~33^5H5HIA%;Z]1=M$NJM J J<A .Us   F5c                r   ^ [        [        U R                  UR                  5      5      5      mSU4S jjnU$ )Nc                4   >  TU    $ ! [          a    / s $ f = fr   )
IndexError)linenor%   s    r   get_line+GrammarLexer.lex_document.<locals>.get_lineX   s&    V}$ 	s    )r<   intreturnr   )listr   r7   r*   )r   r0   r=   r%   s      @r   r"   GrammarLexer.lex_documentU   s-    [!9!9(--!HIJ	 r   r   )r   N)r   r
   r   strr   zdict[str, Lexer] | Noner@   None)r*   rC   r@   r   )r0   r   r@   z#Callable[[int], StyleAndTextTuples])	__name__
__module____qualname____firstlineno____doc__r   r7   r"   __static_attributes__ r   r   r   r      sE    "  *.	#*# # (	#
 
#$ L	r   N)rI   
__future__r   typingr   prompt_toolkit.documentr   "prompt_toolkit.formatted_text.baser   #prompt_toolkit.formatted_text.utilsr   prompt_toolkit.lexersr   compilerr
   __all__r   rK   r   r   <module>rT      s;   
 #  , A ; ' & 
H5 Hr   