1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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?
|