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

#pretty_print, #to_json

Constructor Details

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

Returns a new instance of Comment.



2707
2708
2709
2710
2711
2712
2713
2714
# File 'lib/syntax_tree/node.rb', line 2707

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.



2704
2705
2706
# File 'lib/syntax_tree/node.rb', line 2704

def inline
  @inline
end

#valueObject (readonly)

String

the contents of the comment



2700
2701
2702
# File 'lib/syntax_tree/node.rb', line 2700

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



2740
2741
2742
# File 'lib/syntax_tree/node.rb', line 2740

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

#child_nodesObject Also known as: deconstruct



2744
2745
2746
# File 'lib/syntax_tree/node.rb', line 2744

def child_nodes
  []
end

#commentsObject



2736
2737
2738
# File 'lib/syntax_tree/node.rb', line 2736

def comments
  []
end

#deconstruct_keys(keys) ⇒ Object



2750
2751
2752
# File 'lib/syntax_tree/node.rb', line 2750

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

#format(q) ⇒ Object



2754
2755
2756
# File 'lib/syntax_tree/node.rb', line 2754

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

#ignore?Boolean

Returns:

  • (Boolean)


2732
2733
2734
# File 'lib/syntax_tree/node.rb', line 2732

def ignore?
  value[1..-1].strip == "stree-ignore"
end

#leading!Object



2716
2717
2718
# File 'lib/syntax_tree/node.rb', line 2716

def leading!
  @leading = true
end

#leading?Boolean

Returns:

  • (Boolean)


2720
2721
2722
# File 'lib/syntax_tree/node.rb', line 2720

def leading?
  @leading
end

#trailing!Object



2724
2725
2726
# File 'lib/syntax_tree/node.rb', line 2724

def trailing!
  @trailing = true
end

#trailing?Boolean

Returns:

  • (Boolean)


2728
2729
2730
# File 'lib/syntax_tree/node.rb', line 2728

def trailing?
  @trailing
end