OpenQuizz
Une application de gestion des contenus pédagogiques
ParseException Class Reference
Inheritance diagram for ParseException:
Collaboration diagram for ParseException:

Static Public Member Functions

def explain (exc, depth=16)
 

Additional Inherited Members

- Public Member Functions inherited from ParseBaseException
def __init__ (self, pstr, loc=0, msg=None, elem=None)
 
def __getattr__ (self, aname)
 
def __str__ (self)
 
def __repr__ (self)
 
def markInputline (self, markerString=">!<")
 
def __dir__ (self)
 
- Data Fields inherited from ParseBaseException
 loc
 
 msg
 
 pstr
 
 parserElement
 
 args
 

Detailed Description

Exception thrown when parse expressions don't match class;
supported attributes by name are:
- lineno - returns the line number of the exception text
- col - returns the column number of the exception text
- line - returns the line containing the exception text

Example::

    try:
        Word(nums).setName("integer").parseString("ABC")
    except ParseException as pe:
        print(pe)
        print("column: {}".format(pe.col))

prints::

   Expected integer (at char 0), (line:1, col:1)
    column: 1

Member Function Documentation

◆ explain()

def explain (   exc,
  depth = 16 
)
static
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.

The documentation for this class was generated from the following file: