boseiju/lexer/tokens/intermediates/
damage_kind.rs

1#[derive(idris_derive::Idris)]
2#[derive(serde::Serialize, serde::Deserialize)]
3#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
4pub enum DamageKind {
5    Damage {
6        #[cfg(feature = "spanned_tree")]
7        span: crate::ability_tree::span::TreeSpan,
8    },
9    CombatDamage {
10        #[cfg(feature = "spanned_tree")]
11        span: crate::ability_tree::span::TreeSpan,
12    },
13    NoncombatDamage {
14        #[cfg(feature = "spanned_tree")]
15        span: crate::ability_tree::span::TreeSpan,
16    },
17}
18
19#[cfg(feature = "spanned_tree")]
20impl DamageKind {
21    pub fn span(&self) -> crate::ability_tree::span::TreeSpan {
22        match self {
23            Self::Damage { span } => *span,
24            Self::CombatDamage { span } => *span,
25            Self::NoncombatDamage { span } => *span,
26        }
27    }
28}
29
30impl DamageKind {
31    pub fn try_from_span(span: &crate::lexer::Span) -> Option<Self> {
32        match span.text {
33            "damage" | "damages" => Some(Self::Damage {
34                #[cfg(feature = "spanned_tree")]
35                span: span.into(),
36            }),
37            "combat damage" => Some(Self::CombatDamage {
38                #[cfg(feature = "spanned_tree")]
39                span: span.into(),
40            }),
41            "noncombat damage" => Some(Self::NoncombatDamage {
42                #[cfg(feature = "spanned_tree")]
43                span: span.into(),
44            }),
45            _ => None,
46        }
47    }
48}