boseiju/lexer/tokens/intermediates/
action_keywords.rs1#[derive(idris_derive::Idris)]
3#[derive(serde::Serialize, serde::Deserialize)]
4#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
5pub enum ActionKeyword {
6 Deals {
7 #[cfg(feature = "spanned_tree")]
8 span: crate::ability_tree::span::TreeSpan,
9 },
10 Get {
11 #[cfg(feature = "spanned_tree")]
12 span: crate::ability_tree::span::TreeSpan,
13 },
14 Put {
15 #[cfg(feature = "spanned_tree")]
16 span: crate::ability_tree::span::TreeSpan,
17 },
18 Reveal {
19 #[cfg(feature = "spanned_tree")]
20 span: crate::ability_tree::span::TreeSpan,
21 },
22}
23
24#[cfg(feature = "spanned_tree")]
25impl ActionKeyword {
26 pub fn span(&self) -> crate::ability_tree::span::TreeSpan {
27 match self {
28 Self::Deals { span } => *span,
29 Self::Get { span } => *span,
30 Self::Put { span } => *span,
31 Self::Reveal { span } => *span,
32 }
33 }
34}
35
36impl ActionKeyword {
37 pub fn try_from_span(span: &crate::lexer::Span) -> Option<Self> {
38 match span.text {
39 "deal" | "deals" | "dealt" => Some(Self::Deals {
40 #[cfg(feature = "spanned_tree")]
41 span: span.into(),
42 }),
43 "get" | "gets" => Some(Self::Get {
44 #[cfg(feature = "spanned_tree")]
45 span: span.into(),
46 }),
47 "put" | "puts" => Some(Self::Put {
48 #[cfg(feature = "spanned_tree")]
49 span: span.into(),
50 }),
51 "reveal" | "reveals" => Some(Self::Reveal {
52 #[cfg(feature = "spanned_tree")]
53 span: span.into(),
54 }),
55 _ => None,
56 }
57 }
58}