& d3% ddlZddlZddlZddlmZmZmZmZmZddl m Z Gdde je je je je j Zeej$Zej(dezdzZGd d eZGd d eZGd deZGddeZGddeZy)N)collinelineno_collapse_string_to_rangesreplaced_by_pep8)pyparsing_unicodec eZdZy)ExceptionWordUnicodeN)__name__ __module__ __qualname__6/usr/lib/python3/dist-packages/pyparsing/exceptions.pyr r srr z([z ]{1,16})|.ceZdZUdZeed<eed<eed<ejed<ejeeejefed<dZ ddededejefd Z e dd Zed Zed efd Zed efdZed efdZed efdZedZej.dZd efdZdZ ddddejeded efdZdd efdZeedZy)ParseBaseExceptionz7base exception class for all parsing runtime exceptionslocmsgpstrparser_elementargsrrrrrNcr||_|||_d|_n||_||_||_|||f|_y)Nr)selfrrrelems r__init__zParseBaseException.__init__,sB ;DHDIDHDI"3$ rc<ddl}ddlm}|tj}g}t |t r?|j|j|jd|jdz zdz|jt|jd||dkDrl|j|j|}t}t|| dD]2\}}|d} | j j#d d} t | |r| j$j&j)d sZt+| |vrh|j-t+| t| } |j| j.d | jd | no| 6t| } |j| j.d | jn7| j$} | j&d vr|j| j&|dz}|r3ndj1|S)a Method to take an exception and translate the Python internal traceback into a list of the pyparsing expressions that caused the exception to be raised. Parameters: - exc - exception raised during parsing (need not be a ParseException, in support of Python exceptions that might be raised in a parse action) - depth (default=16) - number of levels back in the stack trace to list expression and function names; if None, the full stack trace names will be listed; if 0, only the failing input line, marker, and exception string will be shown Returns a multi-line string listing the ParserElements and/or function names in the exception's stack trace. rNr) ParserElement ^z: )contextr) parseImpl _parseNoCache.z - )wrapperz )inspectcorer sysgetrecursionlimit isinstancerappendrcolumntyper getinnerframes __traceback__set enumeratef_localsgetf_codeco_name startswithidaddr join) excdepthr)r retcallersseenifffrmf_self self_typecodes rexplain_exceptionz$ParseBaseException.explain_exception=s" ' =))+E c- . JJsxx JJscjj1n-3 4 d3i(()C512 19,,S->->,NG5D"7E67#34 2e))&$7fm4::--886!&zT) HHRZ( $V IJJ$//0)2D2D1ESQ' $V IJJ)"6"6!7q9K9K8LMN::D||'>> JJt||, ? Byy~rch||j|j|j|jS)z internal factory method to simplify creating one type of ParseException from another - avoids having __init__ signature conflicts among subclasses )rrrr)clspes r_from_exceptionz"ParseBaseException._from_exceptions' 277BFFBFFB,=,=>>rreturncBt|j|jS)zG Return the line of text where the exception occurred. )rrrrs rrzParseBaseException.lines DHHdii((rcBt|j|jS)zV Return the 1-based line number of text where the exception occurred. )rrrrOs rrzParseBaseException.linenos dhh **rcBt|j|jSz] Return the 1-based column on the line of text where the exception occurred. rrrrOs rrzParseBaseException.col 488TYY''rcBt|j|jSrRrSrOs rr/zParseBaseException.columnrTrc|jSNrrOs r parserElementz ParseBaseException.parserElements"""rc||_yrWrX)rrs rrYz ParseBaseException.parserElements "rc |jr|jt|jk\rd}n|tj |j|j}||j d}n&|j|j|jdz}d|zj dd}nd}|j|d|jd |jd |jd S) Nz, found end of textrrz , found %rz\\\rz (at char z ), (line:z, col:)) rrlen_exception_word_extractormatchgroupreplacerrr/)rfoundstr found_matchfounds r__str__zParseBaseException.__str__s 99xx3tyy>)08==diiR *'--a0E IIdhhA>E(5099%FH((H:[ )DKK=PVW[WbWbVccdeerct|SrW)strrOs r__repr__zParseBaseException.__repr__s 4yrz>!<) markerString marker_stringrjc||n|}|j}|jdz }|rdj|d||||df}|jS)z Extracts the exception line from the input string, and marks the location of the exception with a special symbol. Nrr)rr/r<strip)rrkrjline_str line_columns rmark_input_linez"ParseBaseException.mark_input_lines^)6(A}| 99kkAo ww,;'x 7MNH~~rc&|j||S)a  Method to translate the Python internal traceback into a list of the pyparsing expressions that caused the exception to be raised. Parameters: - depth (default=16) - number of levels back in the stack trace to list expression and function names; if None, the full stack trace names will be listed; if 0, only the failing input line, marker, and exception string will be shown Returns a multi-line string listing the ParserElements and/or function names in the exception's stack trace. Example:: expr = pp.Word(pp.nums) * 3 try: expr.parse_string("123 456 A789") except pp.ParseException as pe: print(pe.explain(depth=0)) prints:: 123 456 A789 ^ ParseException: Expected W:(0-9), found 'A' (at char 8), (line:1, col:9) Note: the diagnostic output will include string representations of the expressions that failed to parse. These representations will be more helpful if you use `set_name` to give identifiable names to your expressions. Otherwise they will use the default string forms, which may be cryptic to read. Note: pyparsing's default truncation of exception tracebacks may also truncate the stack of expressions that are displayed in the ``explain`` output. To get the full listing of parser expressions, you may have to set ``ParserElement.verbose_stacktrace = True`` )rH)rr>s rexplainzParseBaseException.explainsJ%%dE22rcyrWrrOs r markInputlinez ParseBaseException.markInputlines r)rNN)rW)r r r__doc__int__annotations__rhtypingAnyTupleOptional __slots__r staticmethodrH classmethodrLpropertyrrrr/rYsetterrfrirprrrrtrrrrrsA H H IJJ ,,sC!55 66I$(  %%%__S ! %"??B??)c)) +++ (S(( (((####ff 59 QV #__S1 KN  %33%3Po& ' rrceZdZdZy)ParseExceptionaq Exception thrown when a parse expression doesn't match the input string Example:: try: Word(nums).set_name("integer").parse_string("ABC") except ParseException as pe: print(pe) print("column: {}".format(pe.column)) prints:: Expected integer (at char 0), (line:1, col:1) column: 1 Nr r rrvrrrrrsrrceZdZdZy)ParseFatalExceptionzu User-throwable exception thrown when inconsistent parse content is found; stops all parsing immediately NrrrrrrsrrceZdZdZy)ParseSyntaxExceptionz Just like :class:`ParseFatalException`, but thrown internally when an :class:`ErrorStop` ('-' operator) indicates that parsing is to stop immediately because an unbacktrackable syntax error has been found. Nrrrrrrsrrc"eZdZdZdZdefdZy)RecursiveGrammarExceptionz Exception thrown by :class:`ParserElement.validate` if the grammar could be left-recursive; parser may need to enable left recursion using :class:`ParserElement.enable_left_recursion` c||_yrWparseElementTrace)rparseElementLists rrz"RecursiveGrammarException.__init__'s !1rrMc d|jS)NzRecursiveGrammarException: rrOs rrfz!RecursiveGrammarException.__str__*s,T-C-C,DEErN)r r rrvrrhrfrrrrr s 2FFrr)rer+ryutilrrrrrunicoder ppuLatin1LatinALatinBGreekCyrillicr alphanums_extract_alphanumscompiler_ Exceptionrrrrrrrrrs . 3::szz3::syy#,, 00D0N0NO&BJJt.@'@<'OP_!_!F'(,. F Fr