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.



5941
5942
5943
5944
5945
# File 'lib/syntax_tree.rb', line 5941

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



5939
5940
5941
# File 'lib/syntax_tree.rb', line 5939

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



5936
5937
5938
# File 'lib/syntax_tree.rb', line 5936

def location
  @location
end

#valueObject (readonly)

String

the value of the floating point number literal



5933
5934
5935
# File 'lib/syntax_tree.rb', line 5933

def value
  @value
end

Instance Method Details

#child_nodesObject



5947
5948
5949
# File 'lib/syntax_tree.rb', line 5947

def child_nodes
  []
end

#format(q) ⇒ Object



5951
5952
5953
# File 'lib/syntax_tree.rb', line 5951

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

#pretty_print(q) ⇒ Object



5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
# File 'lib/syntax_tree.rb', line 5955

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



5966
5967
5968
5969
5970
# File 'lib/syntax_tree.rb', line 5966

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