boseiju/ability_tree/terminals/
saga_chapter_number.rs1use crate::lexer::IntoToken;
2
3#[derive(serde::Serialize, serde::Deserialize)]
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
5pub struct SagaChapterNumber {
6 pub chapter: u32,
7 #[cfg(feature = "spanned_tree")]
8 pub span: crate::ability_tree::span::TreeSpan,
9}
10
11impl SagaChapterNumber {
12 pub const COUNT: usize = 1;
13 pub const fn id(&self) -> usize {
14 0
15 }
16}
17
18impl std::fmt::Display for SagaChapterNumber {
19 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20 write!(f, "saga chapter {}", self.chapter)
21 }
22}
23
24#[cfg(feature = "lexer")]
25impl IntoToken for SagaChapterNumber {
26 fn try_from_span(span: &crate::lexer::Span) -> Option<Self> {
27 match span.text {
28 "i" => Some(SagaChapterNumber {
29 chapter: 1,
30 #[cfg(feature = "spanned_tree")]
31 span: span.into(),
32 }),
33 "ii" => Some(SagaChapterNumber {
34 chapter: 2,
35 #[cfg(feature = "spanned_tree")]
36 span: span.into(),
37 }),
38 "iii" => Some(SagaChapterNumber {
39 chapter: 3,
40 #[cfg(feature = "spanned_tree")]
41 span: span.into(),
42 }),
43 "iv" => Some(SagaChapterNumber {
44 chapter: 4,
45 #[cfg(feature = "spanned_tree")]
46 span: span.into(),
47 }),
48 "v" => Some(SagaChapterNumber {
49 chapter: 5,
50 #[cfg(feature = "spanned_tree")]
51 span: span.into(),
52 }),
53 "vi" => Some(SagaChapterNumber {
54 chapter: 6,
55 #[cfg(feature = "spanned_tree")]
56 span: span.into(),
57 }),
58 _ => None,
59 }
60 }
61}