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, #pretty_print, #to_json

Constructor Details

#initialize(value:, inline:, location:) ⇒ Comment

Returns a new instance of Comment.



3687
3688
3689
3690
3691
3692
3693
3694
# File 'lib/syntax_tree/node.rb', line 3687

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.



3684
3685
3686
# File 'lib/syntax_tree/node.rb', line 3684

def inline
  @inline
end

#valueObject (readonly)

String

the contents of the comment



3680
3681
3682
# File 'lib/syntax_tree/node.rb', line 3680

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



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

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

#accept(visitor) ⇒ Object



3720
3721
3722
# File 'lib/syntax_tree/node.rb', line 3720

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

#child_nodesObject Also known as: deconstruct



3724
3725
3726
# File 'lib/syntax_tree/node.rb', line 3724

def child_nodes
  []
end

#commentsObject



3716
3717
3718
# File 'lib/syntax_tree/node.rb', line 3716

def comments
  []
end

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



3728
3729
3730
3731
3732
3733
3734
# File 'lib/syntax_tree/node.rb', line 3728

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



3738
3739
3740
# File 'lib/syntax_tree/node.rb', line 3738

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

#format(q) ⇒ Object



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

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

#ignore?Boolean

Returns:

  • (Boolean)


3712
3713
3714
# File 'lib/syntax_tree/node.rb', line 3712

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

#leading!Object



3696
3697
3698
# File 'lib/syntax_tree/node.rb', line 3696

def leading!
  @leading = true
end

#leading?Boolean

Returns:

  • (Boolean)


3700
3701
3702
# File 'lib/syntax_tree/node.rb', line 3700

def leading?
  @leading
end

#trailing!Object



3704
3705
3706
# File 'lib/syntax_tree/node.rb', line 3704

def trailing!
  @trailing = true
end

#trailing?Boolean

Returns:

  • (Boolean)


3708
3709
3710
# File 'lib/syntax_tree/node.rb', line 3708

def trailing?
  @trailing
end