@staticmethod<EOL><INDENT>def explain(exc, depth=<NUM_LIT:16>):<DEDENT>
import inspect<EOL>if depth is None:<EOL><INDENT>depth = sys.getrecursionlimit()<EOL><DEDENT>ret = []<EOL>if isinstance(exc, ParseBaseException):<EOL><INDENT>ret.append(exc.line)<EOL>ret.append('<STR_LIT:U+0020>' * (exc.col - <NUM_LIT:1>) + '<STR_LIT>')<EOL><DEDENT>ret.append("<STR_LIT>".format(type(exc).__name__, exc))<EOL>if depth > <NUM_LIT:0>:<EOL><INDENT>callers = inspect.getinnerframes(exc.__traceback__, context=depth)<EOL>seen = set()<EOL>for i, ff in enumerate(callers[-depth:]):<EOL><INDENT>frm = ff.frame<EOL>f_self = frm.f_locals.get('<STR_LIT>', None)<EOL>if isinstance(f_self, ParserElement):<EOL><INDENT>if frm.f_code.co_name not in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>continue<EOL><DEDENT>if f_self in seen:<EOL><INDENT>continue<EOL><DEDENT>seen.add(f_self)<EOL>self_type = type(f_self)<EOL>ret.append("<STR_LIT>".format(self_type.__module__,<EOL>self_type.__name__,<EOL>f_self))<EOL><DEDENT>elif f_self is not None:<EOL><INDENT>self_type = type(f_self)<EOL>ret.append("<STR_LIT>".format(self_type.__module__,<EOL>self_type.__name__))<EOL><DEDENT>else:<EOL><INDENT>code = frm.f_code<EOL>if code.co_name in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>continue<EOL><DEDENT>ret.append("<STR_LIT>".format(code.co_name))<EOL><DEDENT>depth -= <NUM_LIT:1><EOL>if not depth:<EOL><INDENT>break<EOL><DEDENT><DEDENT><DEDENT>return '<STR_LIT:\n>'.join(ret)<EOL>
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.

Note: the diagnostic output will include string representations of the expressions
that failed to parse. These representations will be more helpful if you use `setName` to
give identifiable names to your expressions. Otherwise they will use the default string
forms, which may be cryptic to read.

explain() is only supported under Python 3.