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.



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

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.



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

def inline
  @inline
end

#valueObject (readonly)

String

the contents of the comment



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

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



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

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

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  []
end

#commentsObject



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

def comments
  []
end

#deconstruct_keys(keys) ⇒ Object



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

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

#format(q) ⇒ Object



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

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

#ignore?Boolean

Returns:

  • (Boolean)


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

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

#leading!Object



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

def leading!
  @leading = true
end

#leading?Boolean

Returns:

  • (Boolean)


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

def leading?
  @leading
end

#trailing!Object



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

def trailing!
  @trailing = true
end

#trailing?Boolean

Returns:

  • (Boolean)


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

def trailing?
  @trailing
end