§
    ŒŸjŒ  ã                  ót   — d Z ddlmZ ddlmZ ddlmZmZmZ ddl	m
Z
 ddlmZmZ dgZ G d	„ de¦  «        Zd
S )z"
Completer for a regular grammar.
é    )Úannotations)ÚIterable)ÚCompleteEventÚ	CompleterÚ
Completion)ÚDocumenté   )ÚMatchÚ_CompiledGrammarÚGrammarCompleterc                  ó2   — e Zd ZdZdd„Zdd„Zdd„Zdd„ZdS )r   af  
    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.
    Úcompiled_grammarr   Ú
completersúdict[str, Completer]ÚreturnÚNonec                ó"   — || _         || _        d S ©N)r   r   )Úselfr   r   s      ú€/var/www/finuniver-perm.ru/html/student/venv/lib/python3.11/site-packages/prompt_toolkit/contrib/regular_languages/completion.pyÚ__init__zGrammarCompleter.__init__   s   € ð !1ˆÔØ$ˆŒˆˆó    Údocumentr   Úcomplete_eventr   úIterable[Completion]c              #  ó®   K  — | j                              |j        ¦  «        }|r1|                      |                      ||¦  «        ¦  «        E d {V —† d S d S r   )r   Úmatch_prefixÚtext_before_cursorÚ_remove_duplicatesÚ_get_completions_for_match)r   r   r   Úms       r   Úget_completionsz GrammarCompleter.get_completions#   s†   è è € ð Ô!×.Ò.¨xÔ/JÑKÔKˆàð 	Ø×.Ò.Ø×/Ò/°°>ÑBÔBñô ð ð ð ð ð ð ð ð ð ð	ð 	r   Úmatchr
   c           	   #  ó$  K  — |                      ¦   «         D ]ø}|j        }|j        }| j                             |¦  «        }|rÌ|j        }| j                             ||¦  «        }t          |t          |¦  «        ¦  «        }	| 
                    |	|¦  «        D ]v}
|dt          |¦  «        |
j        z   …         |
j        z   }t          | j                             ||¦  «        |t          |j        ¦  «        z
  |
j        |
j        ¬¦  «        V — ŒwŒùdS )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   r#   r   Úmatch_variabler*   r+   Ú	completerr%   Úunwrapped_textr   Ú
completionÚnew_texts               r   r    z+GrammarCompleter._get_completions_for_match-   s<  è è € ð $ŸošoÑ/Ô/ð 	ð 	ˆNØ$Ô,ˆGØ"Ô(ˆEàœ×+Ò+¨GÑ4Ô4ˆIàð Ø%Ô+�ð "&Ô!6×!?Ò!?ÀÈÑ!NÔ!N�õ $ NµC¸Ñ4GÔ4GÑHÔH�ð #,×";Ò";¸HÀnÑ"UÔ"Uð ð �Jà&Ð'N­¨T©¬°ZÔ5NÑ)NÐ'NÔOØ$œ/ñ*ð õ %Ø!Ô2×9Ò9¸'À8ÑLÔLØ',­s°5´<Ñ/@Ô/@Ñ'@Ø *Ô 2Ø%/Ô%<ð	ñ ô ð ð ð ð øð/	ð 	r   Úitemsc              #  óˆ   K  — dd„}t          ¦   «         }|D ]*} ||¦  «        }||vr|                     |¦  «         |V — Œ+dS )zÇ
        Remove duplicates, while keeping the order.
        (Sometimes we have duplicates, because the there several matches of the
        same grammar, each yielding similar completions.)
        r5   r   r   útuple[str, int]c                ó   — | j         | j        fS r   )r%   r&   )r5   s    r   Úhash_completionz<GrammarCompleter._remove_duplicates.<locals>.hash_completionZ   s   € Ø”? JÔ$=Ð=Ð=r   N)r5   r   r   r9   )ÚsetÚadd)r   r7   r;   Úyielded_so_farr5   Ú
hash_values         r   r   z#GrammarCompleter._remove_duplicatesS   sy   è è € ð	>ð 	>ð 	>ð 	>õ 03©u¬uˆàð 	!ð 	!ˆJØ(˜¨Ñ4Ô4ˆJà Ð/Ð/Ø×"Ò" :Ñ.Ô.Ð.Ø Ð Ð Ð øð	!ð 	!r   N)r   r   r   r   r   r   )r   r   r   r   r   r   )r#   r
   r   r   r   r   )r7   r   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r"   r    r   © r   r   r   r      so   € € € € € ðð ð%ð %ð %ð %ðð ð ð ð$ð $ð $ð $ðL!ð !ð !ð !ð !ð !r   N)rC   Ú
__future__r   Útypingr   Úprompt_toolkit.completionr   r   r   Úprompt_toolkit.documentr   Úcompilerr
   r   Ú__all__r   rD   r   r   ú<module>rK      sÇ   ððð ð #Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ð Ð à JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ JØ ,Ð ,Ð ,Ð ,Ð ,Ð ,à -Ð -Ð -Ð -Ð -Ð -Ð -Ð -ð ð€ð
Q!ð Q!ð Q!ð Q!ð Q!�yñ Q!ô Q!ð Q!ð Q!ð Q!r   