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.



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

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.



172
173
174
# File 'lib/syntax_tree/prettyprint.rb', line 172

def break_contents
  @break_contents
end

#flat_contentsObject (readonly)

Returns the value of attribute flat_contents.



172
173
174
# File 'lib/syntax_tree/prettyprint.rb', line 172

def flat_contents
  @flat_contents
end

Instance Method Details

#pretty_print(q) ⇒ Object



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

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