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.



3734
3735
3736
3737
3738
3739
3740
3741
# File 'lib/syntax_tree/node.rb', line 3734

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.



3731
3732
3733
# File 'lib/syntax_tree/node.rb', line 3731

def inline
  @inline
end

#valueObject (readonly)

String

the contents of the comment



3727
3728
3729
# File 'lib/syntax_tree/node.rb', line 3727

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



3793
3794
3795
# File 'lib/syntax_tree/node.rb', line 3793

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

#accept(visitor) ⇒ Object



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

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

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  []
end

#commentsObject



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

def comments
  []
end

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



3775
3776
3777
3778
3779
3780
3781
# File 'lib/syntax_tree/node.rb', line 3775

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



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

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

#format(q) ⇒ Object



3789
3790
3791
# File 'lib/syntax_tree/node.rb', line 3789

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

#ignore?Boolean

Returns:

  • (Boolean)


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

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

#leading!Object



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

def leading!
  @leading = true
end

#leading?Boolean

Returns:

  • (Boolean)


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

def leading?
  @leading
end

#trailing!Object



3751
3752
3753
# File 'lib/syntax_tree/node.rb', line 3751

def trailing!
  @trailing = true
end

#trailing?Boolean

Returns:

  • (Boolean)


3755
3756
3757
# File 'lib/syntax_tree/node.rb', line 3755

def trailing?
  @trailing
end