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

Returns a new instance of EmbDoc.



4974
4975
4976
4977
4978
4979
4980
# File 'lib/syntax_tree/node.rb', line 4974

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

  @leading = false
  @trailing = false
end

Instance Attribute Details

#valueObject (readonly)

String

the contents of the comment



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

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



5042
5043
5044
# File 'lib/syntax_tree/node.rb', line 5042

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

#accept(visitor) ⇒ Object



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

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

#child_nodesObject Also known as: deconstruct



5014
5015
5016
# File 'lib/syntax_tree/node.rb', line 5014

def child_nodes
  []
end

#commentsObject



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

def comments
  []
end

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



5018
5019
5020
5021
5022
5023
# File 'lib/syntax_tree/node.rb', line 5018

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

#deconstruct_keys(_keys) ⇒ Object



5027
5028
5029
# File 'lib/syntax_tree/node.rb', line 5027

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

#format(q) ⇒ Object



5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
# File 'lib/syntax_tree/node.rb', line 5031

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

Returns:

  • (Boolean)


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

def ignore?
  false
end

#inline?Boolean

Returns:

  • (Boolean)


4998
4999
5000
# File 'lib/syntax_tree/node.rb', line 4998

def inline?
  false
end

#leading!Object



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

def leading!
  @leading = true
end

#leading?Boolean

Returns:

  • (Boolean)


4986
4987
4988
# File 'lib/syntax_tree/node.rb', line 4986

def leading?
  @leading
end

#trailing!Object



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

def trailing!
  @trailing = true
end

#trailing?Boolean

Returns:

  • (Boolean)


4994
4995
4996
# File 'lib/syntax_tree/node.rb', line 4994

def trailing?
  @trailing
end