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