Class: SyntaxTree::EmbDoc

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

Overview

EmbDoc represents a multi-line comment.

=begin
first line
second line
=end

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:) ⇒ EmbDoc



4956
4957
4958
4959
4960
4961
4962
# File 'lib/syntax_tree/node.rb', line 4956

def initialize(value:, location:)
  @value = value
  @location = location

  @leading = false
  @trailing = false
end

Instance Attribute Details

#valueObject (readonly)

String

the contents of the comment



4954
4955
4956
# File 'lib/syntax_tree/node.rb', line 4954

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



5024
5025
5026
# File 'lib/syntax_tree/node.rb', line 5024

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

#accept(visitor) ⇒ Object



4992
4993
4994
# File 'lib/syntax_tree/node.rb', line 4992

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

#child_nodesObject Also known as: deconstruct



4996
4997
4998
# File 'lib/syntax_tree/node.rb', line 4996

def child_nodes
  []
end

#commentsObject



4988
4989
4990
# File 'lib/syntax_tree/node.rb', line 4988

def comments
  []
end

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



5000
5001
5002
5003
5004
5005
# File 'lib/syntax_tree/node.rb', line 5000

def copy(value: nil, location: nil)
  EmbDoc.new(
    value: value || self.value,
    location: location || self.location
  )
end

#deconstruct_keys(_keys) ⇒ Object



5009
5010
5011
# File 'lib/syntax_tree/node.rb', line 5009

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

#format(q) ⇒ Object



5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
# File 'lib/syntax_tree/node.rb', line 5013

def format(q)
  if (q.parent.is_a?(DefNode) && q.parent.endless?) ||
       q.parent.is_a?(Statements)
    q.trim
  else
    q.breakable_return
  end

  q.text(value)
end

#ignore?Boolean



4984
4985
4986
# File 'lib/syntax_tree/node.rb', line 4984

def ignore?
  false
end

#inline?Boolean



4980
4981
4982
# File 'lib/syntax_tree/node.rb', line 4980

def inline?
  false
end

#leading!Object



4964
4965
4966
# File 'lib/syntax_tree/node.rb', line 4964

def leading!
  @leading = true
end

#leading?Boolean



4968
4969
4970
# File 'lib/syntax_tree/node.rb', line 4968

def leading?
  @leading
end

#trailing!Object



4972
4973
4974
# File 'lib/syntax_tree/node.rb', line 4972

def trailing!
  @trailing = true
end

#trailing?Boolean



4976
4977
4978
# File 'lib/syntax_tree/node.rb', line 4976

def trailing?
  @trailing
end