Skip to main content

java_lang/ast/
lit.rs

1//! Literal types.
2
3use crate::span::Span;
4
5/// A Java literal value.
6#[derive(Debug, Clone, PartialEq, Eq, Hash)]
7pub enum Lit {
8    Int(IntLit),
9    Float(FloatLit),
10    Bool(BoolLit),
11    Char(CharLit),
12    Str(StrLit),
13    Null(NullLit),
14}
15
16impl Lit {
17    pub fn span(&self) -> Span {
18        match self {
19            Self::Int(l) => l.span,
20            Self::Float(l) => l.span,
21            Self::Bool(l) => l.span,
22            Self::Char(l) => l.span,
23            Self::Str(l) => l.span,
24            Self::Null(l) => l.span,
25        }
26    }
27}
28
29#[derive(Debug, Clone, PartialEq, Eq, Hash)]
30pub struct IntLit {
31    pub value: String,
32    pub span: Span,
33}
34
35#[derive(Debug, Clone, PartialEq, Eq, Hash)]
36pub struct FloatLit {
37    pub value: String,
38    pub span: Span,
39}
40
41#[derive(Debug, Clone, PartialEq, Eq, Hash)]
42pub struct BoolLit {
43    pub value: bool,
44    pub span: Span,
45}
46
47#[derive(Debug, Clone, PartialEq, Eq, Hash)]
48pub struct CharLit {
49    pub value: String,
50    pub span: Span,
51}
52
53#[derive(Debug, Clone, PartialEq, Eq, Hash)]
54pub struct StrLit {
55    pub value: String,
56    pub span: Span,
57}
58
59#[derive(Debug, Clone, PartialEq, Eq, Hash)]
60pub struct NullLit {
61    pub span: Span,
62}