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.



5371
5372
5373
5374
5375
# File 'lib/syntax_tree/node.rb', line 5371

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



5369
5370
5371
# File 'lib/syntax_tree/node.rb', line 5369

def comments
  @comments
end

#valueObject (readonly)

String

the value of the floating point number literal



5366
5367
5368
# File 'lib/syntax_tree/node.rb', line 5366

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



5406
5407
5408
# File 'lib/syntax_tree/node.rb', line 5406

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

#accept(visitor) ⇒ Object



5377
5378
5379
# File 'lib/syntax_tree/node.rb', line 5377

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

#child_nodesObject Also known as: deconstruct



5381
5382
5383
# File 'lib/syntax_tree/node.rb', line 5381

def child_nodes
  []
end

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



5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
# File 'lib/syntax_tree/node.rb', line 5385

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



5398
5399
5400
# File 'lib/syntax_tree/node.rb', line 5398

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

#format(q) ⇒ Object



5402
5403
5404
# File 'lib/syntax_tree/node.rb', line 5402

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