Expand description
Shape algebra, comparison, and match-hook helpers.
sim-shape supplies concrete Shape implementations while the kernel owns
only the open shape protocol.
use std::sync::Arc;
use sim_kernel::{Cx, DefaultFactory, Expr, NoopEvalPolicy};
use sim_shape::{
AnyShape, ExactExprShape, ExprKind, ExprKindShape, HookedShape, Shape,
ShapeRelationKind, TraceMarkHook, relate_shapes,
};
let mut cx = Cx::new(Arc::new(NoopEvalPolicy), Arc::new(DefaultFactory));
let exact_true = ExactExprShape::new(Expr::Bool(true));
let bool_expr = ExprKindShape::new(ExprKind::Bool);
let relation = relate_shapes(&mut cx, &exact_true, &bool_expr, &[]).unwrap();
assert_eq!(relation.kind, ShapeRelationKind::LeftSubshape);
assert!(relation.proven);
let hooked = HookedShape::new(Arc::new(AnyShape), vec![Arc::new(TraceMarkHook)]);
let matched = hooked.check_expr(&mut cx, &Expr::String("trace me".to_owned())).unwrap();
assert!(matched.accepted);
assert!(matched.diagnostics.iter().any(|diagnostic| {
diagnostic.message.starts_with("shape-hook:mark")
}));§Surface
The engine is organized into private module groups whose public items are re-exported at the crate root (the modules themselves are not public):
primitives– atomic shapes (AnyShape,ExactExprShape,ExprKindShape,ClassShape,NumberValueShape,ListShape,FieldShape) and the combinators and object-grammar parsers built on them.algebra– boolean and collection shape algebra:AndShape,OrShape,NotShape,RepeatShape, andTableShapewith its field and extra-field policies.compare– shape comparison and subsumption: normalization (normalize_shape,ShapeNormalForm), relation analysis (relate_shapes,ShapeRelation), andVennShapeSetset reasoning.citizen– citizen integration: class registration, codec, and construction for shape objects, plus the*_class_symbolaccessors.functions– the callable shape object:FunctionObject,FunctionCase, overload selection, and shape-as-value wrapping.hooks– match-extension hooks:HookedShapeand theMatchHookprotocol with the built-in hook implementations.parse– the shape grammar parser that turns anExprinto aShapeand runs checks against expressions and values.base– the base shape vocabulary re-exported from the kernel (Shape,ShapeMatch,ShapeDoc,Bindings,ShapeReport).
Structs§
- Accept
OnNo Diagnostics Hook - Accept hook that repairs quiet rejections with score 1.
- AndShape
- Shape that accepts only when every child shape accepts.
- AnyShape
- The total shape that accepts every value and expression.
- Bindings
- Captures produced by a successful match: named values and named exprs.
- Capture
Shape - A shape that wraps an inner shape and binds the match under a name.
- Class
Shape - A shape that matches values and expressions of a named class.
- Discard
OnDiagnostic Prefix Hook - Discard hook that rejects accepted matches containing a diagnostic prefix.
- Effectful
Shape - A shape that marks its inner shape’s matching as effectful.
- Exact
Expr Shape - A shape that matches one exact expression form.
- Expr
Kind Shape - A shape that matches expressions of a single
ExprKind. - Field
Shape - A shape that matches an object form field by field.
- Field
Spec - A single field requirement within a
FieldShape: a name, a shape, and whether the field must be present. - Function
Case - One overload case of a
FunctionObject: a shape-typed signature paired with the native code that runs when it is selected. - Function
Object - A callable function object: a named set of shape-typed overload cases with selection driven by case priority and argument match score.
- Hooked
Shape - Shape wrapper that runs neutral match hooks around an inner shape.
- List
Shape - A shape that matches a list positionally, with an optional rest shape.
- Match
Hook Context - Context supplied to every hook invocation.
- Match
Hook Object - Opaque runtime object that carries a shape hook.
- Match
Score - A match quality score used to rank shapes during overload selection.
- NotShape
- Shape that accepts when the inner shape rejects.
- Number
Value Shape - A shape that matches number-domain values and number expressions.
- Object
Expr - The decoded form of an object expression: a class symbol and its fields.
- OneOf
Shape - A shape that matches if any one of its choice shapes matches.
- OrShape
- Shape that accepts when at least one child shape accepts.
- Pratt
Shape - A shape that parses a string expression with a
ShapeExprParserbefore matching. - Repeat
Shape - Shape for homogeneous list-like values and collection expressions.
- Score
Floor Hook - Annotate hook that raises accepted match scores to a minimum floor.
- Selected
Case - The case chosen by overload selection together with its match result.
- Shape
Bindings - Captures produced by a successful match: named values and named exprs.
- Shape
Doc - Human-facing description of a
Shape: a name plus optional detail lines. - Shape
Match - The outcome of checking a value or expr against a
Shape. - Shape
Normal Form - Structural summary used by conservative shape comparison.
- Shape
Object - Runtime object wrapping a
Shapeso it is usable as a first-class value: a callable matcher, a kernel class, and (optionally) a re-encodable constructor expression. - Shape
Relation - Conservative relation report between two shapes.
- Shape
Report - The canonical record of a shape check: who was checked against what, the outcome, and the diagnostics.
- Shape
Witness - Result of checking one probe against both compared shapes.
- Table
Field Spec - One field constraint inside a
TableShape. - Table
Shape - Shape for table values or map expressions with named field constraints.
- Trace
Mark Hook - Mark hook that emits the wrapped shape label before and after matching.
- Venn
Shape Set - Named set of shapes used to build Venn-style regions.
Enums§
- Expr
Kind - A coarse classifier over
Exprvariants, used by grammar shapes. - Match
Hook Decision - Hook result interpreted by
HookedShape. - Match
Hook Kind - Capability class for a match hook decision.
- Match
Hook Phase - Point in the wrapper algorithm where a hook runs.
- Match
Hook Target Kind - Match target observed by a hook.
- OrStrategy
- Branch selection policy for
OrShape. - Shape
Normal Kind - Normalized shape structure understood by comparison helpers.
- Shape
Probe - Example value or expression used to gather relation evidence.
- Shape
Relation Kind - Relation categories reported by
ShapeRelation. - Table
Extra Policy - Policy for keys not listed in a
TableShape.
Traits§
- Match
Hook - Runtime hook contract for neutral shape match membranes.
- Shape
- The one shared engine for matching and binding across the runtime.
- Shape
Expr Parser - A parser that turns shape source text into an
ExprforPrattShape.
Functions§
- accept_
on_ no_ diagnostics_ hook_ class_ symbol - Class symbol for the
AcceptOnNoDiagnosticsHookcitizen (shape/AcceptOnNoDiagnosticsHook). - and_
shape_ class_ symbol - Class symbol for the conjunction shape citizen (
shape/And). - any_
shape_ class_ symbol - Class symbol for the
Anyshape citizen (shape/Any). - binding_
failure_ diagnostic - Builds a diagnostic for a binding failure inside a capture or destructuring shape.
- callable_
mismatch_ diagnostic - Builds a diagnostic for a callable shape argument mismatch.
- case_
result_ shape - Borrow the result shape of a case, if it declares one.
- case_
shape - Borrow the argument shape of a single case.
- check_
shape_ on_ expr - Check an expression against a shape, returning the resulting match.
- check_
shape_ on_ value - Check a runtime value against a shape, returning the resulting match.
- check_
value_ report - Check
valueagainstshape_value, building aShapeReportand publishing the satisfaction claim when accepted. - class_
shape_ class_ symbol - Class symbol for the class-membership shape citizen (
shape/Class). - discard_
on_ diagnostic_ prefix_ hook_ class_ symbol - Class symbol for the
DiscardOnDiagnosticPrefixHookcitizen (shape/DiscardOnDiagnosticPrefixHook). - exact_
expr_ shape_ class_ symbol - Class symbol for the exact-expression shape citizen (
shape/ExactExpr). - expected_
shape_ diagnostic - Builds a diagnostic for an expected-shape mismatch.
- expr_
kind_ shape_ class_ symbol - Class symbol for the expression-kind shape citizen (
shape/ExprKind). - function_
cases - Borrow the overload cases of a function object.
- hook_
ref_ arc - Extract a hook from a runtime value produced by
hook_value. - hook_
value - Wrap a hook as an opaque runtime value.
- hooked_
shape_ class_ symbol - Class symbol for the hook-wrapped shape citizen (
shape/Hooked). - insert_
shape_ satisfaction_ claim - Publish the
satisfies-shapeclaim for an accepted report. - list_
shape_ class_ symbol - Class symbol for the list shape citizen (
shape/List). - normalize_
shape - Build the conservative comparison normal form for a shape.
- not_
shape_ class_ symbol - Class symbol for the negation shape citizen (
shape/Not). - or_
shape_ class_ symbol - Class symbol for the disjunction shape citizen (
shape/Or). - overload
- Merge several functions into one whose cases are the union of theirs.
- overload_
selection_ diagnostic - Builds a diagnostic for overload selection failures or ambiguity.
- parse_
shape_ expr - Build a
Shapefrom a shape-grammar expression. - relate_
shapes - Compare two shapes with conservative proof rules plus optional probes.
- repeat_
shape_ class_ symbol - Class symbol for the repetition shape citizen (
shape/Repeat). - satisfies_
shape_ predicate - The predicate symbol (
core/satisfies-shape) used by satisfaction claims. - score_
floor_ hook_ class_ symbol - Class symbol for the
ScoreFloorHookcitizen (shape/ScoreFloorHook). - shape_
error - Build the
WrongShapeerror an expression produces against an expected shape. - shape_
report_ from_ match - Intern a
ShapeMatchinto aShapeReportfor the given shape and target references. - shape_
value - Wrap a shape as a kernel value: an opaque
ShapeObjectthat carries the given symbol as the shape’s name and exposes it as a callable matcher. - shape_
value_ with_ encoding - Like
shape_valuebut also records the constructor encoding so the resulting value can be re-encoded back to its constructor expression. - table_
shape_ class_ symbol - Class symbol for the table shape citizen (
shape/Table). - trace_
mark_ hook_ class_ symbol - Class symbol for the
TraceMarkHookcitizen (shape/TraceMarkHook). - venn_
shape_ set_ class_ symbol - Class symbol for the Venn-set shape citizen (
shape/Venn).
Type Aliases§
- Native
Function Impl - Native implementation backing a single
FunctionCase.