3

Y'íc?#ã@sÎddlZddlZddlZddlmZmZmZmZddlm	Z
Gdd„de
je
je
j
e
je
jƒZeejƒZejdedƒZGd	d
„d
eƒZGdd„deƒZGd
d„deƒZGdd„deƒZGdd„deƒZdS)éNé)ÚcolÚlineÚlinenoÚ_collapse_string_to_ranges)Úpyparsing_unicodec@seZdZdS)ÚExceptionWordUnicodeN)Ú__name__Ú
__module__Ú__qualname__©rrú9/tmp/pip-build-gk9425m9/pyparsing/pyparsing/exceptions.pyrsrz([z
]{1,16})|.c@sÎeZdZdZd eeejedœdd„Ze	d!dd	„ƒZ
ed
d„ƒZe
edœd
d„ƒZe
edœdd„ƒZe
edœdd„ƒZe
edœdd„ƒZedœdd„Zdd„Zd"ddœeedœdd„Zd#edœdd„ZeZdS)$ÚParseBaseExceptionz7base exception class for all parsing runtime exceptionsrN)ÚpstrÚlocÚmsgcCsD||_|dkr||_d|_n||_||_||_|_|||f|_dS)NÚ)rrrZparser_elementÚ
parserElementÚargs)ÚselfrrrÚelemrrr
Ú__init__szParseBaseException.__init__éc
Cs„ddl}ddlm}|dkr$tjƒ}g}t|tƒrV|j|jƒ|jd|j	ddƒ|jdj
t|ƒj|ƒƒ|dkrz|j
|j|d}tƒ}xêt||d…ƒD]Ô\}}|d}	|	jjd	dƒ}
t|
|ƒr|	jjdkrÚq¢t|
ƒ|krèq¢|jt|
ƒƒt|
ƒ}|jdj
|j|j|
ƒƒnP|
dk	rBt|
ƒ}|jd
j
|j|jƒƒn&|	j}|jdkrVq¢|jdj
|jƒƒ|d8}|s¢Pq¢Wdj|ƒ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Ú
_parseNoCachez
{}.{} - {}z{}.{}Úwrapperú<module>z{}Ú
)rr)rr )ÚinspectÚcorerÚsysÚgetrecursionlimitÚ
isinstancerÚappendrÚcolumnÚformatÚtyper	ÚgetinnerframesÚ
__traceback__ÚsetÚ	enumerateÚf_localsÚgetÚf_codeÚco_nameÚidÚaddr
Újoin)
ÚexcÚdepthr"rÚretZcallersÚseenÚiÚffZfrmZf_selfZ	self_typeÚcoderrr
Úexplain_exception)sH


z$ParseBaseException.explain_exceptioncCs||j|j|j|jƒS)z¬
        internal factory method to simplify creating one type of ParseException
        from another - avoids having __init__ signature conflicts among subclasses
        )rrrr)ÚclsÚperrr
Ú_from_exceptionksz"ParseBaseException._from_exception)ÚreturncCst|j|jƒS)zG
        Return the line of text where the exception occurred.
        )rrr)rrrr
rsszParseBaseException.linecCst|j|jƒS)zV
        Return the 1-based line number of text where the exception occurred.
        )rrr)rrrr
rzszParseBaseException.linenocCst|j|jƒS)z]
        Return the 1-based column on the line of text where the exception occurred.
        )rrr)rrrr
rszParseBaseException.colcCst|j|jƒS)z]
        Return the 1-based column on the line of text where the exception occurred.
        )rrr)rrrr
r(ˆszParseBaseException.columncCs†|jrh|jt|jƒkrd}qltj|j|jƒ}|dk	r@|jdƒ}n|j|j|jd…}d|jddƒ}nd}dj|j||j|j	|j
ƒS)	Nz, found end of textrrz
, found %rz\\ú\rz%{}{}  (at char {}), (line:{}, col:{}))rrÚlenÚ_exception_word_extractorÚmatchÚgroupÚreplacer)rrr()rZfoundstrZfound_matchÚfoundrrr
Ú__str__szParseBaseException.__str__cCst|ƒS)N)Ústr)rrrr
Ú__repr__¡szParseBaseException.__repr__z>!<)ÚmarkerString)Ú
marker_stringrAcCsL|dk	r|n|}|j}|jd}|rDdj|d|…|||d…fƒ}|jƒS)z‹
        Extracts the exception line from the input string, and marks
        the location of the exception with a special symbol.
        Nrr)rr(r5Ústrip)rrMrLÚline_strÚline_columnrrr
Úmark_input_line¤s
z"ParseBaseException.mark_input_linecCs|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``
        )r=)rr7rrr
Úexplain²s%zParseBaseException.explain)rNN)r)N)r)r	r
rÚ__doc__rJÚintÚtypingÚOptionalrÚstaticmethodr=Úclassmethodr@Úpropertyrrrr(rIrKrQrRÚ
markInputlinerrrr
rs(A'rc@seZdZdZdS)Ú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

    N)r	r
rrSrrrr
r[Üsr[c@seZdZdZdS)ÚParseFatalExceptionzu
    User-throwable exception thrown when inconsistent parse content
    is found; stops all parsing immediately
    N)r	r
rrSrrrr
r\ðsr\c@seZdZdZdS)ÚParseSyntaxExceptionzó
    Just like :class:`ParseFatalException`, but thrown internally
    when an :class:`ErrorStop<And._ErrorStop>` ('-' operator) indicates
    that parsing is to stop immediately because an unbacktrackable
    syntax error has been found.
    N)r	r
rrSrrrr
r]÷sr]c@s&eZdZdZdd„Zedœdd„ZdS)Ú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<ParserElement.enable_left_recursion>`
    cCs
||_dS)N)ÚparseElementTrace)rÚparseElementListrrr
rsz"RecursiveGrammarException.__init__)rAcCsdj|jƒS)NzRecursiveGrammarException: {})r)r_)rrrr
rI
sz!RecursiveGrammarException.__str__N)r	r
rrSrrJrIrrrr
r^sr^)Úrer$rUÚutilrrrrÚunicoderZppuZLatin1ZLatinAZLatinBÚGreekZCyrillicrÚ	alphanumsZ_extract_alphanumsÚcompilerDÚ	Exceptionrr[r\r]r^rrrr
Ú<module>s"
J