� K�g�+����ddlmZmZddlmZmZmZmZmZm Z m Z m Z m Z m Z mZmZerddlmZddlmZddlmZGd�de��ZGd �d ee��Zd"d efd �ZGd�de��ZGd�de��ZGd�de��Zed��ZGd�de��ZGd�dee��Z Gd�dee��Z!Gd�dee��Z"Gd�de��Z#Gd�d e��Z$d!S)#�)�logger�NO_VALUE�) �Mapping�Iterable�Callable�Union�TypeVar�Tuple�Any�List�Set�Optional� Collection� TYPE_CHECKING��Token)�InteractiveParser)�Treec��eZdZdS)� LarkErrorN��__name__� __module__� __qualname__���_/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/lark/exceptions.pyrr ��������Drrc��eZdZdS)�ConfigurationErrorNrrrrr!r!rrr!�Got %r, expected one of %s�optionsc�6�||vrt|||fz���dS�N)r!)�valuer#�msgs r� assert_configr(s-�� �G��� ���w�'7�!7�8�8�8��rc��eZdZdS)� GrammarErrorNrrrrr*r*rrr*c��eZdZdS)� ParseErrorNrrrrr,r,rrr,c��eZdZdS)�LexErrorNrrrrr.r. rrr.�Tc ���eZdZUdZeed<eed<dZeed<dZded<dd e d ed e fd �Z dddde e e ee feee ee ffdeded ee f d�Zd�ZdS)�UnexpectedInputa�UnexpectedInput Error. Used as a base class for the following exceptions: - ``UnexpectedCharacters``: The lexer encountered an unexpected string - ``UnexpectedToken``: The parser received an unexpected token - ``UnexpectedEOF``: The parser expected a token, but the input ended After catching one of these exceptions, you may call the following helper methods to create a nicer error message. �line�columnN�stater�interactive_parser�(�text�span�returnc��|j� J|���|j}t||z d��}||z}t|t��sx|||��dd��d}|||��dd��d}||zdzdt |�����zzdzS|||��dd��d}|||��dd��d}||zdzd t |�����zzd z�d d ��S) aReturns a pretty string pinpointing the error in the text, with span amount of context characters around it. Note: The parser doesn't hold a copy of the text it has to parse, so you have to provide it again Nr� r������ z^ � � s^ �ascii�backslashreplace) � pos_in_stream�max� isinstance�bytes�rsplit�split�len� expandtabs�decode)�selfr7r8�pos�start�end�before�afters r� get_contextzUnexpectedInput.get_context7sP���!�-�-�t�-�-�-�� ���C�$�J��"�"���D�j���$��&�&� {��%��)�_�+�+�D�!�4�4�R�8�F���S��M�'�'��a�0�0��3�E��E�>�D�(�3��V�5F�5F�5H�5H�1I�1I�+I�I�E�Q� Q��%��)�_�+�+�E�1�5�5�b�9�F���S��M�'�'��q�1�1�!�4�E��U�N�U�*�T�C��8I�8I�8K�8K�4L�4L�-L�L�v�U�]�]�^e�gy�z�z� zrFT�parse_fnzCallable[[str], Tree]�examples�token_type_match_fallback� use_acceptsc ��|j� Jd���t|t��r|���}d}t |��D�]�\}\}}t|t ��r Jd���t |��D�]\} } || ���#t $�r`} | j|jk�rD|rjt|t��rUt| t��r@| j|jkr0tj d|j|j| j|| fz��Yd} ~ ��t|ttf��r�t| ttf��ry| j |j kr&tj d|�d| �d���|cYd} ~ ccS|rA| j j |j j kr'|d stj d |�d| �d���|d f}|d �tj d |�d| �d���|df}Yd} ~ ��yd} ~ wwxYw���|d S)a�Allows you to detect what's wrong in the input text by matching against example errors. Given a parser instance and a dictionary mapping some label with some malformed syntax examples, it'll return the label for the example that bests matches the current error. The function will iterate the dictionary until it finds a matching error, and return the corresponding value. For an example usage, see `examples/error_reporting_lalr.py` Parameters: parse_fn: parse function (usually ``lark_instance.parse``) examples: dictionary of ``{'example_string': value}``. use_accepts: Recommended to keep this as ``use_accepts=True``. Nz Not supported for this exception)NFzExpecting a listzCDifferent accepts with same state[%d]: %s != %s at example [%s][%s]zExact Match at example [z][�]r<z Token Type Fallback at example [TrzSame State match at example [F)r4rDr�items� enumerate�strr1�UnexpectedToken�acceptsr�debug� UnexpectedEOF�token�type) rKrRrSrTrU� candidate�i�label�example�j� malformed�uts r�match_exampleszUnexpectedInput.match_examplesLs��*�z�%�%�'I�%�%�%� �h�� (� (� (��~�~�'�'�H�!� �#,�X�#6�#6�! 5�! 5� �A���w�!�'�3�/�/� C� C�1C� C� C�/� )�'� 2� 2� 5� 5� ��9�5��H�Y�'�'�'�'��&�5�5�5��x�4�:�-�-�'�%� *�4�� A� A�%�!+�2�� ?� ?�%�!#� �d�l� :� :�"�L�)n�*.�*�d�l�B�J�PQ�ST�)U�*V�W�W�W�$�H�H�H�H�&�t�o�}�-M�N�N� <� *�2���/O� P� P� <� "�x�4�:�5�5� &� � �RS�RS�RS�UV�UV�UV�-W� X� X� X�',� � � � � � � � � � �8�<�$&�H�M�T�Z�_�$D�$D�i�XZ�m�$D�$*�L�L�^_�^_�^_�ab�ab�ab�1c�$d�$d�$d�05�t� �I�$�Q�<�/�"�L�L�ST�ST�ST�VW�VW�VW�)X�Y�Y�Y�(-�u� �I����������75���� 5�@��|�s-� B� H�!A8G<�A$G<�H� A*G<�<Hc�l��|jr|j��fd�|D��}dd�|��zS)Nc�P��g|]"}|�vr�|���n|��#Sr)� user_repr)�.0�t_name�ds �r� <listcomp>z4UnexpectedInput._format_expected.<locals>.<listcomp>�s6���`�`�`�V��1����&� �+�+�-�-�-�&�`�`�`rzExpected one of: * %s z * )�_terminals_by_name�join)rK�expectedrns @r�_format_expectedz UnexpectedInput._format_expected�sH��� � "� a��'�A�`�`�`�`�W_�`�`�`�H�,�x�}�}�X�/F�/F�F�Fr)r6)FT)rrr�__doc__�int�__annotations__rBr rprZrQr rr/rr �boolrrhrsrrrr1r1%s!������� � � �I�I�I� �K�K�K��M� �J�J�J���+�+�+�+�{�{��{�3�{�c�{�{�{�{�.>C�/3�>�>�'>�>�',�W�Q��� �5E�-F��QV�WX�Zb�cf�Zg�Wg�Qh�Hi�-i�'j�>�8<�>�+/�>�'�q�k� >�>�>�>�@G�G�G�G�Grr1c�6��eZdZUdZded<d�fd� Zd�Z�xZS)r^zcAn exception that is raised by the parser, when the input ends while it still expects a token. z List[Token]rrNc����tt|�����||_||_ddlm}|dd��|_d|_d|_ d|_ ||_ dS)Nrrz<EOF>�r<) �superr^�__init__rrr4�lexerrr_rBr2r3rp)rKrrr4�terminals_by_namer� __class__s �rr|zUnexpectedEOF.__init__�sv��� �m�T�"�"�+�+�-�-�-� �� ��� � � � � � � ��U�7�B�'�'�� ������ ��� �"3����rc�D�d}||�|j��z }|S)NzUnexpected end-of-input. )rsrr�rK�messages r�__str__zUnexpectedEOF.__str__�s&��-���4�(�(���7�7�7���r)NN)rrrrtrvr|r�� __classcell__�rs@rr^r^�sd�������������� 4� 4� 4� 4� 4� 4�������rr^c�\��eZdZUdZeeed<eeed< d�fd� Zd�Z �xZ S)�UnexpectedCharactersz~An exception that is raised by the lexer, when it cannot match the next string of characters to any of its terminals. �allowed�considered_tokensNc ���tt|�����||_||_||_||_| |_||_||_ | |_ ||_ t|t��r'|||dz��dd��|_n |||_|�|��|_dS)Nrr@rA)r{r�r|r2r3rBr4rpr�r��considered_rules� token_historyrDrErJ�charrQ�_context) rK�seq�lex_posr2r3r�r�r4r�r~r�rs �rr|zUnexpectedCharacters.__init__�s���� �"�D�)�)�2�2�4�4�4��� ��� �$����� �"3����� �!2��� 0���*��� �c�5� !� !� %��G�G�a�K�/�0�7�7��AS�T�T�D�I�I��G� �D�I��(�(��-�-�� � � rc���d|j|j|jfz}|d|jzz }|jr||�|j��z }|jr*|dd�d�|jD����zz }|S)NzINo terminal matches '%s' in the current parser context, at line %d col %dz z Previous tokens: %s z, c3�4K�|]}t|��V��dSr%)�repr)rl�ts r� <genexpr>z/UnexpectedCharacters.__str__.<locals>.<genexpr>�s(����<a�<a��T�!�W�W�<a�<a�<a�<a�<a�<ar)r�r2r3r�r�rsr�rqr�s rr�zUnexpectedCharacters.__str__�s���]�ae�aj�lp�lu�w{�xC�aD�D���6�D�M�)�)�� �<� ;� �t�,�,�T�\�:�:� :�G� � � b� �0�4�9�9�<a�<a�d�N`�<a�<a�<a�3a�3a�a� a�G��r)NNNNNN) rrrrtrrZrvr r|r�r�r�s@rr�r��s�������������X�����3�x����sw�:>�.�.�.�.�.�.�.������rr�c���eZdZUdZeeed<eeed<d �fd� Zedeefd���Z d�Z �xZ S) r[a�An exception that is raised by the parser, when the token it received doesn't match any valid step forward. Parameters: token: The mismatched token expected: The set of expected tokens considered_rules: Which rules were considered, to deduce the expected tokens state: A value representing the parser state. Do not rely on its value or type. interactive_parser: An instance of ``InteractiveParser``, that is initialized to the point of failure, and can be used for debugging and error handling. Note: These parameters are available as attributes of the instance. rrr�Nc�T��tt|�����t|dd��|_t|dd��|_t|dd��|_||_||_||_ t|_ ||_ ||_ ||_||_dS)Nr2�?r3� start_pos)r{r[r|�getattrr2r3rBr4r_rrr�_acceptsr�r5rpr�) rKr_rrr�r4r5r~r�rs �rr|zUnexpectedToken.__init__�s���� �o�t�$�$�-�-�/�/�/��E�6�3�/�/�� ��e�X�s�3�3�� �$�U�K��>�>����� ��� � �� � �� � 0���"4���"3���*����rr9c�v�|jtur%|jo|j���|_|jSr%)r�rr5r\)rKs rr\zUnexpectedToken.accepts�s5�� �=�H� $� $� �3�Y��8O�8W�8W�8Y�8Y�D�M��}�rc ��d|j�d|j�d|j�d|�|jp|j����}|jr |d|jzz }|S)NzUnexpected token z at line z , column z. zPrevious tokens: %r )r_r2r3rsr\rrr�r�s rr�zUnexpectedToken.__str__�si����j�j�j�$�)�)�)�T�[�[�[�$�:O�:O�PT�P\�Pm�`d�`m�:n�:n�:n�p�� � � D� �.��1C�C� C�G��r)NNNNN) rrrrtrrZrvr|�propertyr\r�r�r�s@rr[r[�s��������� � ��#�h�����#�h����+�+�+�+�+�+�$���S������X�� ������rr[c�8��eZdZUdZded<eed<�fd�Z�xZS)� VisitErrorarVisitError is raised when visitors are interrupted by an exception It provides the following attributes for inspection: Parameters: rule: the name of the visit rule that failed obj: the tree-node or token that was being processed orig_exc: the exception that cause it to fail Note: These parameters are available as attributes zUnion[Tree, Token]�obj�orig_excc���d|�d|��}tt|���|��||_||_||_dS)NzError trying to process rule "z": )r{r�r|�ruler�r�)rKr�r�r�r�rs �rr|zVisitError.__init__sL����@D���h�h�O�� �j�$���(�(��1�1�1��� ���� �� � � r)rrrrtrv� Exceptionr|r�r�s@rr�r�s^�������� � � ��������!�!�!�!�!�!�!�!�!rr�c��eZdZdS)�MissingVariableErrorNrrrrr�r�!rrr�N)r")%�utilsrr�typingrrrr r r r r rrrrr}r�parsers.lalr_interactive_parserr�treerr�r� ValueErrorr!r(r*r,r.r/r1r^r�r[r�r�rrr�<module>r�s���#�#�#�#�#�#�#�#�z�z�z�z�z�z�z�z�z�z�z�z�z�z�z�z�z�z�z�z�z�z�z�z�z�z�z�z���������B�B�B�B�B�B������� � � � � � � � � � � � � � ��J� � � �9�9�*�9�9�9�9�  � � � � �9� � � � � � � � �� � � � � � � � �y� � � � �G�C�L�L��kG�kG�kG�kG�kG�i�kG�kG�kG�\�����J�����0&�&�&�&�&�8�_�&�&�&�R0�0�0�0�0�j�/�0�0�0�h!�!�!�!�!��!�!�!�2 � � � � �9� � � � � r
Memory