Class: SyntaxTree::Comment

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

Overview

Comment represents a comment in the source.

# comment

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:, inline:, location:) ⇒ Comment

Returns a new instance of Comment.



3749
3750
3751
3752
3753
3754
3755
3756
# File 'lib/syntax_tree/node.rb', line 3749

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

  @leading = false
  @trailing = false
end

Instance Attribute Details

#inlineObject (readonly) Also known as: inline?

boolean

whether or not there is code on the same line as this comment.

If there is, then inline will be true.



3746
3747
3748
# File 'lib/syntax_tree/node.rb', line 3746

def inline
  @inline
end

#valueObject (readonly)

String

the contents of the comment



3742
3743
3744
# File 'lib/syntax_tree/node.rb', line 3742

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



3808
3809
3810
# File 'lib/syntax_tree/node.rb', line 3808

def ===(other)
  other.is_a?(Comment) && value === other.value && inline === other.inline
end

#accept(visitor) ⇒ Object



3782
3783
3784
# File 'lib/syntax_tree/node.rb', line 3782

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

#child_nodesObject Also known as: deconstruct



3786
3787
3788
# File 'lib/syntax_tree/node.rb', line 3786

def child_nodes
  []
end

#commentsObject



3778
3779
3780
# File 'lib/syntax_tree/node.rb', line 3778

def comments
  []
end

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



3790
3791
3792
3793
3794
3795
3796
# File 'lib/syntax_tree/node.rb', line 3790

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

#deconstruct_keys(_keys) ⇒ Object



3800
3801
3802
# File 'lib/syntax_tree/node.rb', line 3800

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

#format(q) ⇒ Object



3804
3805
3806
# File 'lib/syntax_tree/node.rb', line 3804

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

#ignore?Boolean

Returns:

  • (Boolean)


3774
3775
3776
# File 'lib/syntax_tree/node.rb', line 3774

def ignore?
  value.match?(/\A#\s*stree-ignore\s*\z/)
end

#leading!Object



3758
3759
3760
# File 'lib/syntax_tree/node.rb', line 3758

def leading!
  @leading = true
end

#leading?Boolean

Returns:

  • (Boolean)


3762
3763
3764
# File 'lib/syntax_tree/node.rb', line 3762

def leading?
  @leading
end

#trailing!Object



3766
3767
3768
# File 'lib/syntax_tree/node.rb', line 3766

def trailing!
  @trailing = true
end

#trailing?Boolean

Returns:

  • (Boolean)


3770
3771
3772
# File 'lib/syntax_tree/node.rb', line 3770

def trailing?
  @trailing
end