///|
/// `[ a, b ]` on one line, or one item per line with leading commas (the
/// elm-format form): `[ a\n, b\n]`. With no items: `[]`.
fn sequence(
open : String,
close : String,
items : Array[@pretty.Doc],
) -> @pretty.Doc {
guard !items.is_empty() else { return @pretty.text(open + close) }
let mut body = @pretty.text(open + " ") + @pretty.nest(2, items[0])
for i in 1.. @pretty.Doc {
let mut body = @pretty.text("| ") + @pretty.nest(2, fields[0])
for i in 1.. @pretty.Doc {
label +
@pretty.text(" " + separator) +
@pretty.group(@pretty.tab(4, @pretty.line() + value))
}
///|
/// `(d)`; when `d` breaks, the `)` goes on its own line in the column of
/// the `(`, and the lines of `d` are indented from the column after the `(`
/// (the elm-format form).
fn parens(d : @pretty.Doc) -> @pretty.Doc {
@pretty.group(
@pretty.align(
@pretty.text("(") +
@pretty.nest(1, d) +
@pretty.softline() +
@pretty.text(")"),
),
)
}
///|
/// `head a b` on one line, or each item on its own line at the next tab
/// stop (a multiple of 4), as elm-format indents.
fn spaced(head : @pretty.Doc, items : Array[@pretty.Doc]) -> @pretty.Doc {
let mut rest = @pretty.empty()
for x in items {
rest = rest + @pretty.line() + x
}
@pretty.group(head + @pretty.tab(4, rest))
}
///|
/// `[ a, b ]` always on one line: a pattern never breaks (elm-format keeps
/// patterns on one line, and a broken pattern in a case branch puts `,` in
/// the branch column). With no items: `[]`.
fn flat_sequence(
open : String,
close : String,
items : Array[@pretty.Doc],
) -> @pretty.Doc {
guard !items.is_empty() else { return @pretty.text(open + close) }
let mut body = @pretty.text(open + " ") + items[0]
for i in 1.. @pretty.Doc {
@pretty.text("(") + d + @pretty.text(")")
}