sql_fun_sqlast/sem/
operators.rs1use crate::sem::TypeReference;
2
3#[derive(Debug, Clone, Eq, Hash, PartialEq, serde::Serialize, serde::Deserialize)]
5pub struct BinaryOperatorDefinition {
6 left_arg_type: TypeReference,
7 right_arg_type: TypeReference,
8 result_type: TypeReference,
9 strict: bool,
10}
11
12impl BinaryOperatorDefinition {
13 #[must_use]
15 pub fn new(
16 left_arg_type: &TypeReference,
17 right_arg_type: &TypeReference,
18 result_type: &TypeReference,
19 strict: bool,
20 ) -> Self {
21 Self {
22 left_arg_type: left_arg_type.clone(),
23 right_arg_type: right_arg_type.clone(),
24 result_type: result_type.clone(),
25 strict,
26 }
27 }
28
29 #[must_use]
31 pub fn get_return_type(&self) -> &TypeReference {
32 &self.result_type
33 }
34
35 #[must_use]
37 pub fn is_strict(&self) -> bool {
38 self.strict
39 }
40
41 #[must_use]
43 pub fn left_arg_type(&self) -> &TypeReference {
44 &self.left_arg_type
45 }
46
47 #[must_use]
49 pub fn right_arg_type(&self) -> &TypeReference {
50 &self.right_arg_type
51 }
52}
53
54#[derive(Debug, Clone, Eq, Hash, PartialEq, serde::Serialize, serde::Deserialize)]
56pub struct UnaryOperatorDefinition {
57 arg_type: TypeReference,
58 result_type: TypeReference,
59 strict: bool,
60}
61
62impl UnaryOperatorDefinition {
63 #[must_use]
65 pub fn new(arg_type: &TypeReference, result_type: &TypeReference, strict: bool) -> Self {
66 Self {
67 arg_type: arg_type.clone(),
68 result_type: result_type.clone(),
69 strict,
70 }
71 }
72
73 #[must_use]
75 pub fn get_return_type(&self) -> &TypeReference {
76 &self.result_type
77 }
78
79 #[must_use]
81 pub fn is_strict(&self) -> bool {
82 self.strict
83 }
84
85 #[must_use]
87 pub fn arg_type(&self) -> &TypeReference {
88 &self.arg_type
89 }
90}
91
92#[derive(Debug, Clone)]
94pub enum OperatorDefinition {
95 Binary(Vec<BinaryOperatorDefinition>),
97 LeftUnary(Vec<UnaryOperatorDefinition>),
99 RightUnary(Vec<UnaryOperatorDefinition>),
101}
102
103impl OperatorDefinition {
104 #[must_use]
106 pub fn binary(binaries: &[BinaryOperatorDefinition]) -> Self {
107 Self::Binary(Vec::from_iter(binaries.to_vec()))
108 }
109
110 #[must_use]
112 pub fn left_unary(unaries: &[UnaryOperatorDefinition]) -> Self {
113 Self::LeftUnary(Vec::from_iter(unaries.to_vec()))
114 }
115
116 #[must_use]
118 pub fn right_unary(unaries: &[UnaryOperatorDefinition]) -> Self {
119 Self::RightUnary(Vec::from_iter(unaries.to_vec()))
120 }
121}