Class: SyntaxTree::HeredocBeg

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

Overview

HeredocBeg represents the beginning declaration of a heredoc.

"contents\n"

In the example above the HeredocBeg node represents <<~DOC.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value:, location:, comments: []) ⇒ HeredocBeg

Returns a new instance of HeredocBeg.



6453
6454
6455
6456
6457
# File 'lib/syntax_tree.rb', line 6453

def initialize(value:, location:, comments: [])
  @value = value
  @location = location
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



6451
6452
6453
# File 'lib/syntax_tree.rb', line 6451

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



6448
6449
6450
# File 'lib/syntax_tree.rb', line 6448

def location
  @location
end

#valueObject (readonly)

String

the opening declaration of the heredoc



6445
6446
6447
# File 'lib/syntax_tree.rb', line 6445

def value
  @value
end

Instance Method Details

#child_nodesObject



6459
6460
6461
# File 'lib/syntax_tree.rb', line 6459

def child_nodes
  []
end

#format(q) ⇒ Object



6463
6464
6465
# File 'lib/syntax_tree.rb', line 6463

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

#pretty_print(q) ⇒ Object



6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
# File 'lib/syntax_tree.rb', line 6467

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

    q.breakable
    q.pp(value)

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



6478
6479
6480
6481
6482
6483
6484
6485
# File 'lib/syntax_tree.rb', line 6478

def to_json(*opts)
  {
    type: :heredoc_beg,
    value: value,
    loc: location,
    cmts: comments
  }.to_json(*opts)
end