
                         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"
Validator for a regular langage.
    )unicode_literals)	ValidatorValidationError)Document   )_CompiledGrammar)GrammarValidatorc                   $    \ rS rSrSrS rS rSrg)r	      aB  
Validator which can be used for validation according to variables in
the grammar. Each variable can have its own validator.

:param compiled_grammar: `GrammarCompleter` instance.
:param validators: `dict` mapping variable names of the grammar to the
                   `Validator` 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
validators)selfr   r   s      Flib/third_party/prompt_toolkit/contrib/regular_languages/validation.py__init__GrammarValidator.__init__   s5    *,<====*d++++ 0$    c                 H   U R                   R                  UR                  5      nU(       a  UR                  5        H  nU R                  R                  UR                  5      nU(       d  M1  U R                   R                  UR                  UR                  5      n[        U[        U5      5      n UR                  U5        M     g [        [        UR                  5      SS9e! [         a0  n[        UR                  UR                  -   UR                  S9eS nAff = f)N)cursor_positionmessagezInvalid command)r   matchtext	variablesr   getvarnameunescapevaluer   lenvalidater   startr   r   )r   documentmv	validatorunwrapped_textinner_documentes           r   r!   GrammarValidator.validate    s     !!''6[[] OO//		:	9%)%:%:%C%CAIIqww%WN &.nc.>Q%RN/!**>: #" "#hmm2D*;= = + /-,-GGa6G6G,G$%II/ //s   4C''
D!1+DD!)r   r   N)__name__
__module____qualname____firstlineno____doc__r   r!   __static_attributes__ r   r   r	   r	      s    %=r   r	   N)r/   
__future__r   prompt_toolkit.validationr   r   prompt_toolkit.documentr   compilerr   __all__r	   r1   r   r   <module>r7      s+    ( @ , &
)=y )=r   