
                         V    S r SSKJr  SSKJrJr  SSKJr  SSKJ	r	  Sr
 " S S	\5      rg
)z"
Completer for a regular grammar.
    )unicode_literals)	Completer
Completion)Document   )_CompiledGrammar)GrammarCompleterc                   0    \ rS rSrSrS rS rS rS 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    [        U[        5      (       d   e[        U[        5      (       d   eXl        X l        g N)
isinstancer   dictcompiled_grammar
completers)selfr   r   s      Flib/third_party/prompt_toolkit/contrib/regular_languages/completion.py__init__GrammarCompleter.__init__   s5    *,<====*d++++ 0$    c              #      #    U R                   R                  UR                  5      nU(       a.  U R                  U R	                  X25      5      nU H  nUv   M	     g g 7fr   )r   match_prefixtext_before_cursor_remove_duplicates_get_completions_for_match)r   documentcomplete_eventmcompletionscs         r   get_completions GrammarCompleter.get_completions    sY     !!..x/J/JK11//BDK ! !	 s   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-.Ts4y:;T;T/TUXbXgXggH %!2299'L',s5<</@'@ * 2 2%/%<%<	> >	 #V! 0s   AD&CD&c                 L    / nU H  nX2;  d  M
  UR                  U5        M     U$ )z
Remove duplicates, while keeping the order.
(Sometimes we have duplicates, because the there several matches of the
same grammar, each yielding similar completions.)
)append)r   itemsresultis       r   r   #GrammarCompleter._remove_duplicatesJ   s+     Aa   r   )r   r   N)
__name__
__module____qualname____firstlineno____doc__r   r!   r   r   __static_attributes__ r   r   r	   r	      s    %>@
r   r	   N)rB   
__future__r   prompt_toolkit.completionr   r   prompt_toolkit.documentr   compilerr   __all__r	   rD   r   r   <module>rJ      s-    ( ; , &
Dy Dr   