boseiju/lexer/tokens/intermediates/
card_actions.rs

1#[derive(idris_derive::Idris)]
2#[derive(serde::Serialize, serde::Deserialize)]
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
4pub enum CardActions {
5    Blocks {
6        #[cfg(feature = "spanned_tree")]
7        span: crate::ability_tree::span::TreeSpan,
8    },
9    Dies {
10        #[cfg(feature = "spanned_tree")]
11        span: crate::ability_tree::span::TreeSpan,
12    },
13    Enters {
14        #[cfg(feature = "spanned_tree")]
15        span: crate::ability_tree::span::TreeSpan,
16    },
17    Fight {
18        #[cfg(feature = "spanned_tree")]
19        span: crate::ability_tree::span::TreeSpan,
20    },
21    Leave {
22        #[cfg(feature = "spanned_tree")]
23        span: crate::ability_tree::span::TreeSpan,
24    },
25}
26
27#[cfg(feature = "spanned_tree")]
28impl CardActions {
29    pub fn span(&self) -> crate::ability_tree::span::TreeSpan {
30        match self {
31            Self::Blocks { span } => *span,
32            Self::Dies { span } => *span,
33            Self::Enters { span } => *span,
34            Self::Fight { span } => *span,
35            Self::Leave { span } => *span,
36        }
37    }
38}
39
40impl CardActions {
41    pub fn try_from_span(span: &crate::lexer::Span) -> Option<Self> {
42        match span.text {
43            "block" | "blocks" | "blocked" => Some(Self::Blocks {
44                #[cfg(feature = "spanned_tree")]
45                span: span.into(),
46            }),
47            "die" | "dies" | "died" => Some(Self::Dies {
48                #[cfg(feature = "spanned_tree")]
49                span: span.into(),
50            }),
51            "enter" | "enters" | "entered" => Some(Self::Enters {
52                #[cfg(feature = "spanned_tree")]
53                span: span.into(),
54            }),
55            "fight" | "fights" | "fighted" => Some(Self::Fight {
56                #[cfg(feature = "spanned_tree")]
57                span: span.into(),
58            }),
59            "leave" | "leaves" | "left" => Some(Self::Leave {
60                #[cfg(feature = "spanned_tree")]
61                span: span.into(),
62            }),
63            _ => None,
64        }
65    }
66}