# This file is part of A Boneless Datastructure Language # Copyright (C) 2020 Soni L. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . """ABDL Exceptions. The exceptions for pattern and validation errors are defined here. """ import warnings class DeprecationError(Exception): """Raised for deprecated features, if they are disabled. This class controls warning/error behaviour of deprecated features. Note: This class is deprecated. Use ``abdl.feature`` instead. """ # enable_key_match_compat = False # warn_key_match_compat = False def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) warnings.warn("DeprecationError is deprecated. " "Use ``abdl.feature`` instead.", DeprecationWarning) @classmethod def warn_all(cls): """Enables all deprecation warnings.""" warnings.warn("DeprecationError is deprecated. " "Use ``abdl.feature`` instead.", DeprecationWarning) class PatternError(Exception): """Raised for invalid input or output expressions.""" # TODO implement formatting def __init__(self, msg, pattern=None, defs=None, pos=None, toks=None): super().__init__(msg, pattern, defs, pos, toks) self.msg = msg self.pattern = pattern self.defs = defs self.pos = pos self._toks = toks # internal use def _normalize(self, pattern, defs): if pattern is not None: if self.pattern is not None: raise ValueError("Attempt to normalize normalized pattern") self.pattern = pattern if defs is not None: if self.defs is not None: raise ValueError("Attempt to normalize normalized defs") self.defs = defs class ValidationError(Exception): """Raised when the object tree doesn't validate against the given pattern.""" # FIXME TODO?