boseiju/lexer/tokens/intermediates/
tap_untap_cost.rs

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