
                         V    d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 dZ
 G d d	e      Zy
)z"
Validator for a regular langage.
    )unicode_literals)	ValidatorValidationError)Document   )_CompiledGrammar)GrammarValidatorc                       e Zd ZdZd Zd Zy)r	   aZ  
    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                 h    t        |t              sJ t        |t              sJ || _        || _        y )N)
isinstancer   dictcompiled_grammar
validators)selfr   r   s      Flib/third_party/prompt_toolkit/contrib/regular_languages/validation.py__init__zGrammarValidator.__init__   s3    *,<===*d+++ 0$    c                 8   | j                   j                  |j                        }|r|j                         D ]  }| j                  j                  |j                        }|s+| j                   j                  |j                  |j                        }t        |t        |            }	 |j                  |        y t        t        |j                        d      # t        $ r3}t        |j                  |j                  z   |j                        d }~ww xY w)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   zGrammarValidator.validate    s     !!''6[[] OO//		:	%)%:%:%C%CAIIqww%WN &.nc.>Q%RN/!**>: #" "#hmm2D*;= = + /-,-GGa6G6G,G$%II/ //s   )C	D&.DDN)__name__
__module____qualname____doc__r   r    r   r   r	   r	      s    %=r   r	   N)r+   
__future__r   prompt_toolkit.validationr   r   prompt_toolkit.documentr   compilerr   __all__r	   r,   r   r   <module>r2      s+    ( @ , &
)=y )=r   