Expand description
rpic-core — engine for the pic picture-drawing language.
Pipeline: source → lexer → parser → ast → [eval] → placed
primitives (ir) → render backends (svg, later PNG/PDF). This crate
is pure (no file I/O); the CLI and WASM wrappers drive it.
Note: [eval] is the pic-language interpreter — a safe walker over a typed
expression/geometry tree. It executes no arbitrary code.
Re-exports§
pub use ast::IncludeCtx;pub use ast::IncludePolicy;pub use diagnostic::CompileError;pub use diagnostic::Diagnostic;pub use diagnostic::Span;pub use eval::EvalError;pub use eval::eval;pub use ir::Drawing;pub use lexer::LexError;pub use lexer::lex;pub use parser::ParseError;pub use parser::parse;pub use parser::parse_in_dir;pub use parser::parse_with_prelude;pub use svg::to_svg;pub use token::Token;
Modules§
- ast
- Abstract syntax tree for the pic language.
- diagnostic
- Structured compiler diagnostics for editor/front-end integrations.
- eval
- Evaluator: walks the
crate::astand produces a placed-primitiveDrawingusing pic’s positioning semantics. - geom
- Geometry primitives. pic works in a Cartesian plane with y pointing up; internal units are pic “inches” (scaled to device units by each backend).
- ir
- Intermediate representation: the placed-primitive tree produced by the evaluator and consumed by the render backends. All coordinates are absolute, in pic units (inches), y pointing up.
- lexer
- Hand-written lexer for the pic language.
- parser
- Recursive-descent parser for the pic drawing core.
- svg
- SVG 1.1 backend. Renders a
Drawingto an SVG string. - token
- Token set for the pic language, mirroring dpic’s
dpic.toks.
Structs§
- Compile
Options - Compile options for the
*_with_optionsentry points — the library equivalents of the CLI flags. Preludes (circuits,texlabels) are lexed as their own named source units, NOT glued in front of the user’s source, so diagnostic positions always stay relative to the source they belong to (Diagnostic::filenames an include/library;Noneis the user’s input). - Math
Span - A typeset math label: a self-contained SVG fragment (glyph paths only, rasterizable with no font database) plus exact metrics in inches.
Constants§
- CIRCUITS
- Bundled native circuit-element library (the
definedialect). Prepend it to source to useresistor,capacitor, … Seestd/circuits.pic.
Functions§
- animations_
json - Build the JSON animation manifest array (
[{id,effect,start,duration},…]) for an already-compiled drawing. - compile
- Compile pic source into a placed-primitive
Drawing. - compile_
in_ dir - Compile pic source, resolving
copy "file"includes relative tobase. - compile_
json - Compile to a single JSON object
{ "svg": "...", "animations": [...], "diagnostics": [...], "warnings": [...] }, or{ "error": "...", "error_info": { ... } }on failure. The flaterrorstring is kept for backward compatibility with older bindings. - compile_
json_ in_ dir - Compile to a JSON bundle, resolving
copy "file"includes relative tobase. - compile_
json_ with_ options - Compile to a JSON bundle with
CompileOptions. Diagnostic positions are relative to the user’ssrc(or carry afilenaming the include/library they are in) — never to a concatenated stream. - compile_
with_ diagnostics - Like
compile_with_options, but failures return the structuredCompileError(flat message +Diagnostic) instead of a bare string — for bindings that attach position data to exceptions/conditions. - compile_
with_ options - Compile pic source with
CompileOptionsinto aDrawing. - diagnostics_
json - Build the JSON diagnostic array emitted by pic
printstatements. - render_
svg - Compile pic source directly to an SVG string.
- render_
svg_ in_ dir - Render pic source to SVG, resolving
copy "file"includes relative tobase. - render_
svg_ with_ options - Render pic source to SVG with
CompileOptions. - set_
math_ renderer - Register the process-wide math renderer. The first call wins; later calls are ignored (returns whether this call installed the renderer).