
    *                        S SK JrJr  SSKJrJrJrJrJrJ	r	J
r
JrJrJrJrJr  \(       a  S SKJr  S SKJr  S SKJr   " S S\5      r " S	 S
\\5      rS!S\4S jjr " S S\5      r " S S\5      r " S S\5      r\" S5      r " S S\5      r " S S\\5      r  " S S\\5      r! " S S\\5      r" " S S\5      r# " S S\5      r$g )"   )loggerNO_VALUE    )MappingIterableCallableUnionTypeVarTupleAnyListSetOptional
CollectionTYPE_CHECKINGToken)InteractiveParser)Treec                       \ rS rSrSrg)	LarkError    N__name__
__module____qualname____firstlineno____static_attributes__r       "lib/third_party/lark/exceptions.pyr   r          r    r   c                       \ rS rSrSrg)ConfigurationError   r   Nr   r   r    r!   r$   r$      r"   r    r$   optionsc                 ,    X;  a  [        X U4-  5      eg N)r$   )valuer&   msgs      r!   assert_configr+      s      w'7!788 r    c                       \ rS rSrSrg)GrammarError   r   Nr   r   r    r!   r-   r-      r"   r    r-   c                       \ rS rSrSrg)
ParseError   r   Nr   r   r    r!   r0   r0      r"   r    r0   c                       \ rS rSrSrg)LexError    r   Nr   r   r    r!   r3   r3       r"   r    r3   Tc                       \ rS rSr% Sr\\S'   \\S'   Sr\\S'   Sr	SS\
S\S	\
4S
 jjr  SSSS\\\\\
   4   \\\\\
   4      4   S\S\S	\\   4
S jjrS rSrg)UnexpectedInput%   a  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statetextspanreturnc                    U R                   c   U 5       eU R                   n[        X2-
  S5      nX2-   n[        U[        5      (       dU  XU R	                  SS5      S   nXU R                  SS5      S   nXg-   S-   S[        UR                  5       5      -  -   S-   $ XU R	                  SS5      S   nXU R                  SS5      S   nXg-   S-   S[        UR                  5       5      -  -   S	-   R                  S
S5      $ )zReturns 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)selfr<   r=   posstartendbeforeafters           r!   get_contextUnexpectedInput.get_context6   s    !!-3t3-  CJ"j$&&_++D!4R8FSM''a03E>D(3V5F5F5H1I+IIEQQ_++E15b9FSM''q1!4ENU*TC8I8I8K4L-LLvU]]^egyzzr    parse_fnzCallable[[str], Tree]examplestoken_type_match_fallbackuse_acceptsc                    U R                   c   S5       e[        U[        5      (       a  UR                  5       nSn[	        U5       HA  u  nu  px[        U[
        5      (       a   S5       e[	        U5       H  u  p U" U
5        M     MC     US   $ ! [         Ga  nUR                   U R                   :X  Ga  U(       a  [        U [        5      (       ap  [        U[        5      (       a[  UR                  U R                  :w  aA  [        R                  " SU R                   U R                  UR                  Xi4-  5         SnAM  [        U [        [        45      (       a  [        U[        [        45      (       a  UR                  U R                  :X  a*  [        R                  " SU< SU	< S35        Us SnAs  s  $ U(       a[  UR                  R                  U R                  R                  :X  a-  US	   (       d#  [        R                  " S
U< SU	< S35        US4nUS   c*  [        R                  " SU< SU	< S35        US4n SnAGM   SnAGM   SnAGM  SnAff = f)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][]rA   z Token Type Fallback at example [Tr   zSame State match at example [F)r;   rI   r   items	enumeratestrr7   UnexpectedTokenacceptsr   debugUnexpectedEOFtokentype)rP   rX   rY   rZ   r[   	candidateilabelexamplej	malformeduts               r!   match_examplesUnexpectedInput.match_examplesK   s   * zz%I'II%h((~~'H!	#,X#6A!'3//C1CC/ )' 25Y' !3 $7F |; ' 5xx4::-' *4 A A *2 ? ? "

dll :"LL)n*.**dllBJJPQ)U*V W$&to}-MNN *2/O P P!xx4::5 &RSUV-W X',8$&HHMMTZZ__$DiXZm$*LL^_ab1c$d05tI$Q</"LLSTVW)XY(-uI 01 .5s-   <BI"B!IA0I3I"=BII"c                     U R                   (       a5  U R                   nU Vs/ s H  o3U;   a  X#   R                  5       OUPM     nnSSR                  U5      -  $ s  snf )NzExpected one of: 
	* %s
z
	* )_terminals_by_name	user_reprjoin)rP   expecteddt_names       r!   _format_expected UnexpectedInput._format_expected   sZ    ""''AW_`W_V1	++-&HW_H`,x}}X/FFF as   #Ar   )(   )FT)r   r   r   r   __doc__int__annotations__rG   r   rq   r`   rV   r	   r   r5   r   r   boolr   rn   rw   r   r   r    r!   r7   r7   %   s    	 IKMJ{ {3 {c {. >C/3>'> >',WQ5E-FQVWXZbcfZgWgQhHi-i'j>8<> +/> 'qk	>@Gr    r7   c                   B   ^  \ rS rSr% SrS\S'   SU 4S jjrS rSrU =r	$ )	rd      zcAn exception that is raised by the parser, when the input ends while it still expects a token.
    zList[Token]rt   c                    > [         [        U ]  5         Xl        X l        SSKJn  U" SS5      U l        SU l        SU l	        SU l
        X0l        g )Nr   r   z<EOF> rA   )superrd   __init__rt   r;   lexerr   re   rG   r9   r:   rq   )rP   rt   r;   terminals_by_namer   	__class__s        r!   r   UnexpectedEOF.__init__   sG    mT+- 
 7B'
	"3r    c                 D    SnXR                  U R                  5      -  nU$ )NzUnexpected end-of-input. )rw   rt   rP   messages     r!   __str__UnexpectedEOF.__str__   s#    -((77r    )rq   r:   rt   r9   rG   r;   re   )NN)
r   r   r   r   rz   r|   r   r   r   __classcell__r   s   @r!   rd   rd      s    
4 r    rd   c                   \   ^  \ rS rSr% Sr\\   \S'   \\   \S'     SU 4S jjr	S r
SrU =r$ )	UnexpectedCharacters   zvAn exception that is raised by the lexer, when it cannot match the next
string of characters to any of its terminals.
allowedconsidered_tokensc                 8  > [         [        U ]  5         X0l        X@l        X l        Xpl        Xl        XPl        X`l	        Xl
        Xl        [        U[        5      (       a  XUS-    R                  SS5      U l        O	X   U l        U R!                  U5      U l        g )Nr   rE   rF   )r   r   r   r9   r:   rG   r;   rq   r   r   considered_rulestoken_historyrI   rJ   rO   charrV   _context)rP   seqlex_posr9   r:   r   r   r;   r   r   r   r   s              r!   r   UnexpectedCharacters.__init__   s    "D24 	$
"3!2 0*c5!!GaK077ASTDIDI((-r    c                 D   SU R                   U R                  U R                  4-  nUSU R                  -   -  nU R                  (       a  XR                  U R                  5      -  nU R                  (       a(  USSR                  S U R                   5       5      -  -  nU$ )NzINo terminal matches '%s' in the current parser context, at line %d col %dz

z
Previous tokens: %s
z, c              3   8   #    U  H  n[        U5      v   M     g 7fr(   )repr).0ts     r!   	<genexpr>/UnexpectedCharacters.__str__.<locals>.<genexpr>   s     <aN`T!WWN`s   )r   r9   r:   r   r   rw   r   rs   r   s     r!   r   UnexpectedCharacters.__str__   s    ]aeajajlpluluw{  xC  xC  aD  D6DMM))<<,,T\\::G0499<adN`N`<a3aaaGr    )r   rq   r   r   r:   r   r   r9   rG   r;   r   )NNNNNN)r   r   r   r   rz   r   r`   r|   r   r   r   r   r   r   s   @r!   r   r      s3     X3xsw:>.. r    r   c                      ^  \ rS rSr% Sr\\   \S'   \\   \S'   S\S'   SU 4S jjr\	S\\   4S	 j5       r
S
 rSrU =r$ )ra      aa  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.
rt   r   r   interactive_parserc                    > [         [        U ]  5         [        USS5      U l        [        USS5      U l        [        USS 5      U l        X@l        Xl        X l	        [        U l        X0l        XPl        X`l        Xpl        g )Nr9   ?r:   	start_pos)r   ra   r   getattrr9   r:   rG   r;   re   rt   r   _acceptsr   r   rq   r   )	rP   re   rt   r   r;   r   r   r   r   s	           r!   r   UnexpectedToken.__init__   sq    ot-/ E63/	eXs3$UK>

   0"4"3*r    r>   c                     U R                   [        L a2  U R                  =(       a    U R                  R                  5       U l         U R                   $ r(   )r   r   r   rb   )rP   s    r!   rb   UnexpectedToken.accepts   s9    ==H$ 33Y8O8O8W8W8YDM}}r    c                    SU R                   < SU R                  < SU R                  < SU R                  U R                  =(       d    U R
                  5      < 3nU R                  (       a  USU R                  -  -  nU$ )NzUnexpected token z	 at line z	, column z.
zPrevious tokens: %r
)re   r9   r:   rw   rb   rt   r   r   s     r!   r   UnexpectedToken.__str__   sa    jj$))T[[$:O:OPTP\P\Pm`d`m`m:np.1C1CCCGr    )r   rq   r:   r   rt   r   r9   rG   r;   re   r   )NNNNN)r   r   r   r   rz   r   r`   r|   r   propertyrb   r   r   r   r   s   @r!   ra   ra      sR     #h#h+++$ S  
 r    ra   c                   B   ^  \ rS rSr% SrS\S'   \\S'   U 4S jrSrU =r	$ )
VisitErrori  aV  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                 d   > SU< SU< 3n[         [        U ]  U5        Xl        X l        X0l        g )NzError trying to process rule "z":

)r   r   r   ruler   r   )rP   r   r   r   r   r   s        r!   r   VisitError.__init__  s+    @DhOj$(1	 r    )r   r   r   )
r   r   r   r   rz   r|   	Exceptionr   r   r   r   s   @r!   r   r     s     
 
! !r    r   c                       \ rS rSrSrg)MissingVariableErrori!  r   Nr   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   r   r   parsers.lalr_interactive_parserr   treer   r   r   
ValueErrorr$   r+   r-   r0   r3   r5   r7   rd   r   ra   r   r   r   r    r!   <module>r      s    # z z z zB		 		J 	9* 9
	9 		 		y 	 CLjGi jGZJ 0&8_ &R1j/ 1j! !2	9 	r    