# 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 <https://www.gnu.org/licenses/>.
class DeprecationError(Exception):
"""Raised for deprecated features, if they are disabled.
This class controls warning/error behaviour of deprecated features."""
#enable_key_match_compat = False
#warn_key_match_compat = False
@classmethod
def warn_all(cls):
"""Enables all deprecation warnings."""
pass
class PatternError(Exception):
"""Raised for invalid input or output expressions."""
# TODO implement formatting
def __init__(self, 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")
else:
self.pattern = pattern
if defs is not None:
if self.defs is not None:
raise ValueError("Attempt to normalize normalized defs")
else:
self.defs = defs
@classmethod
def _str_escape(cls, s, pos, toks):
raise cls("Error in string escape", None, None, pos, toks)
@classmethod
def _str_end(cls, s, pos, toks):
raise cls("Unfinished string", None, None, pos, toks)
@classmethod
def _re_escape(cls, s, pos, toks):
raise cls("Error in regex escape", None, None, pos, toks)
@classmethod
def _re_end(cls, s, pos, toks):
raise cls("Unfinished regex", None, None, pos, toks)
@classmethod
def _unexpected_tok(cls, s, pos, toks):
raise cls("Unexpected token", None, None, pos, toks)
class ValidationError(Exception):
"""Raised when the object tree doesn't validate against the given pattern."""
# FIXME TODO?