Class: PrettyPrint::IfBreak

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

Overview

A node in the print tree that represents printing one thing if the surrounding group node is broken and another thing if the surrounding group node is flat.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(break_contents: [], flat_contents: []) ⇒ IfBreak

Returns a new instance of IfBreak.



176
177
178
179
# File 'lib/syntax_tree/prettyprint.rb', line 176

def initialize(break_contents: [], flat_contents: [])
  @break_contents = break_contents
  @flat_contents = flat_contents
end

Instance Attribute Details

#break_contentsObject (readonly)

Returns the value of attribute break_contents.



174
175
176
# File 'lib/syntax_tree/prettyprint.rb', line 174

def break_contents
  @break_contents
end

#flat_contentsObject (readonly)

Returns the value of attribute flat_contents.



174
175
176
# File 'lib/syntax_tree/prettyprint.rb', line 174

def flat_contents
  @flat_contents
end

Instance Method Details

#pretty_print(q) ⇒ Object



181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/syntax_tree/prettyprint.rb', line 181

def pretty_print(q)
  q.group(2, "if-break(", ")") do
    q.breakable("")
    q.group(2, "[", "],") do
      q.seplist(break_contents) { |content| q.pp(content) }
    end
    q.breakable
    q.group(2, "[", "]") do
      q.seplist(flat_contents) { |content| q.pp(content) }
    end
  end
end