|
| 1 | +import Foundation |
| 2 | + |
| 3 | +public class BinaryOperator: Expression { |
| 4 | + var lhs: Expression |
| 5 | + var rhs: Expression |
| 6 | + var operatorType: BinaryOperatorType |
| 7 | + |
| 8 | + init(lhs: Expression, rhs: Expression, operatorType: BinaryOperatorType) { |
| 9 | + self.lhs = lhs |
| 10 | + self.rhs = rhs |
| 11 | + self.operatorType = operatorType |
| 12 | + } |
| 13 | +} |
| 14 | + |
| 15 | +extension BinaryOperator: Serializable { |
| 16 | + public func serialize(with schemaProvider: SchemaProvider) throws -> String { |
| 17 | + let leftString = try self.lhs.serialize(with: schemaProvider) |
| 18 | + let rightString = try self.rhs.serialize(with: schemaProvider) |
| 19 | + return "\(leftString) \(self.operatorType) \(rightString)" |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +public func equal(lhs: Expression, rhs: Expression) -> BinaryOperator { |
| 24 | + return BinaryOperator(lhs: lhs, rhs: rhs, operatorType: .equal) |
| 25 | +} |
| 26 | + |
| 27 | +public func notEqual(lhs: Expression, rhs: Expression) -> BinaryOperator { |
| 28 | + return BinaryOperator(lhs: lhs, rhs: rhs, operatorType: .notEqual) |
| 29 | +} |
| 30 | + |
| 31 | +public func lesserThan(lhs: Expression, rhs: Expression) -> BinaryOperator { |
| 32 | + return BinaryOperator(lhs: lhs, rhs: rhs, operatorType: .lesserThan) |
| 33 | +} |
| 34 | + |
| 35 | +public func lesserOrEqual(lhs: Expression, rhs: Expression) -> BinaryOperator { |
| 36 | + return BinaryOperator(lhs: lhs, rhs: rhs, operatorType: .lesserOrEqual) |
| 37 | +} |
| 38 | + |
| 39 | +public func greaterThan(lhs: Expression, rhs: Expression) -> BinaryOperator { |
| 40 | + return BinaryOperator(lhs: lhs, rhs: rhs, operatorType: .greaterThan) |
| 41 | +} |
| 42 | + |
| 43 | +public func greaterOrEqual(lhs: Expression, rhs: Expression) -> BinaryOperator { |
| 44 | + return BinaryOperator(lhs: lhs, rhs: rhs, operatorType: .greaterOrEqual) |
| 45 | +} |
0 commit comments