Class: Janeway::AST::BinaryOperator

Inherits:
Expression show all
Defined in:
lib/janeway/ast/binary_operator.rb

Instance Attribute Summary collapse

Attributes inherited from Expression

#value

Instance Method Summary collapse

Methods inherited from Expression

#indented, #literal?, #singular_query?, #type

Constructor Details

#initialize(operator, left = nil, right = nil) ⇒ BinaryOperator

Returns a new instance of BinaryOperator.

Raises:



8
9
10
11
12
13
14
15
# File 'lib/janeway/ast/binary_operator.rb', line 8

def initialize(operator, left = nil, right = nil)
  super(nil)
  raise ArgumentError, "expect symbol, got #{operator.inspect}" unless operator.is_a?(Symbol)

  @operator = operator
  self.left = left if left
  self.right = right if right
end

Instance Attribute Details

#leftObject

Returns the value of attribute left.



6
7
8
# File 'lib/janeway/ast/binary_operator.rb', line 6

def left
  @left
end

#operatorObject (readonly)

Returns the value of attribute operator.



6
7
8
# File 'lib/janeway/ast/binary_operator.rb', line 6

def operator
  @operator
end

#rightObject

Returns the value of attribute right.



6
7
8
# File 'lib/janeway/ast/binary_operator.rb', line 6

def right
  @right
end

Instance Method Details

#to_sObject



50
51
52
53
# File 'lib/janeway/ast/binary_operator.rb', line 50

def to_s
  # Make precedence explicit by adding parentheses
  "(#{@left} #{operator_to_s} #{@right})"
end