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.grammar– codec-neutral grammar graph lowering plus the seed JSON Schema renderer used by existing model-runner contracts.parse– the shape grammar parser that turns anExprinto aShapeand runs checks against expressions and values.query– reusable Shape relation predicates for scoped retrieval.recursive– recursive shape descriptors with named definitions and bounded reference checks.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.
- Grammar
Graph - A named codec-neutral grammar graph.
- Grammar
Target - Target metadata for one rendered grammar.
- 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.
- Option
Field Spec - One option field constraint for
check_option_map. - 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
DefRef - A reference to a named shape inside the surrounding
ShapeDefs. - Shape
Defs - A shape with a root descriptor and named definitions available to refs.
- Shape
Doc - Human-facing description of a
Shape: a name plus optional detail lines. - Shape
Grammar - Rendered grammar text plus its neutral graph and diagnostics.
- 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 for building Venn-style regions.
Enums§
- Expr
Kind - A coarse classifier over
Exprvariants, used by grammar shapes. - Grammar
Dialect - The concrete grammar dialect requested by a renderer.
- Grammar
Position - Output position for a grammar-rendered form.
- 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. - Production
- A codec-neutral grammar production.
- Shape
Normal Kind - Normalized shape structure understood by comparison helpers.
- Shape
Probe - Example value or expression that gathers relation evidence.
- Shape
Query Relation - Direction used when matching a candidate Shape against a requested Shape.
- Shape
Relation Kind - Relation categories reported by
ShapeRelation. - Table
Extra Policy - Policy for keys not listed in a
TableShape. - Terminal
Atom - Abstract terminal atoms that concrete renderers map to their own syntax.
Traits§
- Grammar
Renderer - Renders a neutral
GrammarGraphinto one concrete codec grammar surface. - 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_
option_ map - Check an option-map expression against field specs and an extra-key policy.
- 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_
def_ ref_ class_ symbol - Class symbol for the recursive shape reference citizen (
shape/Ref). - shape_
defs_ class_ symbol - Class symbol for the recursive shape definitions citizen (
shape/Defs). - shape_
error - Build the
WrongShapeerror an expression produces against an expected shape. - shape_
grammar - Lowers
shapeand renders it through a supplied codec-owned renderer. - shape_
grammar_ graph - Lower a
Shapeinto a codec-neutral production graph. - shape_
json_ schema - Render
shapeas JSON Schema using the seed renderer. - shape_
query_ matches - Returns whether
candidatesatisfies the requested relation towanted. - 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.