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
75
76
77
78
use thiserror::Error;

use crate::analyzer::{Parse, Tag};

pub type MopsResult<T, E = MopsErr> = std::result::Result<T, E>;

#[derive(Debug, Error)]
pub enum MopsErr {
    #[error("IO err -> {0}")]
    IO(#[from] std::io::Error),

    #[error("XML deserialize err -> {0}")]
    XMLde(#[from] quick_xml::DeError),

    #[error("Serde err -> {0}")]
    Serde(#[from] serde_json::error::Error),

    #[error("Mops dictionary err -> {0}")]
    Dictionary(#[from] DictionaryErr),

    #[error("Fst map err -> {0}")]
    FSTMap(#[from] fst::Error),

    #[error("Parse err -> {0}")]
    Parse(#[from] ParseErr),
}

#[derive(Debug, Error)]
pub enum DictionaryErr {
    #[error("IO err -> {0}")]
    IO(#[from] std::io::Error),

    #[error("Fst err -> {0}")]
    FstBuild(#[from] fst::Error),

    #[error("SmallString conversion err -> {0}")]
    SmallString(#[source] core::convert::Infallible),

    #[error("SmallVec conversion err -> {0}")]
    SmallVec(#[source] core::convert::Infallible),

    #[error("Binary search not found tag: {0:?}")]
    BinaryTag(Tag),

    #[error("Binary search not found lemma: {0}")]
    BinaryLemma(String),

    #[error("Binary search not found parses: {0:?}")]
    BinaryParse(Vec<Parse>),

    #[error("No normal form in lemma {0}")]
    LostNormalForm(u64),

    #[error("No word form in lemma {0}")]
    NoForms(u64),
}

#[derive(Debug, derive_more::Display)]
pub enum Bound {
    #[display(fmt = "word_parses")]
    WordParses,
    #[display(fmt = "tags")]
    Tags,
    #[display(fmt = "lemmas")]
    Lemmas,
}

#[derive(Debug, Error)]
pub enum ParseErr {
    #[error("Index of search {idx} more than {vec} len")]
    OutOfBound { idx: u64, vec: Bound },

    #[error("Word from dictionary {0} lost his normal form")]
    LostNormal(String),

    #[error("To be continued...")]
    FutureRelease,
}