Skip to documentation
SLOP

tiny.preserves.text

Reference tiny.preserves text

Defined in tiny.preserves.

A text syntax for values, with two readers and two writers.

API (11)

Actions

Public operations.

Types and contracts

Public types and contracts.

Namespaces

Public namespaces.

Values and defaults

Public values and defaults.

No direct callersNo direct callstiny.preservestext
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Source: lib/preserves/src/text/nesting.zig:15

zig
/// The error both text readers return when input nests past `maximum`. Code calling either text/// reader matches on it, so input nested too deeply stands apart from other bad input. The error/// set holds one tag, `NestingLimitExceeded`, which also belongs to `ParseError` and to the text/// reader's `DecodeError`.pub const Error = error{NestingLimitExceeded};

Source: lib/preserves/src/text/nesting.zig:9

zig
/// The deepest nesting the text readers accept: 256 levels. Tests and callers that build deep input/// read it for that bound. The top value sits at level 0, and each record, sequence, set,/// dictionary, annotation and `#:` embedded value adds a level. Opening a level at 256 fails, so/// 256 nested levels read and 257 fail. `parse` and `decode` stop at the same depth for the same/// text.pub const maximum: Level = 256;

Source: lib/preserves/src/root.zig:119

zig
pub const text = @import("text/root.zig");

Source: lib/preserves/src/text/root.zig

zig
//! A text syntax for values, with two readers and two writers. People write and read this form by//! hand, so a reader meets text that a person typed. A caller needs to know which text each reader//! accepts, what the decoded value owns, and what stops deeply nested input. Each level of nesting//! costs the readers a level of recursion, and text can nest as deep as its length allows.//! Hand-written text lists set elements and dictionary entries in any order, and can repeat them.//! The syntax is the text syntax of the [Preserves](https://preserves.dev/) data language, which//! the package keeps.//!//! Both readers stop at 256 levels of nesting (`max_nesting_depth`), and each record, sequence,//! set, dictionary, annotation and `#:` embedded value adds a level. Depth is the one bound://! neither reader limits input size, item count or memory. Both readers reject a repeated set//! element or dictionary key. The reader `parse` then sorts sets and dictionaries, and the reader//! `decode` keeps the written order. The two writers are `encode`, which refuses discards,//! captures, binds and rest patterns, and `toText`, which writes them. Both readers copy every//! string they keep, so the decoded value owns all its memory and borrows nothing from the text.//!//! `parse` reads `# ` comments, and reads `#:` embedded values into `AnyEmbedded` values. `decode`//! rejects `# ` comments, and rejects `#:` embedded values whose type is `NoEmbedded` or//! `AnyEmbedded`. Both readers read a bare token with underscores between digits, such as `1_000`,//! as a symbol. `encode` writes the symbol `1_000` bare, so `parse` reads it back as a symbol.//! `encode` writes a `'` inside a quoted symbol as `\'`, `parse` accepts `\'` and `\"` in strings//! and quoted symbols, and `decode` accepts `\'` in quoted symbols and `\"` in strings, and rejects//! `\'` in strings and `\"` in quoted symbols with `BadEscape`. `decode` checks strings and symbols//! as UTF-8, and `parse` returns `InvalidUtf8` for invalid UTF-8 in strings and symbols.const preserves = @import("../root.zig");const format = @import("format.zig");const parser = @import("parser.zig");const nesting = @import("nesting.zig");pub const reader = @import("reader.zig");pub const writer = @import("writer.zig");const value_mod = preserves.value;const embedded_mod = preserves.embedded_mod;const parse_error_mod = preserves.parse_error;const integer_mod = preserves.integer_mod;/// An embedded value that points to a payload of the host program, with optional functions to/// compare, hash, free and copy it. Code that builds embedded values for `parse`, `toText` or/// `Value` names it. It is the type of the embedded values in the text namespace's values. `parse`/// makes each `#:` embedded value one of these, owning the value it read.pub const AnyEmbedded = embedded_mod.AnyEmbedded;/// The value type `parse` returns and `toText` writes: `Value(AnyEmbedded)`. Code that reads data/// files names it as the value each file decodes to. `Value.Domain` names the type of its embedded/// values, so a caller can pass it to `decode`.pub const Value = value_mod.Value(AnyEmbedded);/// The error set `parse` returns, the same set as `preserves.ParseError`. Code that calls `parse`/// switches on it.pub const ParseError = parse_error_mod.ParseError;pub const NestingError = nesting.Error;pub const max_nesting_depth = nesting.maximum;pub const toText = format.toText;pub const parse = parser.parse;pub const decode = reader.decode;pub const encode = writer.encode;

Audit

Definitions4
Public names4
Members1
Version26.7.0
Revisiondaab053ee433