Skip to main content

sim_codec_algol/
lib.rs

1//! General-purpose Algol codec for the SIM runtime: the infix, Pratt-parsed
2//! surface that round-trips every expression through the shared `Expr` graph.
3//!
4//! A decoder tokenizes infix source and parses it with a precedence-driven
5//! Pratt parser into checked `Expr` forms; an encoder serializes any `Expr`
6//! back to infix text, inserting parentheses according to operator binding
7//! power. Like the Lisp codec, it covers the full expression graph rather than
8//! a single domain, so any value the kernel can hold round-trips through it.
9//!
10//! # Module map
11//!
12//! All submodules are private; their public items are re-exported at the crate
13//! root. `parse` tokenizes and decodes infix source into located expression
14//! trees and exposes `ParseCx`, `SpannedToken`, the `decode_algol_located`
15//! family, and `algol_pratt_shape` for Shape-backed infix matching. `pratt`
16//! holds the precedence-climbing parser (`PrattParser`) and the operator table
17//! (`default_pratt_table`, `supports_pratt`). `encode` renders any `Expr` back
18//! to infix text (`encode_algol`). `runtime` provides the `Lib` registration
19//! (`AlgolCodec`, `AlgolCodecLib`) that wires the codec into the runtime.
20#![forbid(unsafe_code)]
21#![deny(missing_docs)]
22
23mod encode;
24mod parse;
25mod pratt;
26mod runtime;
27
28pub use encode::encode_algol;
29pub use parse::{
30    AlgolShapeParser, ParseCx, SpannedToken, algol_pratt_shape, decode_algol_located,
31    decode_algol_located_with_budget, parse_algol_expr_with_table,
32    parse_algol_expr_with_table_and_budget, tokenize_algol_spanned,
33    tokenize_algol_spanned_with_budget,
34};
35pub use pratt::{
36    AlgolTokenSource, PrattCodecParser, PrattParser, PrattTokenSource, SpannedPrattToken,
37    default_pratt_table, supports_pratt,
38};
39pub use runtime::{AlgolCodec, AlgolCodecLib};
40
41#[cfg(test)]
42mod tests;
43
44/// Cookbook recipes for this codec, embedded at build time.
45pub static RECIPES: sim_cookbook::EmbeddedDir =
46    include!(concat!(env!("OUT_DIR"), "/cookbook_recipes.rs"));