Mpj*ddlmZmZddlmZmZmZmZmZm Z m Z m Z m Z m Z mZmZerddlmZddlmZddlmZGddeZGd d eeZd!d efd ZGd deZGddeZGddeZedZGddeZGddeeZ GddeeZ!GddeeZ"GddeZ#GddeZ$y )")loggerNO_VALUE) MappingIterableCallableUnionTypeVarTupleAnyListSetOptional Collection TYPE_CHECKINGToken)InteractiveParser)Treec eZdZy) LarkErrorN__name__ __module__ __qualname__]/mnt/ssd/data/Dropbox/adrian/scripts/msg_venv/lib/python3.12/site-packages/lark/exceptions.pyrr rrc eZdZy)ConfigurationErrorNrrrrr!r!rrr!optionsc,||vrt|||fzyN)r!)valuer"msgs r assert_configr's$ G w'7!788rc eZdZy) GrammarErrorNrrrrr)r)rrr)c eZdZy) ParseErrorNrrrrr+r+rrr+c eZdZy)LexErrorNrrrrr-r- rrr-Tc eZdZUdZeed<eed<dZeed<dZded<dde d ed e fd Z dd d de e e ee feee ee ffdeded ee f dZdZy)UnexpectedInputaUnexpectedInput 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. linecolumnNstaterinteractive_parsertextspanreturnc|jxsd}t||z d}||z}t|tsX|||j ddd}|||j ddd}||zdzdt |jzzdzS|||j ddd}|||j ddd}||zdzdt |jzzd zjd 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 r r z^   s^ asciibackslashreplace) pos_in_streammax isinstancebytesrsplitsplitlen expandtabsdecode)selfr5r6posstartendbeforeafters r get_contextzUnexpectedInput.get_context7s  %AC$J"Dj$&%_++D!4R8FSM''a03EE>D(3V5F5F5H1I+IIEQ Q%_++E15b9FSM''q1!4EUNU*TC8I8I8K4L-LLvU]]^egyz zrparse_fnzCallable[[str], Tree]examplestoken_type_match_fallback use_acceptsc ,|jJdt|tr|j}d}t |D];\}\}}t|t rJdt |D]\} } || =|d S#t $r} | j|jk(r`|ryt|trit| trY| j|jk7r@tjd|j|j| j|| fzYd} ~ t|ttfrt| ttfr| j|jk(r'tjd|d| d|cYd} ~ ccS|rR| jj|jjk(r%|d s tjd |d| d|d f}|d  tjd |d| d|df}Yd} ~ d} ~ wwxYw)aAllows 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)r3rBritems enumeratestrr0UnexpectedTokenacceptsrdebug UnexpectedEOFtokentype) rIrPrQrRrS candidateilabelexamplej malformeduts rmatch_exampleszUnexpectedInput.match_examplesKs*zz%I'II% h (~~'H! #,X#6! 5 Aw!'3/ C1C C/ )' 2 5 95Y' 5! 5F|;'5xx4::-' *4 A *2 ? " dll :"LL)n*.**dllBJJPQST)U*VW$&to}-MN *2/O P!xx4::5 & RSUV-W X', 8$&HHMMTZZ__$DiXZm$*LL^_ab1c$d05t I$Q</"LLSTVW)XY(-u I75s-3B HBH#A"HHA9HHc|jr2|j}|Dcgc]}||vr||jn|}}ddj|zScc}w)NzExpected one of: * %s z * )_terminals_by_name user_reprjoin)rIexpecteddt_names r_format_expectedz UnexpectedInput._format_expecteds[  " "''AW_`V1& ++-&H`H`,x}}X/FFFas A)()FT)rrr__doc__int__annotations__r@r rhrXrOr rr.rr boolrrfrnrrrr0r0%s  I KM J++{{3{c{,>C/3>'>>',WQ 5E-FQVWXZbcfZgWgQhHi-i'j>8<>+/>'qk >@Grr0c6eZdZUdZded<dfd ZdZxZS)r\zcAn exception that is raised by the parser, when the input ends while it still expects a token. z List[Token]rkctt| ||_||_ddlm}|dd|_d|_d|_ d|_ ||_ y)Nrrzr:) superr\__init__rkr3lexerrr]r@r1r2rh)rIrkr3terminals_by_namer __class__s rrxzUnexpectedEOF.__init__sM mT+-    7B'   "3rcFd}||j|jz }|S)NzUnexpected end-of-input. )rnrkrImessages r__str__zUnexpectedEOF.__str__s%-4((77r)NN)rrrrprrrxr __classcell__r{s@rr\r\s 4rr\cPeZdZUdZeeed<eeed< dfd ZdZ 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. allowedconsidered_tokensc Dtt| ||_||_||_||_| |_||_||_ | |_ ||_ t|tr|||dzjdd|_n |||_|j!||_y)Nrr>r?)rwrrxr1r2r@r3rhrrconsidered_rules token_historyrBrCrHcharrO_context) rIseqlex_posr1r2rrr3rrzrr{s rrxzUnexpectedCharacters.__init__s "D24  $ "3 !2 0* c5 !GGaK077ASTDIG DI((- rc2d|j|j|jfz}|d|jzz }|jr||j |jz }|j r(|ddjd|j Dzz }|S)NzINo terminal matches '%s' in the current parser context, at line %d col %dz z Previous tokens: %s z, c32K|]}t|ywr$)repr).0ts r z/UnexpectedCharacters.__str__..s..rrcheZdZUdZeeed<eeed<dfd ZedeefdZ dZ xZ S) rYaAn 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. rkrctt| t|dd|_t|dd|_t|dd|_||_||_||_ t|_ ||_ ||_ ||_||_y)Nr1?r2 start_pos)rwrYrxgetattrr1r2r@r3r]rkr_acceptsrr4rhr) rIr]rkrr3r4rzrr{s rrxzUnexpectedToken.__init__s ot-/E63/ eXs3 $UK>      0"4"3*rr7c|jtur-|jxr|jj|_|jSr$)rrr4rZ)rIs rrZzUnexpectedToken.acceptss9 ==H $ 33Y8O8O8W8W8YDM}}rc d|jd|jd|jd|j|jxs |j }|j r|d|j zz }|S)NzUnexpected token z at line z , column z. zPrevious tokens: %r )r]r1r2rnrZrkrr}s rrzUnexpectedToken.__str__sajj$))T[[$:O:OPTP\P\Pm`d`m`m:np    .1C1CC CGr)NNNNN) rrrrprrXrrrxpropertyrZrrrs@rrYrYsG #h#h+$S rrYc8eZdZUdZded<eed<fdZxZS) 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]objorig_exccfd|d|}tt| |||_||_||_y)NzError trying to process rule "z": )rwrrxrulerr)rIrrrr~r{s rrxzVisitError.__init__s1@DhO j$(1   r)rrrrprr Exceptionrxrrs@rrrs   !!rrc eZdZy)MissingVariableErrorNrrrrrr rrrN)zGot %r, expected one of %s)%utilsrrtypingrrrr r r r r rrrrryrparsers.lalr_interactive_parserrtreerrr ValueErrorr!r'r)r+r-r.r0r\rrYrrrrrrs#zzzzB   J 9*9  9    y  CLjGijGZJ0&8_&R0j/0h!!2 9 r