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.



3121
3122
3123
3124
3125
3126
3127
3128
# File 'lib/syntax_tree/node.rb', line 3121

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.



3118
3119
3120
# File 'lib/syntax_tree/node.rb', line 3118

def inline
  @inline
end

#valueObject (readonly)

String

the contents of the comment



3114
3115
3116
# File 'lib/syntax_tree/node.rb', line 3114

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



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

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

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  []
end

#commentsObject



3150
3151
3152
# File 'lib/syntax_tree/node.rb', line 3150

def comments
  []
end

#deconstruct_keys(_keys) ⇒ Object



3164
3165
3166
# File 'lib/syntax_tree/node.rb', line 3164

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

#format(q) ⇒ Object



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

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

#ignore?Boolean

Returns:

  • (Boolean)


3146
3147
3148
# File 'lib/syntax_tree/node.rb', line 3146

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

#leading!Object



3130
3131
3132
# File 'lib/syntax_tree/node.rb', line 3130

def leading!
  @leading = true
end

#leading?Boolean

Returns:

  • (Boolean)


3134
3135
3136
# File 'lib/syntax_tree/node.rb', line 3134

def leading?
  @leading
end

#trailing!Object



3138
3139
3140
# File 'lib/syntax_tree/node.rb', line 3138

def trailing!
  @trailing = true
end

#trailing?Boolean

Returns:

  • (Boolean)


3142
3143
3144
# File 'lib/syntax_tree/node.rb', line 3142

def trailing?
  @trailing
end