Class: SyntaxTree::FloatLiteral

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

Overview

FloatLiteral represents a floating point number literal.

1.0

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid

Constructor Details

#initialize(value:, location:) ⇒ FloatLiteral

Returns a new instance of FloatLiteral.



5318
5319
5320
5321
5322
# File 'lib/syntax_tree/node.rb', line 5318

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



5316
5317
5318
# File 'lib/syntax_tree/node.rb', line 5316

def comments
  @comments
end

#valueObject (readonly)

String

the value of the floating point number literal



5313
5314
5315
# File 'lib/syntax_tree/node.rb', line 5313

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



5353
5354
5355
# File 'lib/syntax_tree/node.rb', line 5353

def ===(other)
  other.is_a?(FloatLiteral) && value === other.value
end

#accept(visitor) ⇒ Object



5324
5325
5326
# File 'lib/syntax_tree/node.rb', line 5324

def accept(visitor)
  visitor.visit_float(self)
end

#child_nodesObject Also known as: deconstruct



5328
5329
5330
# File 'lib/syntax_tree/node.rb', line 5328

def child_nodes
  []
end

#copy(value: nil, location: nil) ⇒ Object



5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
# File 'lib/syntax_tree/node.rb', line 5332

def copy(value: nil, location: nil)
  node =
    FloatLiteral.new(
      value: value || self.value,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end

#deconstruct_keys(_keys) ⇒ Object



5345
5346
5347
# File 'lib/syntax_tree/node.rb', line 5345

def deconstruct_keys(_keys)
  { value: value, location: location, comments: comments }
end

#format(q) ⇒ Object



5349
5350
5351
# File 'lib/syntax_tree/node.rb', line 5349

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