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.



3678
3679
3680
3681
3682
3683
3684
3685
# File 'lib/syntax_tree/node.rb', line 3678

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.



3675
3676
3677
# File 'lib/syntax_tree/node.rb', line 3675

def inline
  @inline
end

#valueObject (readonly)

String

the contents of the comment



3671
3672
3673
# File 'lib/syntax_tree/node.rb', line 3671

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



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

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

#accept(visitor) ⇒ Object



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

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

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  []
end

#commentsObject



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

def comments
  []
end

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



3719
3720
3721
3722
3723
3724
3725
# File 'lib/syntax_tree/node.rb', line 3719

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



3729
3730
3731
# File 'lib/syntax_tree/node.rb', line 3729

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

#format(q) ⇒ Object



3733
3734
3735
# File 'lib/syntax_tree/node.rb', line 3733

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

#ignore?Boolean

Returns:

  • (Boolean)


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

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

#leading!Object



3687
3688
3689
# File 'lib/syntax_tree/node.rb', line 3687

def leading!
  @leading = true
end

#leading?Boolean

Returns:

  • (Boolean)


3691
3692
3693
# File 'lib/syntax_tree/node.rb', line 3691

def leading?
  @leading
end

#trailing!Object



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

def trailing!
  @trailing = true
end

#trailing?Boolean

Returns:

  • (Boolean)


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

def trailing?
  @trailing
end