Dextrin.Text.Printer (Dextrin v0.1.0)

Copy Markdown View Source

.dxn printer — the reverse of Dextrin.Text.Actions. Single-line, minimal-whitespace output: a printer, not a formatter (no line-wrapping or indentation policy is specified anywhere in DXN.md) — Dextrin.Text.Formatter.pretty/2 owns multi-line, human-readable rendering, built on top of this module.

Returns {:ok, _} | {:error, _} rather than raising, matching Dextrin.Binary.Encoder's equivalent path — the only way this can fail is a struct with no tag_encoder registered (or one that itself returns {:error, _}), never any of the built-in DXN value types.

Summary

Functions

Whether name is a valid bare identifier (DXN.md §1.1) on its own — the one thing that decides whether a Dextrin.Keyword can use map_entry's colon-shorthand (identifier ":" value) at all, or must fall back to the arrow form instead. Public so Dextrin.Text.Formatter can apply the same rule rather than duplicating this check (or, worse, not checking at all — the bug this once was: an empty or space-containing keyword name printed as "": 0 / a bare : 0, neither of which parses back).

Functions

bare_identifier?(name)

@spec bare_identifier?(String.t()) :: boolean()

Whether name is a valid bare identifier (DXN.md §1.1) on its own — the one thing that decides whether a Dextrin.Keyword can use map_entry's colon-shorthand (identifier ":" value) at all, or must fall back to the arrow form instead. Public so Dextrin.Text.Formatter can apply the same rule rather than duplicating this check (or, worse, not checking at all — the bug this once was: an empty or space-containing keyword name printed as "": 0 / a bare : 0, neither of which parses back).

print(value, opts \\ [])

@spec print(
  term(),
  keyword()
) :: {:ok, String.t()} | {:error, Dextrin.Error.t()}