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
use crate::ast::{self, support::*};

// this is a separate type because it mixes tokens and nodes
// for example, a Str is a node because it can contain nested subexpressions but an Integer is a token.
// This means that we have to write it out manually instead of using the macro to create the type for us.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum LiteralKind {
    Float(ast::Float),
    Integer(ast::Integer),
    Uri(ast::Uri),
}

impl ast::Literal {
    pub fn kind(&self) -> LiteralKind {
        if let Some(it) = token(self) {
            return LiteralKind::Float(it);
        }

        if let Some(it) = token(self) {
            return LiteralKind::Integer(it);
        }

        if let Some(it) = token(self) {
            return LiteralKind::Uri(it);
        }

        unreachable!()
    }
}