
    ^h                    l    S r SSKJr  SSKJr  SSKJrJrJr  SSK	J
r
  SSKJrJr  S/r " S	 S\5      rg
)z"
Completer for a regular grammar.
    )annotations)Iterable)CompleteEvent	Completer
Completion)Document   )Match_CompiledGrammarGrammarCompleterc                  d    \ rS rSrSr      S	S jr      S
S jr      SS jrSS jrSr	g)r      aN  
Completer which can be used for autocompletion according to variables in
the grammar. Each variable can have a different autocompleter.

:param compiled_grammar: `GrammarCompleter` instance.
:param completers: `dict` mapping variable names of the grammar to the
                   `Completer` instances to be used for each variable.
c                    Xl         X l        g Ncompiled_grammar
completers)selfr   r   s      m/home/james-whalen/.local/lib/python3.13/site-packages/prompt_toolkit/contrib/regular_languages/completion.py__init__GrammarCompleter.__init__   s     !1$    c              #     #    U R                   R                  UR                  5      nU(       a)  U R                  U R	                  X25      5       S h  vN   g g  N7fr   )r   match_prefixtext_before_cursor_remove_duplicates_get_completions_for_match)r   documentcomplete_eventms       r   get_completions GrammarCompleter.get_completions#   sV      !!..x/J/JK..//B   s   AAAAc           	   #  P  #    UR                  5        GH  nUR                  nUR                  nU R                  R	                  U5      nU(       d  M@  UR
                  nU R                  R                  XG5      n[        U[        U5      5      n	UR                  X5       H|  n
US[        U5      U
R                  -    U
R                  -   n[        U R                  R                  XK5      U[        UR                  5      -
  U
R                   U
R"                  S9v   M~     GM     g7f)z
Yield all the possible completions for this input string.
(The completer assumes that the cursor position was at the end of the
input string.)
N)textstart_positiondisplaydisplay_meta)	end_nodesvarnamestartr   getvaluer   unescaper   lenr!   r%   r$   r   escapestringr&   r'   )r   matchr   match_variabler)   r*   	completerr$   unwrapped_textr   
completionnew_texts               r   r   +GrammarCompleter._get_completions_for_match-   s     $oo/N$,,G"((E++G4Iy%++ "&!6!6!?!?!N $NC4GH #,";";H"UJ&'NTZ5N5N)NO$//*  %!2299'L',s5<</@'@ * 2 2%/%<%<	  #V! 0s   AD&CD&c              #     #    SS jn[        5       nU H'  nU" U5      nXS;  d  M  UR                  U5        Uv   M)     g7f)z
Remove duplicates, while keeping the order.
(Sometimes we have duplicates, because the there several matches of the
same grammar, each yielding similar completions.)
c                2    U R                   U R                  4$ r   )r$   r%   )r5   s    r   hash_completion<GrammarCompleter._remove_duplicates.<locals>.hash_completionZ   s    ??J$=$===r   N)r5   r   returnztuple[str, int])setadd)r   itemsr:   yielded_so_farr5   
hash_values         r   r   #GrammarCompleter._remove_duplicatesS   sA     	> 03uJ(4J/"":.    s
    A A r   N)r   r   r   zdict[str, Completer]r<   None)r   r   r   r   r<   Iterable[Completion])r1   r
   r   r   r<   rD   )r?   rD   r<   rD   )
__name__
__module____qualname____firstlineno____doc__r   r!   r   r   __static_attributes__ r   r   r   r      sd    % 0%>R%	% 2?	$$,9$	$L!r   N)rI   
__future__r   typingr   prompt_toolkit.completionr   r   r   prompt_toolkit.documentr   compilerr
   r   __all__r   rK   r   r   <module>rR      s8    #  J J , - 
Q!y Q!r   