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.



3055
3056
3057
3058
3059
3060
3061
3062
# File 'lib/syntax_tree/node.rb', line 3055

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.



3052
3053
3054
# File 'lib/syntax_tree/node.rb', line 3052

def inline
  @inline
end

#valueObject (readonly)

String

the contents of the comment



3048
3049
3050
# File 'lib/syntax_tree/node.rb', line 3048

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



3088
3089
3090
# File 'lib/syntax_tree/node.rb', line 3088

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

#child_nodesObject Also known as: deconstruct



3092
3093
3094
# File 'lib/syntax_tree/node.rb', line 3092

def child_nodes
  []
end

#commentsObject



3084
3085
3086
# File 'lib/syntax_tree/node.rb', line 3084

def comments
  []
end

#deconstruct_keys(keys) ⇒ Object



3098
3099
3100
# File 'lib/syntax_tree/node.rb', line 3098

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

#format(q) ⇒ Object



3102
3103
3104
# File 'lib/syntax_tree/node.rb', line 3102

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

#ignore?Boolean

Returns:

  • (Boolean)


3080
3081
3082
# File 'lib/syntax_tree/node.rb', line 3080

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

#leading!Object



3064
3065
3066
# File 'lib/syntax_tree/node.rb', line 3064

def leading!
  @leading = true
end

#leading?Boolean

Returns:

  • (Boolean)


3068
3069
3070
# File 'lib/syntax_tree/node.rb', line 3068

def leading?
  @leading
end

#trailing!Object



3072
3073
3074
# File 'lib/syntax_tree/node.rb', line 3072

def trailing!
  @trailing = true
end

#trailing?Boolean

Returns:

  • (Boolean)


3076
3077
3078
# File 'lib/syntax_tree/node.rb', line 3076

def trailing?
  @trailing
end