Skip to content

Standard library and data formats

Arbor includes standard facilities for everyday programs and its own toolchain. This chapter describes their intended scope rather than a finalized module API.

Design documentation

This chapter describes the language design. Examples are illustrative; implementation availability and unresolved rules are explained in Design status.

Batteries are included: collections, numbers, modular arithmetic, Unicode strings, time, concurrency, logging, configuration, and testing all have standard support. Precise module names and the full v0.1 inventory remain to be planned.

JSON, TOML, and YAML are supported data formats. Full YAML is not required in v0.1, but manifest.yaml must work through a documented supported subset. Unsupported YAML constructs are rejected explicitly. The exact subset and round-trip/serialization rules remain open.

The formatter, linter, documentation generator, and LSP are official tools, with machine-readable diagnostics and API information as a design goal. Formatting must not change string contents or program semantics.

Output and diagnostics: write and log

The standard output API is named write, replacing the earlier print spelling. write("foo") writes to stdout by default. It also supports explicit stderr and file destinations. Diagnostic output uses log, which is available without requiring users to create or configure a logger first. Both APIs should be readily available through the normal standard environment.

Illustrative API spellings:

write("foo");
write("Something went wrong", to=stderr);

with open("report.txt", mode="write") as report {
    write("Report contents", to=report);
}

log("Reached this point");
log.debug("Parsed statement", statement_id=statement.id);
log.error("Could not connect");

log also accepts typed diagnostic instances, using their message, structured fields, and default severity. The warn keyword is the language operation for emitting a warning instance.

Destination keyword spelling, writer protocols, newline behavior, encoding, buffering, and return conventions are still to be specified. Explicit file handles make file-opening and ownership separate from writing. Writes have ordinary I/O effects and declared operational failures; they are not exempt from purity.

Logging configuration lives in manifest.yaml and is optional because defaults are provided. Proposed defaults are stderr output, an info threshold, readable text formatting, and log(message) as shorthand for an info-level event. These defaults make the simplest diagnostic call visible without contaminating a program's stdout. Exact levels, shorthand, formatting, and schema remain provisional. An illustrative configuration is:

logging:
    level: info
    destination: stderr
    format: text

The application controls logging configuration; dependencies use the provided logging system without replacing the application's configuration on import. Standard-library logging keeps the Secret redaction guarantee and the previously defined pure-function diagnostic exemption. Renaming output to write does not extend that logging guarantee to arbitrary output APIs. write, log, and sleep remain automatically exempt from standalone-call linting.

Terminal styled text

The selected syntax is a term'...' typed literal containing named dollar controls. This supersedes the earlier {styles:content} annotations and their brace-escaping proposal:

write(term'this is an unrecoverable $bold${red}error$reset, do something');

The literal describes styled text. ANSI escapes are generated by the terminal renderer rather than becoming the authored representation. The exact value type name and programmatic style-construction API remain provisional.

Named controls and boundaries

Control Meaning
$bold Enable bold in the current style
$blue, $red Change the current foreground color
$reset Restore the base style for the rendered value
$push Save the complete current style on a local stack
$pop Restore and remove the most recently saved style
$company_error Apply a declared custom style preset

$reset is the canonical reset spelling; the earlier $esc spelling is not an additional alias. Attribute changes preserve other current attributes: changing foreground does not clear bold, for example. Reset changes the current attributes but does not discard the saved-style stack.

An unbraced control consumes a complete identifier. $blueword names one control; it is never guessed to mean $blue followed by word. A braced spelling explicitly ends the name and works for both built-ins and custom presets:

term'${blue}word';
term'An unrecoverable ${company_error}error$reset occurred.';

Braces outside a ${name} control are ordinary text. Whitespace outside controls is preserved exactly; spaces used around controls are not silently removed. A malformed control, dangling unescaped dollar, or unknown name is a compilation error. ${name} denotes a style control, not variable interpolation.

Dollar escaping

A maximal consecutive run of N dollar signs, where N is at least two, emits N-1 literal dollar signs and performs no control expansion for that run. Emitted characters are not reparsed. This is a run rule, not repeated pairwise escaping:

Source text inside a term literal Literal output
$$ $
$$company_error $company_error
$$$company_error $$company_error
$$${blue} $${blue}

A later independently occurring single dollar can still introduce a control.

Style scopes and custom presets

Nested formatting uses explicit push/pop scopes:

term'$bold Heading: $push${company_error}failure$pop continues in bold.$reset';

If company_error applies bold red, failure is bold red. The following text returns to the saved bold style and foreground. Push/pop may nest. The compiler checks for stack underflow and unmatched pushes within each literal; scopes do not cross literal boundaries.

Custom names resolve to declared formatting presets, such as bold plus red for company_error. Presets apply their specified attributes and retain other current attributes. They cannot replace built-in control definitions or inject arbitrary source/control text. Unknown presets are compilation errors. The declaration or configuration API and the full attribute vocabulary remain to be specified.

At the end of rendering the whole value, the renderer restores its incoming style so formatting does not leak into subsequent output. This restoration is separate from compile-time validation of explicit push/pop balance.

Rendering uses terminal capabilities, supports auto/always/never styling, and respects NO_COLOR in automatic mode. Redirected output and ordinary file output default to plain text. Plain-text rendering omits controls while preserving content and applying the same dollar-unescaping rule. Tests can inspect content and styles without comparing raw ANSI sequences. Exact renderer option APIs remain open.

Future value interpolation must keep inserted ordinary text separate from authored controls; inserted strings are not reparsed as styling. Value interpolation and multiline syntax, disabling individual inherited attributes, additional color formats, and the programmatic construction API remain open. Styling does not broaden the standard-library logging guarantee for Secret values.

See Settings for manifest initialization and the proposed development-only logging overrides.