Skip to main content

Module format

Module format 

Source
Expand description

Opinionated CST-backed formatter entries.

Sole import path for the formatter surface - format_source, format_source_with_parsed, try_format_source, format_node, format_node_range, format_node_with_alignment, format_node_range_with_alignment, PostingAlignment, compute_alignment, canonicalize_directives, CanonicalizeError, lf_to_crlf_outside_strings, crlf_to_lf_outside_strings, cr_outside_strings_present. The flat crate-root re-exports were removed in round-5 and the duplicate crate::cst::format path was sealed in round-6 of the PR #1284 reviews, so a future deprecation can be done at exactly one site.

Structs§

PostingAlignment
Pre-computed alignment data for a whole source file.

Enums§

CanonicalizeError
Error returned by canonicalize_directives.

Functions§

canonicalize_directives
Render typed Beancount Directives in the canonical form emitted by format_source.
compute_alignment
Compute the file-wide alignment columns for a parsed SourceFile.
cr_outside_strings_present
true iff src contains at least one \r byte OUTSIDE a string literal — i.e. the byte sequence the canonical formatter would fold to \n via crlf_to_lf_outside_strings.
crlf_to_lf_outside_strings
Replace CRLF and bare-CR line terminators with LF, but ONLY outside string literals.
format_node
Format a SOURCE_FILE syntax node in opinionated canonical form.
format_node_range
Format the subset of node’s top-level children that intersect range, returning the snapped byte range and the canonical-form replacement text.
format_node_range_with_alignment
Like format_node_range but skips the per-call compute_alignment walk by accepting a precomputed PostingAlignment.
format_node_with_alignment
Like format_node but skips the per-call compute_alignment walk by accepting a precomputed PostingAlignment.
format_source
Format a Beancount source file in opinionated canonical form.
format_source_with_parsed
Like format_source but reuses the caller’s crate::ParseResult instead of re-parsing source.
lf_to_crlf_outside_strings
Convert every \n line terminator OUTSIDE string literals back to \r\n, leaving \n characters inside strings (and inside comments… see below) untouched.
try_format_source
Like format_source, but returns the parse errors instead of silently formatting around them.