1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//! AST nodes for constants (literals).
use crate::{language::SyntaxToken, AstToken, SyntaxKind};

use SyntaxKind::*;

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Scon {
    Int(SyntaxToken),
    Real(SyntaxToken),
    Word(SyntaxToken),
    Char(SyntaxToken),
    String(SyntaxToken),
}

impl AstToken for Scon {
    fn syntax(&self) -> &SyntaxToken {
        match self {
            Self::Int(s) => s,
            Self::Real(s) => s,
            Self::Word(s) => s,
            Self::Char(s) => s,
            Self::String(s) => s,
        }
    }

    fn cast(token: SyntaxToken) -> Option<Self>
    where
        Self: Sized,
    {
        match token.kind() {
            INT => Some(Self::Int(token)),
            REAL => Some(Self::Real(token)),
            WORD => Some(Self::Word(token)),
            CHAR => Some(Self::Char(token)),
            STRING => Some(Self::String(token)),
            _ => None,
        }
    }
}

//  #[derive(Debug, Clone, PartialEq, Eq, Hash)]
//  pub struct Int {
//      syntax: SyntaxToken,
//  }
//
//  impl_ast_token!(Int, INT);
//
//  impl Int {
//      // Sketchy for now
//      // Obviously will fail if the number is negated ("~")
//      pub fn parse<F: FromStr>(&self) -> F
//      where
//          <F as FromStr>::Err: std::fmt::Debug,
//      {
//          self.syntax().text().parse::<F>().unwrap()
//      }
//  }
//
//  #[derive(Debug, Clone, PartialEq, Eq, Hash)]
//  pub struct Real {
//      syntax: SyntaxToken,
//  }
//
//  impl_ast_token!(Real, REAL);
//
//  #[derive(Debug, Clone, PartialEq, Eq, Hash)]
//  pub struct Word {
//      syntax: SyntaxToken,
//  }
//
//  impl_ast_token!(Word, WORD);
//
//  #[derive(Debug, Clone, PartialEq, Eq, Hash)]
//  pub struct Char {
//      syntax: SyntaxToken,
//  }
//
//  impl_ast_token!(Char, CHAR);
//
//  #[derive(Debug, Clone, PartialEq, Eq, Hash)]
//  pub struct String {
//      syntax: SyntaxToken,
//  }
//
//  impl_ast_token!(String, STRING);