Class: Janeway::AST::BinaryOperator
- Inherits:
-
Expression
- Object
- Expression
- Janeway::AST::BinaryOperator
- Defined in:
- lib/janeway/ast/binary_operator.rb
Overview
AST node for binary operators:
== != <= >= < > || &&
Instance Attribute Summary collapse
-
#left ⇒ Object
Returns the value of attribute left.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#right ⇒ Object
Returns the value of attribute right.
Attributes inherited from Expression
Instance Method Summary collapse
-
#comparison_operator? ⇒ Boolean
True if this operator is a comparison operator.
-
#initialize(operator, left = nil, right = nil) ⇒ BinaryOperator
constructor
A new instance of BinaryOperator.
-
#logical_operator? ⇒ Boolean
True if this operator is a logical operator.
- #to_s ⇒ Object
- #tree(level) ⇒ Array
Methods inherited from Expression
#indented, #literal?, #singular_query?, #type
Constructor Details
#initialize(operator, left = nil, right = nil) ⇒ BinaryOperator
Returns a new instance of BinaryOperator.
10 11 12 13 14 15 16 17 |
# File 'lib/janeway/ast/binary_operator.rb', line 10 def initialize(operator, left = nil, right = nil) super(nil) raise ArgumentError, "expect symbol, got #{operator.inspect}" unless operator.is_a?(Symbol) @name = operator # eg. :equal self.left = left if left self.right = right if right end |
Instance Attribute Details
#left ⇒ Object
Returns the value of attribute left.
8 9 10 |
# File 'lib/janeway/ast/binary_operator.rb', line 8 def left @left end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/janeway/ast/binary_operator.rb', line 8 def name @name end |
#right ⇒ Object
Returns the value of attribute right.
8 9 10 |
# File 'lib/janeway/ast/binary_operator.rb', line 8 def right @right end |
Instance Method Details
#comparison_operator? ⇒ Boolean
True if this operator is a comparison operator
69 70 71 |
# File 'lib/janeway/ast/binary_operator.rb', line 69 def comparison_operator? operator_type == :comparison end |
#logical_operator? ⇒ Boolean
True if this operator is a logical operator
75 76 77 |
# File 'lib/janeway/ast/binary_operator.rb', line 75 def logical_operator? operator_type == :logical end |
#to_s ⇒ Object
52 53 54 55 |
# File 'lib/janeway/ast/binary_operator.rb', line 52 def to_s # Make precedence explicit by adding parentheses "(#{@left} #{operator_to_s} #{@right})" end |
#tree(level) ⇒ Array
59 60 61 62 63 64 65 |
# File 'lib/janeway/ast/binary_operator.rb', line 59 def tree(level) [ indented(level, to_s), @left.tree(level + 1), @right.tree(level + 1), ] end |