pub struct Interpreter {
pub max_depth: usize,
pub max_terminals: usize,
pub seed: u64,
/* private fields */
}Fields§
§max_depth: usizeHard cap on rule-derivation recursion depth. Defaults to MAX_DEPTH
(64). Exceeding it returns ShapeError::DepthLimitExceeded.
max_terminals: usizeHard cap on the number of terminals a single derivation may emit.
Defaults to MAX_TERMINALS (100 000). Exceeding it returns
ShapeError::CapacityOverflow.
seed: u64Seed for stochastic rule selection. Each call to Interpreter::derive
constructs a fresh Pcg64 from this seed, so re-running with the same
seed produces a bit-identical ShapeModel. Default 0.
Implementations§
Source§impl Interpreter
impl Interpreter
pub fn new() -> Self
Sourcepub fn add_statement(&mut self, stmt: Statement) -> Result<(), ShapeError>
pub fn add_statement(&mut self, stmt: Statement) -> Result<(), ShapeError>
Registers one parsed grammar statement — rule, attr, const, or
style. The one-stop text loading path:
use symbios_shape::Interpreter;
use symbios_shape::grammar::parse_statement;
let mut interp = Interpreter::new();
for line in ["attr Floors = 3", r#"Lot --> Extrude(Floors * 3.2) I("Mass")"#] {
interp.add_statement(parse_statement(line).unwrap()).unwrap();
}Sourcepub fn set_style(&mut self, name: impl Into<String>) -> Result<(), ShapeError>
pub fn set_style(&mut self, name: impl Into<String>) -> Result<(), ShapeError>
Selects a declared style; its attr overrides apply at derivation
(below host set_attr overrides, above attr defaults).
Sourcepub fn clear_style(&mut self)
pub fn clear_style(&mut self)
Clears any active style.
Sourcepub fn rules(&self) -> &HashMap<String, RuleDef>
pub fn rules(&self) -> &HashMap<String, RuleDef>
Returns a reference to the full rule table (rule name → definition).
Sourcepub fn set_attr(&mut self, name: impl Into<String>, value: f64)
pub fn set_attr(&mut self, name: impl Into<String>, value: f64)
Sets a named attribute readable from grammar expressions. The host’s
override channel: call before derive to parameterize a grammar from
outside (per-lot floor counts, prosperity knobs, …).
Sourcepub fn attrs(&self) -> &HashMap<String, f64>
pub fn attrs(&self) -> &HashMap<String, f64>
Returns the attribute table (host overrides + grammar declarations).
Sourcepub fn set_variants(
&mut self,
name: impl Into<String>,
variants: Vec<RuleVariant>,
)
pub fn set_variants( &mut self, name: impl Into<String>, variants: Vec<RuleVariant>, )
Directly inserts a pre-built variant list for name, bypassing weight validation.
The rule’s declared parameters are preserved when it already exists.
Intended for restoring snapshots produced by
crate::genetics::ShapeGenotype::to_interpreter.
Sourcepub fn add_rule(&mut self, name: impl Into<String>, ops: Vec<ShapeOp>)
pub fn add_rule(&mut self, name: impl Into<String>, ops: Vec<ShapeOp>)
Registers a deterministic production rule.
Sourcepub fn add_grammar_rule(&mut self, rule: GrammarRule) -> Result<(), ShapeError>
pub fn add_grammar_rule(&mut self, rule: GrammarRule) -> Result<(), ShapeError>
Registers a rule parsed from grammar text — parameters, weighted or guarded variants and all. The one-stop registration path for text-driven hosts.
Sourcepub fn add_rule_variants(
&mut self,
name: impl Into<String>,
params: Vec<String>,
variants: Vec<RuleVariant>,
) -> Result<(), ShapeError>
pub fn add_rule_variants( &mut self, name: impl Into<String>, params: Vec<String>, variants: Vec<RuleVariant>, ) -> Result<(), ShapeError>
Registers a rule from pre-built variants, validating selector shape:
all-weighted, or when(..) guards with at most one trailing else.
Sourcepub fn add_rule_def(
&mut self,
name: impl Into<String>,
params: Vec<String>,
variants: Vec<(f64, Vec<ShapeOp>)>,
) -> Result<(), ShapeError>
pub fn add_rule_def( &mut self, name: impl Into<String>, params: Vec<String>, variants: Vec<(f64, Vec<ShapeOp>)>, ) -> Result<(), ShapeError>
Registers a rule with declared parameter names and weighted variants — the full-fidelity registration path for parameterized rules.
Returns Err(InvalidNumericValue) for bad weights and
Err(ParseError) for duplicate or over-long parameter lists.
Sourcepub fn add_weighted_rules(
&mut self,
name: impl Into<String>,
variants: Vec<(f64, Vec<ShapeOp>)>,
) -> Result<(), ShapeError>
pub fn add_weighted_rules( &mut self, name: impl Into<String>, variants: Vec<(f64, Vec<ShapeOp>)>, ) -> Result<(), ShapeError>
Registers a stochastic rule with multiple weighted alternatives.
variants is a list of (relative_weight, ops) pairs. Weights need not
sum to 1.0 — they are normalised internally during selection.
Returns Err(InvalidNumericValue) if any weight is non-finite or negative.
Sourcepub fn derive(
&self,
root_scope: Scope,
root_rule: impl Into<String>,
) -> Result<ShapeModel, ShapeError>
pub fn derive( &self, root_scope: Scope, root_rule: impl Into<String>, ) -> Result<ShapeModel, ShapeError>
Derives the shape model starting from root_scope and root_rule.
Uses a breadth-first work queue to expand rules until all branches
terminate via I(mesh_id) or an unknown rule name (implicit terminal).
A fresh RNG seeded from self.seed is created for each call, making
derivations reproducible for the same seed value.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Interpreter
impl RefUnwindSafe for Interpreter
impl Send for Interpreter
impl Sync for Interpreter
impl Unpin for Interpreter
impl UnsafeUnpin for Interpreter
impl UnwindSafe for Interpreter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more