sql_ast/ast/
operator.rs

1// Licensed under the Apache License, Version 2.0 (the "License");
2// you may not use this file except in compliance with the License.
3// You may obtain a copy of the License at
4//
5// http://www.apache.org/licenses/LICENSE-2.0
6//
7// Unless required by applicable law or agreed to in writing, software
8// distributed under the License is distributed on an "AS IS" BASIS,
9// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10// See the License for the specific language governing permissions and
11// limitations under the License.
12
13use std::fmt;
14
15/// Unary operators
16#[derive(Debug, Clone, PartialEq, Eq, Hash)]
17pub enum UnaryOperator {
18    Plus,
19    Minus,
20    Not,
21}
22
23impl fmt::Display for UnaryOperator {
24    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
25        f.write_str(match self {
26            UnaryOperator::Plus => "+",
27            UnaryOperator::Minus => "-",
28            UnaryOperator::Not => "NOT",
29        })
30    }
31}
32
33/// Binary operators
34#[derive(Debug, Clone, PartialEq, Eq, Hash)]
35pub enum BinaryOperator {
36    Plus,
37    Minus,
38    Multiply,
39    Divide,
40    Modulus,
41    Gt,
42    Lt,
43    GtEq,
44    LtEq,
45    Eq,
46    NotEq,
47    And,
48    Or,
49    Like,
50    Ilike,
51    NotLike,
52    In,
53}
54
55impl fmt::Display for BinaryOperator {
56    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
57        f.write_str(match self {
58            BinaryOperator::Plus => "+",
59            BinaryOperator::Minus => "-",
60            BinaryOperator::Multiply => "*",
61            BinaryOperator::Divide => "/",
62            BinaryOperator::Modulus => "%",
63            BinaryOperator::Gt => ">",
64            BinaryOperator::Lt => "<",
65            BinaryOperator::GtEq => ">=",
66            BinaryOperator::LtEq => "<=",
67            BinaryOperator::Eq => "=",
68            BinaryOperator::NotEq => "<>",
69            BinaryOperator::And => "AND",
70            BinaryOperator::Or => "OR",
71            BinaryOperator::Like => "LIKE",
72            BinaryOperator::Ilike => "ILIKE",
73            BinaryOperator::NotLike => "NOT LIKE",
74            BinaryOperator::In => "IN",
75        })
76    }
77}