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.



3160
3161
3162
3163
3164
3165
3166
3167
# File 'lib/syntax_tree/node.rb', line 3160

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.



3157
3158
3159
# File 'lib/syntax_tree/node.rb', line 3157

def inline
  @inline
end

#valueObject (readonly)

String

the contents of the comment



3153
3154
3155
# File 'lib/syntax_tree/node.rb', line 3153

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



3193
3194
3195
# File 'lib/syntax_tree/node.rb', line 3193

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

#child_nodesObject Also known as: deconstruct



3197
3198
3199
# File 'lib/syntax_tree/node.rb', line 3197

def child_nodes
  []
end

#commentsObject



3189
3190
3191
# File 'lib/syntax_tree/node.rb', line 3189

def comments
  []
end

#deconstruct_keys(_keys) ⇒ Object



3203
3204
3205
# File 'lib/syntax_tree/node.rb', line 3203

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

#format(q) ⇒ Object



3207
3208
3209
# File 'lib/syntax_tree/node.rb', line 3207

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

#ignore?Boolean

Returns:

  • (Boolean)


3185
3186
3187
# File 'lib/syntax_tree/node.rb', line 3185

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

#leading!Object



3169
3170
3171
# File 'lib/syntax_tree/node.rb', line 3169

def leading!
  @leading = true
end

#leading?Boolean

Returns:

  • (Boolean)


3173
3174
3175
# File 'lib/syntax_tree/node.rb', line 3173

def leading?
  @leading
end

#trailing!Object



3177
3178
3179
# File 'lib/syntax_tree/node.rb', line 3177

def trailing!
  @trailing = true
end

#trailing?Boolean

Returns:

  • (Boolean)


3181
3182
3183
# File 'lib/syntax_tree/node.rb', line 3181

def trailing?
  @trailing
end