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.



5978
5979
5980
5981
5982
# File 'lib/syntax_tree.rb', line 5978

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



5976
5977
5978
# File 'lib/syntax_tree.rb', line 5976

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



5973
5974
5975
# File 'lib/syntax_tree.rb', line 5973

def location
  @location
end

#valueObject (readonly)

String

the value of the floating point number literal



5970
5971
5972
# File 'lib/syntax_tree.rb', line 5970

def value
  @value
end

Instance Method Details

#child_nodesObject



5984
5985
5986
# File 'lib/syntax_tree.rb', line 5984

def child_nodes
  []
end

#format(q) ⇒ Object



5988
5989
5990
# File 'lib/syntax_tree.rb', line 5988

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

#pretty_print(q) ⇒ Object



5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
# File 'lib/syntax_tree.rb', line 5992

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



6003
6004
6005
6006
6007
# File 'lib/syntax_tree.rb', line 6003

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