jpreprocess_core/ctype/
sa_irregular.rs1use std::{fmt::Display, str::FromStr};
2
3use serde::{Deserialize, Serialize};
4
5use super::{CTypeKind, CTypeParseError};
6
7#[derive(Clone, Copy, PartialEq, Debug, Serialize, Deserialize)]
8pub enum SaIrregular {
10 Alone,
12 ConjugationSuru,
14 ConjugationZuru,
16}
17
18impl FromStr for SaIrregular {
19 type Err = CTypeParseError;
20 fn from_str(s: &str) -> Result<Self, Self::Err> {
21 match s {
22 "スル" => Ok(Self::Alone),
23 "-スル" => Ok(Self::ConjugationSuru),
24 "-ズル" => Ok(Self::ConjugationZuru),
25 "−スル" => Ok(Self::ConjugationSuru),
26 "−ズル" => Ok(Self::ConjugationZuru),
27 _ => Err(CTypeParseError::new(s.to_string(), CTypeKind::SaIrregular)),
28 }
29 }
30}
31
32impl Display for SaIrregular {
33 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34 f.write_str(match &self {
35 Self::Alone => "スル",
36 Self::ConjugationSuru => "−スル",
37 Self::ConjugationZuru => "−ズル",
38 })
39 }
40}