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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
use super::*;
impl crate::MainPrefixNode {
    pub fn as_operator(&self) -> OperatorNode {
        use ValkyrieOperator::*;
        let o = match self.text.as_str() {
            "!" => Not,
            "+" => Positive,
            "-" => Negative,
            "&" => Box,
            "*" => Unbox,
            "⅟" => Reciprocal,
            "√" => Roots(2),
            "∛" => Roots(3),
            "∜" => Roots(4),
            ".." => Unpack { level: 2 },
            "..." => Unpack { level: 3 },
            _ => unimplemented!("{} is a unknown prefix operator", self.text),
        };
        OperatorNode { kind: o, span: self.span.clone() }
    }
}
impl crate::TypePrefixNode {
    pub fn as_operator(&self) -> OperatorNode {
        use ValkyrieOperator::*;
        let o = match self.text.as_str() {
            "!" => Not,
            "+" => CovariantType,
            "-" => ContravariantType,
            "&" => Box,
            _ => unimplemented!("{} is a unknown prefix operator", self.text),
        };
        OperatorNode { kind: o, span: self.span.clone() }
    }
}
impl crate::MainInfixNode {
    pub fn as_operator(&self) -> OperatorNode {
        use valkyrie_ast::LogicMatrix;
        use ValkyrieOperator::*;
        let o = match self.text.as_str() {
            s if s.starts_with("is") => Is { negative: s.ends_with("not") },
            s if s.ends_with("in") => In { negative: s.ends_with("not") },
            "∈" | "∊" => In { negative: false },
            "∉" => In { negative: true },
            "∋" => Contains { negative: false },
            "∌" => Contains { negative: true },

            "+" => Plus,
            "+=" => PlusAssign,
            "-" => Minus,
            "-=" => MinusAssign,
            "*" => Multiply,
            "/" => Divide,
            "⁒" | "٪" | "%%" => Modulo,
            "%" => Remainder,
            "÷" | "/%" => DivideRemainder,
            "^" => Power,
            "=" => Assign { monadic: false },
            "?=" => Assign { monadic: true },
            "==" => Equal { negative: false },
            "≠" | "!=" => Equal { negative: true },
            "≡" | "===" => StrictlyEqual { negative: false },
            "≢" | "!==" | "=!=" => StrictlyEqual { negative: true },
            ">" => Greater { equal: false },
            "≥" | ">=" => Greater { equal: true },
            "≫" | ">>" => MuchGreater,
            "⋙" | ">>>" => VeryMuchGreater,
            ">>=" => Placeholder,
            "<" => Less { equal: false },
            "≤" | "<=" => Less { equal: true },
            "≪" | "<<" => MuchLess,
            "⋘" | "<<<" => VeryMuchLess,
            "<<=" => Placeholder,
            // logic operators
            "∧" | "&&" => LogicMatrix::And.into(),
            "⊼" => LogicMatrix::Nand.into(),
            "⩟" => LogicMatrix::Xnor.into(), // aka. xand
            "∨" | "||" => LogicMatrix::Or.into(),
            "⊽" => LogicMatrix::Nor.into(),
            "⊻" => LogicMatrix::Xor.into(),
            // range
            "..<" => RangeTo { equal: false },
            "..=" => RangeTo { equal: true },
            // list operator
            "⇴" | "⨵" | "⊕" | "⟴" => Map,
            _ => unimplemented!("{} is a unknown infix operator", self.text),
        };
        OperatorNode { kind: o, span: self.span.clone() }
    }
}
impl crate::TypeInfixNode {
    pub fn as_operator(&self) -> OperatorNode {
        use ValkyrieOperator::*;
        let o = match self.text.as_str() {
            "+" => Plus,
            "->" => CovariantType,
            _ => unimplemented!("{} is a unknown infix type operator", self.text),
        };
        OperatorNode { kind: o, span: self.span.clone() }
    }
}
impl crate::MainSuffixNode {
    pub fn as_operator(&self) -> OperatorNode {
        use ValkyrieOperator::*;
        let o = match self.text.as_str() {
            "!" => QuickRaise,
            "℃" => Celsius,
            "℉" => Fahrenheit,
            "⁒" | "٪" => DivideByDecimal { power: 1 },
            "%" => DivideByDecimal { power: 2 },
            "‰" => DivideByDecimal { power: 3 },
            "‱" => DivideByDecimal { power: 4 },
            _ => unimplemented!("{} is a unknown suffix operator", self.text),
        };
        OperatorNode { kind: o, span: self.span.clone() }
    }
}

impl crate::TypeSuffixNode {
    pub fn as_operator(&self) -> OperatorNode {
        use ValkyrieOperator::*;
        let o = match self.text.as_str() {
            "!" => QuickRaise,
            "?" => Celsius,
            _ => unimplemented!("{} is a unknown type suffix operator", self.text),
        };
        OperatorNode { kind: o, span: self.span.clone() }
    }
}