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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
use super::*;
use crate::helper::ValkyrieNode;

impl Default for ExpressionType {
    fn default() -> Self {
        Self::Placeholder
    }
}

impl Debug for PostfixCallPart {
    fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::Apply(call) => Debug::fmt(call, f),
            Self::ApplyDot(call) => Debug::fmt(call, f),
            Self::View(call) => Debug::fmt(call, f),
            Self::Generic(call) => Debug::fmt(call, f),
            Self::Lambda(call) => Debug::fmt(call, f),
            Self::LambdaDot(call) => Debug::fmt(call, f),
            Self::Match(call) => Debug::fmt(call, f),
        }
    }
}

#[cfg(feature = "pretty-print")]
impl PrettyPrint for ExpressionNode {
    fn pretty(&self, theme: &PrettyProvider) -> PrettyTree {
        self.body.pretty(theme)
    }
}

#[cfg(feature = "pretty-print")]
impl PrettyPrint for ExpressionType {
    fn pretty(&self, theme: &PrettyProvider) -> PrettyTree {
        match self {
            Self::Placeholder => unreachable!(),
            Self::Slot(node) => node.pretty(theme),
            Self::Symbol(node) => node.pretty(theme),
            Self::Number(node) => node.pretty(theme),
            Self::Text(node) => node.pretty(theme),
            Self::String(node) => node.pretty(theme),
            Self::Prefix(node) => node.pretty(theme),
            Self::Binary(node) => node.pretty(theme),
            Self::Suffix(node) => node.pretty(theme),
            Self::Table(node) => node.pretty(theme),
            Self::Apply(node) => node.pretty(theme),
            Self::ApplyDot(node) => node.pretty(theme),
            Self::LambdaCall(node) => node.pretty(theme),
            Self::LambdaDot(node) => node.pretty(theme),
            Self::Subscript(node) => node.pretty(theme),
            Self::GenericCall(node) => node.pretty(theme),
            Self::New(node) => node.pretty(theme),
            Self::Resume(node) => node.pretty(theme),
            Self::If(node) => node.pretty(theme),
            Self::IfLet(node) => node.pretty(theme),
            Self::Switch(node) => node.pretty(theme),
            Self::Try(node) => node.pretty(theme),
            Self::MatchDot(node) => node.pretty(theme),
            Self::Formatted(node) => node.pretty(theme),
            Self::Null(node) => node.pretty(theme),
            Self::Boolean(node) => node.pretty(theme),
        }
    }
}

impl PrettyPrint for PostfixCallPart {
    fn pretty(&self, theme: &PrettyProvider) -> PrettyTree {
        match self {
            Self::Apply(node) => node.pretty(theme),
            Self::ApplyDot(node) => node.pretty(theme),
            Self::View(node) => node.pretty(theme),
            Self::Generic(node) => node.pretty(theme),
            Self::Lambda(node) => node.pretty(theme),
            Self::LambdaDot(node) => node.pretty(theme),
            Self::Match(node) => node.pretty(theme),
        }
    }
}

impl ValkyrieNode for ExpressionType {
    fn get_range(&self) -> Range<u32> {
        match self {
            Self::Placeholder => unreachable!(),
            Self::Slot(node) => node.span.clone(),
            Self::Symbol(node) => node.get_range(),
            Self::Number(node) => node.span.clone(),
            Self::Text(node) => node.span.clone(),
            Self::String(node) => node.span.clone(),
            Self::New(node) => node.span.clone(),
            Self::Prefix(node) => node.span.clone(),
            Self::Binary(node) => node.get_range(),
            Self::Suffix(node) => node.span.clone(),
            Self::Table(node) => node.span.clone(),
            Self::Apply(node) => node.span.clone(),
            Self::ApplyDot(node) => node.span.clone(),
            Self::LambdaCall(node) => node.span.clone(),
            Self::LambdaDot(node) => node.span.clone(),
            Self::Subscript(node) => node.span.clone(),
            Self::GenericCall(node) => node.span.clone(),
            Self::Resume(node) => node.span.clone(),
            Self::If(node) => node.span.clone(),
            Self::IfLet(node) => node.span.clone(),
            Self::Switch(node) => node.span.clone(),
            Self::Try(node) => node.span.clone(),
            Self::MatchDot(node) => node.span.clone(),
            Self::Formatted(node) => node.span.clone(),
            Self::Null(node) => node.span.clone(),
            Self::Boolean(node) => node.span.clone(),
        }
    }
}