Class: SyntaxTree::Comment

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Overview

Comment represents a comment in the source.

# comment

Defined Under Namespace

Classes: List

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Comment.



3327
3328
3329
3330
3331
3332
3333
3334
# File 'lib/syntax_tree/node.rb', line 3327

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.



3324
3325
3326
# File 'lib/syntax_tree/node.rb', line 3324

def inline
  @inline
end

#valueObject (readonly)

String

the contents of the comment



3320
3321
3322
# File 'lib/syntax_tree/node.rb', line 3320

def value
  @value
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



3360
3361
3362
# File 'lib/syntax_tree/node.rb', line 3360

def child_nodes
  []
end

#commentsObject



3356
3357
3358
# File 'lib/syntax_tree/node.rb', line 3356

def comments
  []
end

#deconstruct_keys(keys) ⇒ Object



3366
3367
3368
# File 'lib/syntax_tree/node.rb', line 3366

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

#format(q) ⇒ Object



3370
3371
3372
# File 'lib/syntax_tree/node.rb', line 3370

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

#ignore?Boolean

Returns:

  • (Boolean)


3352
3353
3354
# File 'lib/syntax_tree/node.rb', line 3352

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

#leading!Object



3336
3337
3338
# File 'lib/syntax_tree/node.rb', line 3336

def leading!
  @leading = true
end

#leading?Boolean

Returns:

  • (Boolean)


3340
3341
3342
# File 'lib/syntax_tree/node.rb', line 3340

def leading?
  @leading
end

#pretty_print(q) ⇒ Object



3374
3375
3376
3377
3378
3379
3380
3381
# File 'lib/syntax_tree/node.rb', line 3374

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("comment")

    q.breakable
    q.pp(value)
  end
end

#to_json(*opts) ⇒ Object



3383
3384
3385
3386
3387
3388
3389
3390
# File 'lib/syntax_tree/node.rb', line 3383

def to_json(*opts)
  {
    type: :comment,
    value: value.force_encoding("UTF-8"),
    inline: inline,
    loc: location
  }.to_json(*opts)
end

#trailing!Object



3344
3345
3346
# File 'lib/syntax_tree/node.rb', line 3344

def trailing!
  @trailing = true
end

#trailing?Boolean

Returns:

  • (Boolean)


3348
3349
3350
# File 'lib/syntax_tree/node.rb', line 3348

def trailing?
  @trailing
end