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 << valueAttributes
Node
the left-hand side of the expression
the operator used between the two expressions
Node
the right-hand side of the expression
def initialize(left:, operator:, right:, location:) @left = left @operator = operator @right = right @location = location @comments = [] endPublic Instance Methods Source
def ===(other) other.is_a?(Binary) && left === other.left && operator === other.operator && right === other.right endSource
def accept(visitor) visitor.visit_binary(self) endSource
def child_nodes [left, right] endSource
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 endSource
def deconstruct_keys(_keys) { left: left, operator: operator, right: right, location: location, comments: comments } endSource
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