class PrettyPrint
inherits Reference
¶
This class implements a pretty printing algorithm. It finds line breaks and nice indentations for grouped structure.
References¶
- Ruby's prettyprint.rb
- Christian Lindig, Strictly Pretty, March 2000
- Philip Wadler, A prettier printer, March 1998
Class methods¶
.format(obj, io : IO, width : Int32, newline = "\n", indent = 0)
¶
(obj, io : IO, width : Int32, newline = "\n", indent = 0)
Pretty prints obj into io with the given width as a limit and starting with the given indentation.
.format(io : IO, width : Int32, newline = "\n", indent = 0
¶
(io : IO, width : Int32, newline = "\n", indent = 0
Creates a pretty printer and yields it to the block, appending any output to the given io.
.new(output : IO, maxwidth = 79, newline = "\n", indent = 0)
¶
(output : IO, maxwidth = 79, newline = "\n", indent = 0)
Creates a new pretty printer that will write to the given output and be capped at maxwidth.
Methods¶
#fill_breakable(sep = " ")
¶
(sep = " ")
Similar to #breakable
except
the decision to break or not is determined individually.
#group(indent = 0, open_obj = "", close_obj = ""
¶
(indent = 0, open_obj = "", close_obj = ""
Creates a group of objects. Inside a group all breakable objects are either turned into newlines or are output as is, depending on the available width.
#list(left, elements, right, &) : Nil
¶
(left, elements, right, &) : Nil
Appends a list of elements surrounded by left and right and separated by commas, yielding each element to the given block.
#list(left, elements, right) : Nil
¶
(left, elements, right) : Nil
Appends a list of elements surrounded by left and right and separated by commas.
#surround(left, right, left_break = "", right_break = "", &) : Nil
¶
(left, right, left_break = "", right_break = "", &) : Nil
Appends a group that is surrounded by the given left and right objects, and optionally is surrounded by the given breakable objects.