Skip to main content

parse_shape_expr

Function parse_shape_expr 

Source
pub fn parse_shape_expr(expr: &Expr) -> Result<Arc<dyn Shape>>
Expand description

Build a Shape from a shape-grammar expression.

Bare symbols name the built-in atomic shapes (Any, Number, String, Bool, Symbol, Map, List, Nil, and the core Number value shape); any other symbol becomes a ClassShape for that class. Lists drive the combinator grammar: (capture name Shape) wraps a shape in a CaptureShape, (fields ...) builds an anonymous FieldShape, and any other list becomes a ListShape over its parsed items.

This is parser behavior layered on the kernel Shape protocol; the kernel owns the protocol, this function owns the concrete grammar.

ยงExamples

use sim_kernel::{Expr, Symbol};
use sim_shape::{Shape, parse_shape_expr};

let shape = parse_shape_expr(&Expr::Symbol(Symbol::new("Number"))).unwrap();
assert!(!shape.is_total());