summary refs log tree commit diff stats
path: root/abdl/exceptions.py
diff options
context:
space:
mode:
authorSoniEx2 <endermoneymod@gmail.com>2020-02-03 11:30:04 -0300
committerSoniEx2 <endermoneymod@gmail.com>2020-02-03 11:30:04 -0300
commite9f667fdb1cf4176d9bd62e7fbbecedb60cde008 (patch)
tree06f5f35148cfcb371fd8203679e0c25c021a6bce /abdl/exceptions.py
parentbc9bfb31bb009a7f3fa8ce79a4f1afdb74ce58c0 (diff)
Add broken stuff
Diffstat (limited to 'abdl/exceptions.py')
-rw-r--r--abdl/exceptions.py74
1 files changed, 74 insertions, 0 deletions
diff --git a/abdl/exceptions.py b/abdl/exceptions.py
new file mode 100644
index 0000000..961acff
--- /dev/null
+++ b/abdl/exceptions.py
@@ -0,0 +1,74 @@
+# 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?