Skip to main content

Crate rpic_core

Crate rpic_core 

Source
Expand description

rpic-core — engine for the pic picture-drawing language.

Pipeline: source → lexerparserast → [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::ast and produces a placed-primitive Drawing using 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 Drawing to an SVG string.
token
Token set for the pic language, mirroring dpic’s dpic.toks.

Structs§

CompileOptions
Compile options for the *_with_options entry 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::file names an include/library; None is the user’s input).
MathSpan
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 define dialect). Prepend it to source to use resistor, capacitor, … See std/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 to base.
compile_json
Compile to a single JSON object { "svg": "...", "animations": [...], "diagnostics": [...], "warnings": [...] }, or { "error": "...", "error_info": { ... } } on failure. The flat error string is kept for backward compatibility with older bindings.
compile_json_in_dir
Compile to a JSON bundle, resolving copy "file" includes relative to base.
compile_json_with_options
Compile to a JSON bundle with CompileOptions. Diagnostic positions are relative to the user’s src (or carry a file naming the include/library they are in) — never to a concatenated stream.
compile_with_diagnostics
Like compile_with_options, but failures return the structured CompileError (flat message + Diagnostic) instead of a bare string — for bindings that attach position data to exceptions/conditions.
compile_with_options
Compile pic source with CompileOptions into a Drawing.
diagnostics_json
Build the JSON diagnostic array emitted by pic print statements.
render_svg
Compile pic source directly to an SVG string.
render_svg_in_dir
Render pic source to SVG, resolving copy "file" includes relative to base.
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).