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.



4997
4998
4999
5000
5001
5002
# File 'lib/syntax_tree.rb', line 4997

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



4995
4996
4997
# File 'lib/syntax_tree.rb', line 4995

def comments
  @comments
end

#leftObject (readonly)

nil | untyped

the left side of the expression



4986
4987
4988
# File 'lib/syntax_tree.rb', line 4986

def left
  @left
end

#locationObject (readonly)

Location

the location of this node



4992
4993
4994
# File 'lib/syntax_tree.rb', line 4992

def location
  @location
end

#rightObject (readonly)

nil | untyped

the right side of the expression



4989
4990
4991
# File 'lib/syntax_tree.rb', line 4989

def right
  @right
end

Instance Method Details

#child_nodesObject



5004
5005
5006
# File 'lib/syntax_tree.rb', line 5004

def child_nodes
  [left, right]
end

#format(q) ⇒ Object



5008
5009
5010
# File 'lib/syntax_tree.rb', line 5008

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

#pretty_print(q) ⇒ Object



5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
# File 'lib/syntax_tree.rb', line 5012

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



5030
5031
5032
5033
5034
5035
5036
5037
5038
# File 'lib/syntax_tree.rb', line 5030

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