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
use std::{fmt::Display, str::FromStr};

use serde::{Deserialize, Serialize};

use crate::{error::JPreprocessErrorKind, JPreprocessError};

#[derive(Clone, Copy, PartialEq, Debug, Serialize, Deserialize)]
/// 接頭詞
pub enum Settoushi {
    /// 形容詞接続
    KeiyoushiSetsuzoku,
    /// 数接続
    SuuSetsuzoku,
    /// 動詞接続
    DoushiSetsuzoku,
    /// 名詞接続
    MeishiSetsuzoku,
}

impl FromStr for Settoushi {
    type Err = JPreprocessError;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "形容詞接続" => Ok(Self::KeiyoushiSetsuzoku),
            "数接続" => Ok(Self::SuuSetsuzoku),
            "動詞接続" => Ok(Self::DoushiSetsuzoku),
            "名詞接続" => Ok(Self::MeishiSetsuzoku),
            _ => Err(JPreprocessErrorKind::PartOfSpeechParseError
                .with_error(anyhow::anyhow!("Parse failed in Settoushi"))),
        }
    }
}

impl Display for Settoushi {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(
            f,
            "{},*,*",
            match &self {
                Self::KeiyoushiSetsuzoku => "形容詞接続",
                Self::SuuSetsuzoku => "数接続",
                Self::DoushiSetsuzoku => "動詞接続",
                Self::MeishiSetsuzoku => "名詞接続",
            },
        )
    }
}