boseiju/lexer/tokens/intermediates/
plus_minus.rs

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