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
#[cfg(feature = "size-of")]
use size_of::SizeOf;

use crate::code_point::CodePoint;
use crate::structure::Located;
use crate::structure::rlt::new_types::Enclosed;
use crate::structure::span::Span;

#[derive(Clone, Debug, PartialEq)]
pub enum Literal {
    Binary(Span),
    Octal(Span),
    Hex(Span),
    Floating(Span),
    Char(Span),
    String(Span),
    Tuple(Enclosed<Box<[Literal]>>),
}

#[cfg(feature = "size-of")]
impl SizeOf for Literal {
    fn size_of_children(&self, context: &mut size_of::Context) {
        match self {
            Literal::Binary(x) => x.size_of_children(context),
            Literal::Octal(x) => x.size_of_children(context),
            Literal::Hex(x) => x.size_of_children(context),
            Literal::Floating(x) => x.size_of_children(context),
            Literal::Char(x) => x.size_of_children(context),
            Literal::String(x) => x.size_of_children(context),
            Literal::Tuple(x) => x.size_of_children(context),
        }
    }
}

impl Located for Literal {
    fn location(&self) -> CodePoint {
        match self {
            Literal::Binary(x) => x.location(),
            Literal::Octal(x) => x.location(),
            Literal::Hex(x) => x.location(),
            Literal::Floating(x) => x.location(),
            Literal::Char(x) => x.location(),
            Literal::String(x) => x.location(),
            Literal::Tuple(x) => x.left.location(),
        }
    }
}