Class: SyntaxTree::Heredoc
Overview
Heredoc represents a heredoc string literal.
"contents\n"
Instance Attribute Summary collapse
-
#beginning ⇒ Object
readonly
- HeredocBeg
-
the opening of the heredoc.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#ending ⇒ Object
readonly
- String
-
the ending of the heredoc.
-
#parts ⇒ Object
readonly
- Array[ StringEmbExpr | StringDVar | TStringContent ]
-
the parts of the heredoc string literal.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(beginning:, ending: nil, parts: [], location:, comments: []) ⇒ Heredoc
constructor
A new instance of Heredoc.
Methods inherited from Node
Constructor Details
#initialize(beginning:, ending: nil, parts: [], location:, comments: []) ⇒ Heredoc
Returns a new instance of Heredoc.
4344 4345 4346 4347 4348 4349 4350 |
# File 'lib/syntax_tree/node.rb', line 4344 def initialize(beginning:, ending: nil, parts: [], location:, comments: []) @beginning = beginning @ending = ending @parts = parts @location = location @comments = comments end |
Instance Attribute Details
#beginning ⇒ Object (readonly)
- HeredocBeg
-
the opening of the heredoc
4332 4333 4334 |
# File 'lib/syntax_tree/node.rb', line 4332 def beginning @beginning end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
4342 4343 4344 |
# File 'lib/syntax_tree/node.rb', line 4342 def comments @comments end |
#ending ⇒ Object (readonly)
- String
-
the ending of the heredoc
4335 4336 4337 |
# File 'lib/syntax_tree/node.rb', line 4335 def ending @ending end |
#parts ⇒ Object (readonly)
- Array[ StringEmbExpr | StringDVar | TStringContent ]
-
the parts of the
heredoc string literal
4339 4340 4341 |
# File 'lib/syntax_tree/node.rb', line 4339 def parts @parts end |
Instance Method Details
#accept(visitor) ⇒ Object
4352 4353 4354 |
# File 'lib/syntax_tree/node.rb', line 4352 def accept(visitor) visitor.visit_heredoc(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
4356 4357 4358 |
# File 'lib/syntax_tree/node.rb', line 4356 def child_nodes [beginning, *parts] end |
#deconstruct_keys(keys) ⇒ Object
4362 4363 4364 4365 4366 4367 4368 4369 4370 |
# File 'lib/syntax_tree/node.rb', line 4362 def deconstruct_keys(keys) { beginning: beginning, location: location, ending: ending, parts: parts, comments: comments } end |
#format(q) ⇒ Object
4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 |
# File 'lib/syntax_tree/node.rb', line 4372 def format(q) # This is a very specific behavior that should probably be included in the # prettyprint module. It's when you want to force a newline, but don't # want to force the break parent. breakable = -> do q.target << PrettyPrint::Breakable.new(" ", 1, indent: false, force: true) end q.group do q.format(beginning) q.line_suffix(priority: Formatter::HEREDOC_PRIORITY) do q.group do breakable.call parts.each do |part| if part.is_a?(TStringContent) texts = part.value.split(/\r?\n/, -1) q.seplist(texts, breakable) { |text| q.text(text) } else q.format(part) end end q.text(ending) end end end end |