Source code for pynusmv.exception

"""
The :mod:`pynusmv.exception` module provides all the exceptions used in PyNuSMV.
Every particular exception raised by a PyNuSMV function is a sub-class
of the :class:`PyNuSMVError` class, such that one can catch all PyNuSMV by
catching :class:`PyNuSMVError` exceptions.

"""


__all__ = ['PyNuSMVError', 'MissingManagerError', 'NuSMVLexerError',
           'NuSMVNoReadFileError', 'NuSMVModelAlreadyReadError',
           'NuSMVCannotFlattenError', 'NuSMVModelAlreadyFlattenedError',
           'NuSMVNeedFlatHierarchyError', 'NuSMVModelAlreadyEncodedError',
           'NuSMVFlatModelAlreadyBuiltError', 'NuSMVNeedFlatModelError',
           'NuSMVModelAlreadyBuiltError', 'NuSMVNeedVariablesEncodedError',
           'NuSMVInitError', 'NuSMVParserError', 'NuSMVTypeCheckingError',
           'NuSMVFlatteningError', 'NuSMVBddPickingError', 'Error',
           'NuSMVParsingError']


from collections import namedtuple


[docs]class PyNuSMVError(Exception): """ A generic PyNuSMV Error, superclass of all PyNuSMV Errors. """ pass
[docs]class MissingManagerError(PyNuSMVError): """ Exception for missing BDD manager. """ pass
[docs]class NuSMVLexerError(PyNuSMVError): """ Exception for NuSMV lexer error. """ pass
[docs]class NuSMVNoReadFileError(PyNuSMVError): """ Exception raised when no SMV model has been read yet. """ pass
[docs]class NuSMVModelAlreadyReadError(PyNuSMVError): """ Exception raised when a model is already read. """ pass
[docs]class NuSMVCannotFlattenError(PyNuSMVError): """ Exception raised when no SMV model has been read yet. """ pass
[docs]class NuSMVModelAlreadyFlattenedError(PyNuSMVError): """ Exception raised when the model is already flattened. """ pass
[docs]class NuSMVNeedFlatHierarchyError(PyNuSMVError): """ Exception raised when the model must be flattened. """ pass
[docs]class NuSMVModelAlreadyEncodedError(PyNuSMVError): """ Exception raised when the model is already encoded. """ pass
[docs]class NuSMVFlatModelAlreadyBuiltError(PyNuSMVError): """ Exception raised when the flat model is already built. """ pass
[docs]class NuSMVNeedFlatModelError(PyNuSMVError): """ Exception raised when the model must be flattened. """ pass
[docs]class NuSMVModelAlreadyBuiltError(PyNuSMVError): """ Exception raised when the BDD model is already built. """ pass
[docs]class NuSMVNeedVariablesEncodedError(PyNuSMVError): """ Exception raised when the variables of the model must be encoded. """ pass
[docs]class NuSMVInitError(PyNuSMVError): """ NuSMV initialisation-related exception. """ pass
[docs]class NuSMVParserError(PyNuSMVError): """ Exception raised when an error occured while parsing a string with NuSMV. """ pass
[docs]class NuSMVTypeCheckingError(PyNuSMVError): """ Exception raised when an expression is wrongly typed. """ pass
[docs]class NuSMVFlatteningError(PyNuSMVError): """ Exception raised when an error occured while flattening some expression. """ pass
[docs]class NuSMVBddPickingError(PyNuSMVError): """ Exception raised when an error occured while picking a state/inputs from a BDD. """ pass
[docs]class NuSMVParsingError(PyNuSMVError): """ A :class:`NuSMVParsingError` is a NuSMV parsing exception. Contains several errors accessible through the "errors" attribute. """ def __init__(self, errors): """ Initialize this exception with errors. :param errors: a tuple of errors :type errors: tuple(:class:`Error`) """ super().__init__(self) self._errors = errors def __str__(self): return "\n".join([str(err) for err in self._errors]) def __repr__(self): return repr(self._errors) @property
[docs] def errors(self): """ The tuple of errors of this exception. """ return self._errors
Error = namedtuple('Error', ('line', 'token', 'message')) """ An :class:`Error` is a single parsing error generated by NuSMV parser. """ Error.__str__ = lambda self: "Error at line {}, token '{}': {}".format(*self) Error.__repr__ = lambda self: "Error at line {}, token '{}': {}".format(*self)