2018-12-13 13:39:08 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
module Gitlab
|
|
|
|
module Ci
|
|
|
|
module Pipeline
|
|
|
|
module Expression
|
|
|
|
module Lexeme
|
|
|
|
class Operator < Lexeme::Base
|
2019-09-04 21:01:54 +05:30
|
|
|
# This operator class is design to handle single operators that take two
|
|
|
|
# arguments. Expression::Parser was originally designed to read infix operators,
|
|
|
|
# and so the two operands are called "left" and "right" here. If we wish to
|
|
|
|
# implement an Operator that takes a greater or lesser number of arguments, a
|
|
|
|
# structural change or additional Operator superclass will likely be needed.
|
|
|
|
|
|
|
|
OperatorError = Class.new(Expression::ExpressionError)
|
|
|
|
|
|
|
|
def initialize(left, right)
|
|
|
|
raise OperatorError, 'Invalid left operand' unless left.respond_to? :evaluate
|
|
|
|
raise OperatorError, 'Invalid right operand' unless right.respond_to? :evaluate
|
|
|
|
|
|
|
|
@left = left
|
|
|
|
@right = right
|
|
|
|
end
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
def self.type
|
|
|
|
:operator
|
|
|
|
end
|
2019-09-04 21:01:54 +05:30
|
|
|
|
|
|
|
def self.precedence
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
2018-03-27 19:54:05 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|