aws_smt_strings/
errors.rs

1// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2// SPDX-License-Identifier: Apache-2.0
3
4//!
5//! Error codes
6//!
7
8use std::fmt::Display;
9
10#[derive(Debug, PartialEq, Eq, Clone, Copy)]
11///
12/// Error codes produced by operations on partitions and regular expressions
13///
14pub enum Error {
15    /// The derivative of R with respect to a character set  C is not defined.
16    ///
17    /// This means that C is not included in a derivative class of R (i.e., it
18    /// overlaps several classes).
19    UndefinedDerivative,
20
21    /// The complementary class of a regular expression R is empty
22    ///
23    /// The deriv classes of R consists of a set of disjoint
24    /// character intervals C<sub>0</sub>, ... C<sub>n-1</sub> and an implicit complementary
25    /// class equal to complement (Union(C<sub>0</sub>, ..., C<sub>n-1</sub>)).
26    /// It's an error to try to compute the derivative of R with respect
27    /// to the complementary class if it is empty.
28    EmptyComplementaryClass,
29
30    /// The class id of a [CharSet][crate::character_sets::CharSet] `s` in a
31    /// [CharPartition][crate::character_sets::CharPartition] `p` is not defined.
32    ///
33    /// This means that `s` overlaps a class of `p` but is not contained in that class.
34    AmbiguousCharSet,
35
36    /// Bad class id for a [CharPartition][crate::character_sets::CharPartition].
37    ///
38    /// A bad class id is either of the form `ClassId::Interval(i)` where `i` is out of bound,
39    /// or `ClassId::Complement` where the complementary class is empty.
40    BadClassId,
41
42    /// Error reported where a list of disjoint char sets is expected.
43    NonDisjointCharSets,
44
45    /// No default successor specified for an automaton state when one is required.
46    MissingDefaultSuccessor,
47}
48
49impl Display for Error {
50    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
51        match &self {
52            Self::UndefinedDerivative => "undefined derivative",
53            Self::EmptyComplementaryClass => "empty complementary class",
54            Self::AmbiguousCharSet => "character set not contained in a single partition class",
55            Self::BadClassId => "bad class id",
56            Self::NonDisjointCharSets => "expected disjoint character sets",
57            Self::MissingDefaultSuccessor => "a default successor is required",
58        }
59        .fmt(f)
60    }
61}
62
63impl std::error::Error for Error {}