Class: SyntaxTree::Dot3

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree.rb

Overview

Dot3 represents using the … operator between two expressions. Usually this is to create a range object. It’s effectively the same event as the Dot2 node but with this operator you’re asking Ruby to omit the final value.

1...2

Like Dot2 it can also be used to create a flip-flop.

if value == 5 ... value == 10
end

One of the sides of the expression may be nil, but not both.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(left:, right:, location:, comments: []) ⇒ Dot3

Returns a new instance of Dot3.



5034
5035
5036
5037
5038
5039
# File 'lib/syntax_tree.rb', line 5034

def initialize(left:, right:, location:, comments: [])
  @left = left
  @right = right
  @location = location
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



5032
5033
5034
# File 'lib/syntax_tree.rb', line 5032

def comments
  @comments
end

#leftObject (readonly)

nil | untyped

the left side of the expression



5023
5024
5025
# File 'lib/syntax_tree.rb', line 5023

def left
  @left
end

#locationObject (readonly)

Location

the location of this node



5029
5030
5031
# File 'lib/syntax_tree.rb', line 5029

def location
  @location
end

#rightObject (readonly)

nil | untyped

the right side of the expression



5026
5027
5028
# File 'lib/syntax_tree.rb', line 5026

def right
  @right
end

Instance Method Details

#child_nodesObject



5041
5042
5043
# File 'lib/syntax_tree.rb', line 5041

def child_nodes
  [left, right]
end

#format(q) ⇒ Object



5045
5046
5047
# File 'lib/syntax_tree.rb', line 5045

def format(q)
  DotFormatter.new("...", self).format(q)
end

#pretty_print(q) ⇒ Object



5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
# File 'lib/syntax_tree.rb', line 5049

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("dot3")

    if left
      q.breakable
      q.pp(left)
    end

    if right
      q.breakable
      q.pp(right)
    end

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



5067
5068
5069
5070
5071
5072
5073
5074
5075
# File 'lib/syntax_tree.rb', line 5067

def to_json(*opts)
  {
    type: :dot3,
    left: left,
    right: right,
    loc: location,
    cmts: comments
  }.to_json(*opts)
end