Skip to main content

Crate sim_codec_algol

Crate sim_codec_algol 

Source
Expand description

General-purpose Algol codec for the SIM runtime: the infix, Pratt-parsed surface that round-trips every expression through the shared Expr graph.

A decoder tokenizes infix source and parses it with a precedence-driven Pratt parser into checked Expr forms; an encoder serializes any Expr back to infix text, inserting parentheses according to operator binding power. Like the Lisp codec, it covers the full expression graph rather than a single domain, so any value the kernel can hold round-trips through it.

§Module map

All submodules are private; their public items are re-exported at the crate root. parse tokenizes and decodes infix source into located expression trees and exposes ParseCx, SpannedToken, and the decode_algol_located family. pratt holds the precedence-climbing parser (PrattParser) and the operator table (default_pratt_table, supports_pratt). encode renders any Expr back to infix text (encode_algol). runtime provides the Lib registration (AlgolCodec, AlgolCodecLib) that wires the codec into the runtime.

Structs§

AlgolCodec
Runtime decoder and encoder for the Algol surface, wrapping a PrattParser over crate::default_pratt_table.
AlgolCodecLib
The Lib that registers the Algol codec (codec:algol) with the runtime.
ParseCx
Cursor over a spanned Algol token stream, driving the Pratt parser with peek, advance, and lookahead operations.
PrattParser
Precedence-climbing parser for the Algol surface: tokenizes infix source and parses it into LocatedExprTree forms using operator binding powers from its PrattTable.
SpannedToken
A Pratt token paired with its byte span and the trivia (whitespace and comments) that preceded it, so source layout can be reconstructed on encode.

Functions§

decode_algol_located
Decodes Algol source into a LocatedExpr, attaching span and trivia origin so source layout round-trips.
decode_algol_located_with_budget
Decodes Algol source into a LocatedExpr under an explicit decode budget.
default_pratt_table
Builds the default Algol operator table.
encode_algol
Renders an Expr back to Algol infix text using the operator table.
parse_algol_expr_with_table
Parses Algol source into a bare Expr using a caller-supplied operator table, lowering raw number literals through cx.
parse_algol_expr_with_table_and_budget
Parses Algol source into a bare Expr under an explicit decode budget, using a caller-supplied operator table.
supports_pratt
Reports whether this codec offers Pratt parsing. Always true for the Algol surface.
tokenize_algol_spanned
Tokenizes Algol source into spanned tokens under a default decode budget.
tokenize_algol_spanned_with_budget
Tokenizes Algol source into spanned tokens under an explicit budget.