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



4938
4939
4940
4941
4942
4943
4944
# File 'lib/syntax_tree/node.rb', line 4938

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

  @leading = false
  @trailing = false
end

Instance Attribute Details

#valueObject (readonly)

String

the contents of the comment



4936
4937
4938
# File 'lib/syntax_tree/node.rb', line 4936

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



5006
5007
5008
# File 'lib/syntax_tree/node.rb', line 5006

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

#accept(visitor) ⇒ Object



4974
4975
4976
# File 'lib/syntax_tree/node.rb', line 4974

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

#child_nodesObject Also known as: deconstruct



4978
4979
4980
# File 'lib/syntax_tree/node.rb', line 4978

def child_nodes
  []
end

#commentsObject



4970
4971
4972
# File 'lib/syntax_tree/node.rb', line 4970

def comments
  []
end

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



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

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

#deconstruct_keys(_keys) ⇒ Object



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

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

#format(q) ⇒ Object



4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
# File 'lib/syntax_tree/node.rb', line 4995

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



4966
4967
4968
# File 'lib/syntax_tree/node.rb', line 4966

def ignore?
  false
end

#inline?Boolean



4962
4963
4964
# File 'lib/syntax_tree/node.rb', line 4962

def inline?
  false
end

#leading!Object



4946
4947
4948
# File 'lib/syntax_tree/node.rb', line 4946

def leading!
  @leading = true
end

#leading?Boolean



4950
4951
4952
# File 'lib/syntax_tree/node.rb', line 4950

def leading?
  @leading
end

#trailing!Object



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

def trailing!
  @trailing = true
end

#trailing?Boolean



4958
4959
4960
# File 'lib/syntax_tree/node.rb', line 4958

def trailing?
  @trailing
end