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§
- Algol
Codec - Runtime decoder and encoder for the Algol surface, wrapping a
PrattParserovercrate::default_pratt_table. - Algol
Codec Lib - The
Libthat 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.
- Pratt
Parser - Precedence-climbing parser for the Algol surface: tokenizes infix source and
parses it into
LocatedExprTreeforms using operator binding powers from itsPrattTable. - Spanned
Token - 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
LocatedExprunder an explicit decodebudget. - default_
pratt_ table - Builds the default Algol operator table.
- encode_
algol - Renders an
Exprback to Algol infix text using the operatortable. - parse_
algol_ expr_ with_ table - Parses Algol
sourceinto a bareExprusing a caller-supplied operatortable, lowering raw number literals throughcx. - parse_
algol_ expr_ with_ table_ and_ budget - Parses Algol
sourceinto a bareExprunder an explicit decodebudget, using a caller-supplied operatortable. - supports_
pratt - Reports whether this codec offers Pratt parsing. Always
truefor the Algol surface. - tokenize_
algol_ spanned - Tokenizes Algol
sourceinto spanned tokens under a default decode budget. - tokenize_
algol_ spanned_ with_ budget - Tokenizes Algol
sourceinto spanned tokens under an explicitbudget.