A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://ruby-syntax-tree.github.io/syntax_tree/SyntaxTree/Binary.html below:

class SyntaxTree::Binary - RDoc Documentation

  1. SyntaxTree::
  2. Binary
class SyntaxTree::Binary

Binary represents any expression that involves two sub-expressions with an operator in between. This can be something that looks like a mathematical operation:

1 + 1

but can also be something like pushing a value onto an array:

array << value
Attributes
Node

the left-hand side of the expression

Symbol

the operator used between the two expressions

Node

the right-hand side of the expression

Public Class Methods

Source

def initialize(left:, operator:, right:, location:)
  @left = left
  @operator = operator
  @right = right
  @location = location
  @comments = []
end
Public Instance Methods

Source

def ===(other)
  other.is_a?(Binary) && left === other.left &&
    operator === other.operator && right === other.right
end

Source

def accept(visitor)
  visitor.visit_binary(self)
end

Source

def child_nodes
  [left, right]
end

Source

def copy(left: nil, operator: nil, right: nil, location: nil)
  node =
    Binary.new(
      left: left || self.left,
      operator: operator || self.operator,
      right: right || self.right,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end

Source

def deconstruct_keys(_keys)
  {
    left: left,
    operator: operator,
    right: right,
    location: location,
    comments: comments
  }
end

Source

def format(q)
  left = self.left
  power = operator == :**

  q.group do
    q.group { q.format(left) }
    q.text(" ") unless power

    if operator != :<<
      q.group do
        q.text(operator.name)
        q.indent do
          power ? q.breakable_empty : q.breakable_space
          q.format(right)
        end
      end
    elsif left.is_a?(Binary) && left.operator == :<<
      q.group do
        q.text(operator.name)
        q.indent do
          power ? q.breakable_empty : q.breakable_space
          q.format(right)
        end
      end
    else
      q.text("<< ")
      q.format(right)
    end
  end
end

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4