Expand description
Core decoder/encoder and output-position contracts for the SIM codec layer.
sim-codec is the foundation crate of the sim-codec-* family. The SIM kernel
defines the Expr graph and the codec contract types; this crate provides
the concrete runtime that every other codec crate implements against: the
Decoder/Encoder traits, their located and tree-shaped variants, the
DecodePosition/DecodeTarget output-position model (eval, quote, data,
pattern), and the CodecRuntime glue that registers a codec as a
runtime object. On top of those contracts it carries the shared
Expr<->tree encode machinery, domain-codec scaffolding, decode resource
limits, portable encode/decode, string-literal coding, and tree validation.
A decoder turns tokens or text into a checked Expr form; an encoder knows
its output position and renders an Expr back to text or bytes. Downstream
crates (general-purpose and domain codecs) build on these primitives rather
than re-implementing them.
Module map (these modules are private; their public items are re-exported at the crate root, so they are listed here in plain text rather than linked):
- implementation: implementation root that aggregates the submodules below
and re-exports their public surface.
- runtime: the
Decoder/Encoderruntime contracts, theDecodePosition/DecodeTargetoutput positions,Input/Output, and theCodecRuntimeregistration glue. - domain: builder scaffolding for domain codec libs (
DomainCodecLib) and the shared UTF-8 input helper. - domain_form: a generic
#(...)domain-form parser and formatter. - limits: decode resource ceilings (
DecodeLimits), running budgets (DecodeBudget), and theReadCxdecode context. - list_encode: the shared list/
Exprvalue-to-expr encode machinery. - portable: codec-neutral, lossless portable encode/decode for the data
subset of
Expr. - strings: string-literal encode/decode helpers.
- tree: structural validation of a
LocatedExprTree.
- runtime: the
- runtime_api: the eval-facing surface that drives codecs through the kernel
(
DecodedForm, codec lookup, and decode/encode entry points).
Structs§
- Codec
Runtime - A registered codec as a runtime object: a symbol-named bundle of optional decode/encode capabilities plus the Shapes and default-decode policy it exposes.
- Decode
Budget - Running counters for a single decode. Construct one per decode call.
- Decode
Limits - Resource ceiling shared by every codec decode path.
- Domain
Codec Lib - A host-registered lib that exports one codec (and optionally the Shapes it uses) built from a decoder and encoder.
- Domain
Form - A parsed
#(name ...)form: a name, keyed fields, and positional values. - Loss
Report - Loss report for one parse/encode/reparse cycle.
- Prism
Diagnostic - A parse diagnostic surfaced by the Prism.
- Prism
Encode - Encode result for one codec surface.
- Prism
Inspection - Metadata describing how input was inspected.
- Prism
Parse - Parse result for one codec surface.
- Prism
Span - A half-open byte span belonging to a parsed surface.
- ReadCx
- The decode context threaded through every
Decoder: the kernel context plus the active codec id, read policy, and resource limits. - Round
Trip - Full round-trip proof for one codec surface.
- Runtime
Codec Prism - Runtime-backed
CodecPrismfor an installed codec symbol. - Semantic
Id - Stable identity for a semantic expression.
Enums§
- Binary
Carrier - How binary frame bytes are carried at the codec boundary.
- Codec
Default Decode - A codec’s policy for choosing a
DecodeTargetfrom aDecodePosition. - Decode
Position - The syntactic position a decode is targeting, mirroring the kernel’s
EncodePosition. - Decode
Target - The checked form a decode resolves to once a position is known: inert data or an evaluable term.
- Decoded
Form - The position-resolved result of a default decode: inert data or an evaluable term.
- Diagnostic
Severity - Diagnostic severity.
- Domain
Form Error - A domain-form parse or access error.
- Domain
Value - A parsed domain-form value.
- Input
- Raw input handed to a
Decoder: source text or source bytes. - Output
- Rendered output produced by an
Encoder: text or bytes. - Prism
Input Kind - What kind of input the Prism inspected.
- Prism
Output - Output from a Prism encode pass.
- Prism
Surface - The class of codec surface a Prism is driving.
Traits§
- Codec
Prism - A codec-aware editor contract for one codec surface.
- Decoder
- The core decode contract: turn
Inputinto a checked kernelExpr. - Encoder
- The core encode contract: render a kernel
ExprtoOutput. - Located
Decoder - A decoder that preserves source
Origin, producing aLocatedExpr. - Located
Encoder - An encoder that consumes a
LocatedExpr, able to use source origin for a higher-fidelity rendering than the plainEncoder. - Tree
Decoder - A decoder that preserves the full source tree as a
LocatedExprTree, including trivia, for lossless round-tripping. - Tree
Encoder - An encoder that consumes a full
LocatedExprTree, able to reproduce trivia and exact layout for lossless round-trips.
Functions§
- codec_
value - Wrap a
CodecRuntimeas an opaque runtimeValuefor registry storage. - decode_
datum_ with_ codec - Decode
inputto aDatumwith the codec namedsymbol, using defaultDecodeLimits. - decode_
datum_ with_ codec_ and_ limits - Decode
inputto aDatumunder explicitDecodeLimits, failing if the decodedExpris not inert data. - decode_
default_ with_ codec - Decode
inputand resolve it to data or a term per the codec’s policy and the requestedposition, using defaultDecodeLimits. - decode_
default_ with_ codec_ and_ limits - Position-aware decode under explicit
DecodeLimits; seedecode_default_with_codec. - decode_
located_ with_ codec - Decode
inputpreserving source origin, attributing spans tosource_id, using defaultDecodeLimits. - decode_
located_ with_ codec_ and_ limits - Origin-preserving decode under explicit
DecodeLimits; seedecode_located_with_codec. - decode_
portable - Parse codec-neutral portable text back into an
Expr, failing closed on any malformed input rather than panicking. - decode_
string_ literal - Parse a double-quoted, escaped string literal back to its value.
- decode_
term_ with_ codec - Decode
inputto an evaluableTermwith the codec namedsymbol, using defaultDecodeLimits. - decode_
term_ with_ codec_ and_ limits - Decode
inputto aTermunder explicitDecodeLimits, lowering the decodedExprto a term per the codec’sCodecDefaultDecodepolicy. - decode_
tree_ with_ codec - Decode
inputinto a fullLocatedExprTree(trivia and layout retained), attributing spans tosource_id, using defaultDecodeLimits. - decode_
tree_ with_ codec_ and_ limits - Full-tree decode under explicit
DecodeLimits; seedecode_tree_with_codec. - decode_
with_ codec - Decode
inputwith the codec namedsymbol, using defaultDecodeLimits. - decode_
with_ codec_ and_ limits - Decode
inputwith the codec namedsymbolunder explicitDecodeLimits. - domain_
input_ text - Read a codec
Inputas UTF-8 text, tagging any error withcodec. The shared body of every domain codec’sinput_texthelper. - encode_
datum_ with_ codec - Encode a
Datumwith the codec namedsymbol, lifting it to anExprfirst. - encode_
located_ with_ codec - Encode a
LocatedExprwith the codec namedsymbol, using its origin for fidelity whenoptionsrequest lossless-origin output. - encode_
portable - Serialize a data-subset
Exprinto the codec-neutral portable text form. - encode_
string_ literal - Render
valueas a double-quoted, backslash-escaped string literal. - encode_
term_ with_ codec - Encode a
Termwith the codec namedsymbol, lifting it to anExprfirst. - encode_
tree_ with_ codec - Encode a
LocatedExprTreewith the codec namedsymbol, reproducing layout and trivia whenoptionsrequest lossless-origin output. - encode_
value_ expr - Walk a runtime
Valueinto a kernelExprready for encoding. - encode_
value_ with_ codec - Encode a runtime
Valuewith the codec namedsymbol, forcing lists and tables into anExprviaencode_value_exprbefore encoding. - encode_
with_ codec - Encode
exprwith the codec namedsymbolunderoptions. - force_
list_ for_ encode - Force a list value into a bounded Vec for v1 encoding.
- format_
domain_ form - Render a domain form as an ASCII
#(...)string. Round-trips throughparse_domain_form. - parse_
domain_ form - Parse a top-level
#(...)domain form. - resolve_
expr_ shape - Resolve a general codec’s expression shape: the
primarysymbol, thencore/Expr, thencore/Any, then nil. This is the shared fallback chain that every general-purpose codec (json/binary/binary-base64/algol/lisp/doc) hand-rolled identically before OVERLAP6.07. - resolve_
options_ shape - Resolve a general codec’s encode-options shape:
core/EncodeOptions, thencore/Any, then nil. The shared fallback chain those codecs hand-rolled. - validate_
expr_ tree - Check that a
LocatedExprTreeis structurally consistent with itsExpr.