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.



6121
6122
6123
6124
6125
# File 'lib/syntax_tree.rb', line 6121

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



6119
6120
6121
# File 'lib/syntax_tree.rb', line 6119

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



6116
6117
6118
# File 'lib/syntax_tree.rb', line 6116

def location
  @location
end

#valueObject (readonly)

String

the opening declaration of the heredoc



6113
6114
6115
# File 'lib/syntax_tree.rb', line 6113

def value
  @value
end

Instance Method Details

#child_nodesObject



6127
6128
6129
# File 'lib/syntax_tree.rb', line 6127

def child_nodes
  []
end

#format(q) ⇒ Object



6131
6132
6133
# File 'lib/syntax_tree.rb', line 6131

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

#pretty_print(q) ⇒ Object



6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
# File 'lib/syntax_tree.rb', line 6135

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



6146
6147
6148
6149
6150
6151
6152
6153
# File 'lib/syntax_tree.rb', line 6146

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