Class: SyntaxTree::FloatLiteral

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

Overview

FloatLiteral represents a floating point number literal.

1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value:, location:, comments: []) ⇒ FloatLiteral

Returns a new instance of FloatLiteral.



5626
5627
5628
5629
5630
# File 'lib/syntax_tree.rb', line 5626

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



5624
5625
5626
# File 'lib/syntax_tree.rb', line 5624

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



5621
5622
5623
# File 'lib/syntax_tree.rb', line 5621

def location
  @location
end

#valueObject (readonly)

String

the value of the floating point number literal



5618
5619
5620
# File 'lib/syntax_tree.rb', line 5618

def value
  @value
end

Instance Method Details

#child_nodesObject



5632
5633
5634
# File 'lib/syntax_tree.rb', line 5632

def child_nodes
  []
end

#format(q) ⇒ Object



5636
5637
5638
# File 'lib/syntax_tree.rb', line 5636

def format(q)
  q.text(value)
end

#pretty_print(q) ⇒ Object



5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
# File 'lib/syntax_tree.rb', line 5640

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

    q.breakable
    q.pp(value)

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

#to_json(*opts) ⇒ Object



5651
5652
5653
5654
5655
# File 'lib/syntax_tree.rb', line 5651

def to_json(*opts)
  { type: :float, value: value, loc: location, cmts: comments }.to_json(
    *opts
  )
end