
    Xh*                        d dl mZmZ ddlmZmZmZmZmZm	Z	m
Z
mZmZmZmZmZ erd dlmZ d dlmZ d dlmZ  G d de      Z G d	 d
ee      Zd!defdZ G d de      Z G d de      Z G d de      Z ed      Z G d de      Z G d dee      Z  G d dee      Z! G d dee      Z" G d de      Z# G d de      Z$y )"   )loggerNO_VALUE    )MappingIterableCallableUnionTypeVarTupleAnyListSetOptional
CollectionTYPE_CHECKINGToken)InteractiveParser)Treec                       e Zd Zy)	LarkErrorN__name__
__module____qualname__     C/var/www/html/myenv/lib/python3.12/site-packages/lark/exceptions.pyr   r          r   r   c                       e Zd Zy)ConfigurationErrorNr   r   r   r   r!   r!      r   r   r!   optionsc                 ,    | |vrt        || |fz        y N)r!   )valuer"   msgs      r   assert_configr'      s$    G w'7!788 r   c                       e Zd Zy)GrammarErrorNr   r   r   r   r)   r)      r   r   r)   c                       e Zd Zy)
ParseErrorNr   r   r   r   r+   r+      r   r   r+   c                       e Zd Zy)LexErrorNr   r   r   r   r-   r-       r   r   r-   Tc                       e Zd ZU dZeed<   eed<   dZeed<   dZded<   dde	d	ed
e	fdZ
	 	 ddddeeeee	   f   eeeee	   f      f   deded
ee   f
dZd Zy)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||| j	                  dd      d   }||| j                  dd      d   }||z   dz   dt        |j                               z  z   dz   S ||| j	                  dd      d   }||| j                  dd      d   }||z   dz   dt        |j                               z  z   d	z   j                  d
d      S )a   Returns 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
        r   
r    z^
   
    s   ^
asciibackslashreplace)	pos_in_streammax
isinstancebytesrsplitsplitlen
expandtabsdecode)selfr5   r6   posstartendbeforeafters           r   get_contextzUnexpectedInput.get_context7   s$    !!-3t3-  C$J"Dj$&%_++D!4R8FSM''a03EE>D(3V5F5F5H1I+IIEQQ%_++E15b9FSM''q1!4EUNU*TC8I8I8K4L-LLvU]]^egyzzr   parse_fnzCallable[[str], Tree]examplestoken_type_match_fallbackuse_acceptsc                 ,   | j                   J d       t        |t              r|j                         }d}t	        |      D ];  \  }\  }}t        |t
              rJ d       t	        |      D ]  \  }	}
	  ||
        = |d   S # t        $ r}|j                   | j                   k(  r`|ryt        | t              rit        |t              rY|j                  | j                  k7  r@t        j                  d| j                   | j                  |j                  ||	fz         Y d}~t        | t        t        f      rt        |t        t        f      r|j                  | j                  k(  r't        j                  d|d|	d       |cY d}~c c S |rR|j                  j                  | j                  j                  k(  r%|d	   s t        j                  d
|d|	d       |df}|d    t        j                  d|d|	d       |df}Y d}~d}~ww xY w)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)NFzExpecting a listzCDifferent accepts with same state[%d]: %s != %s at example [%s][%s]zExact Match at example [z][]r:   z Token Type Fallback at example [Tr   zSame State match at example [F)r3   rB   r   items	enumeratestrr0   UnexpectedTokenacceptsr   debugUnexpectedEOFtokentype)rI   rP   rQ   rR   rS   	candidateilabelexamplej	malformeduts               r   match_exampleszUnexpectedInput.match_examplesL   s   * zz%I'II%h(~~'H!	#,X#6 !	5Aw!'3/C1CC/ )' 2 595Y'5!	5F |; ' 5xx4::-' *4 A *2 ? "

dll :"LL)n*.**dllBJJPQST)U*V W$&to}-MN *2/O P!xx4::5 &RSUV-W X',8$&HHMMTZZ__$DiXZm$*LL^_ab1c$d05tI$Q</"LLSTVW)XY(-uI75s-   3B
HBH#A"HHA9HHc                     | j                   r2| j                   }|D cg c]  }||v r||   j                         n| }}ddj                  |      z  S c c}w )NzExpected one of: 
	* %s
z
	* )_terminals_by_name	user_reprjoin)rI   expecteddt_names       r   _format_expectedz UnexpectedInput._format_expected   s[    ""''AW_`V1&	++-&H`H`,x}}X/FFF as    A)(   )FT)r   r   r   __doc__int__annotations__r@   r   rh   rX   rO   r	   r   r.   r   r   boolr   rf   rn   r   r   r   r0   r0   %   s    	 IKMJ++{ {3 {c {. >C/3>'> >',WQ5E-FQVWXZbcfZgWgQhHi-i'j>8<> +/> 'qk	>@Gr   r0   c                   6     e Zd ZU dZded<   d fd	Zd Z xZS )r\   zcAn exception that is raised by the parser, when the input ends while it still expects a token.
    zList[Token]rk   c                     t         t        |           || _        || _        ddlm}  |dd      | _        d| _        d| _	        d| _
        || _        y )Nr   r   z<EOF> r:   )superr\   __init__rk   r3   lexerr   r]   r@   r1   r2   rh   )rI   rk   r3   terminals_by_namer   	__class__s        r   rx   zUnexpectedEOF.__init__   sM    mT+- 
 7B'
	"3r   c                 F    d}|| j                  | j                        z  }|S )NzUnexpected end-of-input. )rn   rk   rI   messages     r   __str__zUnexpectedEOF.__str__   s%    -4((77r   )NN)r   r   r   rp   rr   rx   r   __classcell__r{   s   @r   r\   r\      s    
4r   r\   c                   P     e Zd ZU dZee   ed<   ee   ed<   	 	 d fd	Zd Z	 xZ
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_tokensc                 D   t         t        |           || _        || _        || _        || _        |	| _        || _        || _	        |
| _
        || _        t        |t              r|||dz    j                  dd      | _        n
||   | _        | j!                  |      | _        y )Nr   r>   r?   )rw   r   rx   r1   r2   r@   r3   rh   r   r   considered_rulestoken_historyrB   rC   rH   charrO   _context)rI   seqlex_posr1   r2   r   r   r3   r   rz   r   r{   s              r   rx   zUnexpectedCharacters.__init__   s    "D24 	$
"3!2 0*c5!GGaK077ASTDIGDI((-r   c                 2   d| j                   | j                  | j                  fz  }|d| j                  z   z  }| j                  r|| j                  | j                        z  }| j                  r(|ddj                  d | j                  D              z  z  }|S )NzINo terminal matches '%s' in the current parser context, at line %d col %dz

z
Previous tokens: %s
z, c              3   2   K   | ]  }t        |        y wr$   )repr).0ts     r   	<genexpr>z/UnexpectedCharacters.__str__.<locals>.<genexpr>   s     <aT!W<as   )r   r1   r2   r   r   rn   r   rj   r}   s     r   r   zUnexpectedCharacters.__str__   s    ]aeajajlpluluw{  xC  xC  aD  D6DMM))<<t,,T\\::G0499<adN`N`<a3aaaGr   )NNNNNN)r   r   r   rp   r   rX   rr   r   rx   r   r   r   s   @r   r   r      s.     X3xsw:>..r   r   c                   h     e Zd ZU dZee   ed<   ee   ed<   d fd	Zedee   fd       Z	d Z
 xZS )	rY   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.
    rk   r   c                    t         t        |           t        |dd      | _        t        |dd      | _        t        |dd       | _        || _        || _        || _	        t        | _        || _        || _        || _        || _        y )Nr1   ?r2   	start_pos)rw   rY   rx   getattrr1   r2   r@   r3   r]   rk   r   _acceptsr   r4   rh   r   )	rI   r]   rk   r   r3   r4   rz   r   r{   s	           r   rx   zUnexpectedToken.__init__   s    ot-/ E63/	eXs3$UK>

   0"4"3*r   r7   c                     | j                   t        u r-| j                  xr | j                  j                         | _         | j                   S r$   )r   r   r4   rZ   )rI   s    r   rZ   zUnexpectedToken.accepts   s9    ==H$ 33Y8O8O8W8W8YDM}}r   c                     d| j                   d| j                  d| j                  d| j                  | j                  xs | j
                        }| j                  r|d| j                  z  z  }|S )NzUnexpected token z	 at line z	, column z.
zPrevious tokens: %r
)r]   r1   r2   rn   rZ   rk   r   r}   s     r   r   zUnexpectedToken.__str__   sa    jj$))T[[$:O:OPTP\P\Pm`d`m`m:np.1C1CCCGr   )NNNNN)r   r   r   rp   r   rX   rr   rx   propertyrZ   r   r   r   s   @r   rY   rY      sG     #h#h+$ S  
r   rY   c                   8     e Zd ZU dZded<   eed<    fdZ xZS )
VisitErrorar  VisitError 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
    zUnion[Tree, Token]objorig_excc                 f    d|d|}t         t        |   |       || _        || _        || _        y )NzError trying to process rule "z":

)rw   r   rx   ruler   r   )rI   r   r   r   r~   r{   s        r   rx   zVisitError.__init__  s1    @DhOj$(1	 r   )r   r   r   rp   rr   	Exceptionrx   r   r   s   @r   r   r     s     
 
! !r   r   c                       e Zd Zy)MissingVariableErrorNr   r   r   r   r   r   !  r   r   r   N)zGot %r, expected one of %s)%utilsr   r   typingr   r   r   r	   r
   r   r   r   r   r   r   r   ry   r   parsers.lalr_interactive_parserr   treer   r   r   
ValueErrorr!   r'   r)   r+   r-   r.   r0   r\   r   rY   r   r   r   r   r   <module>r      s    # z z z zB		 		J 	9* 9
	9 		 		y 	 CLkGi kG\J 0&8_ &R0j/ 0h! !2	9 	r   