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



4701
4702
4703
4704
4705
4706
# File 'lib/syntax_tree.rb', line 4701

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



4699
4700
4701
# File 'lib/syntax_tree.rb', line 4699

def comments
  @comments
end

#leftObject (readonly)

nil | untyped

the left side of the expression



4690
4691
4692
# File 'lib/syntax_tree.rb', line 4690

def left
  @left
end

#locationObject (readonly)

Location

the location of this node



4696
4697
4698
# File 'lib/syntax_tree.rb', line 4696

def location
  @location
end

#rightObject (readonly)

nil | untyped

the right side of the expression



4693
4694
4695
# File 'lib/syntax_tree.rb', line 4693

def right
  @right
end

Instance Method Details

#child_nodesObject



4708
4709
4710
# File 'lib/syntax_tree.rb', line 4708

def child_nodes
  [left, right]
end

#format(q) ⇒ Object



4712
4713
4714
# File 'lib/syntax_tree.rb', line 4712

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

#pretty_print(q) ⇒ Object



4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
# File 'lib/syntax_tree.rb', line 4716

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



4734
4735
4736
4737
4738
4739
4740
4741
4742
# File 'lib/syntax_tree.rb', line 4734

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