microcad_lang/eval/
body.rs

1// Copyright © 2025 The µcad authors <info@ucad.xyz>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4use crate::{eval::*, model::*};
5
6/// Evaluate the body into a value.
7impl Eval<Value> for Body {
8    fn eval(&self, context: &mut EvalContext) -> EvalResult<Value> {
9        context.scope(StackFrame::Body(SymbolMap::default()), |context| {
10            self.statements.eval(context)
11        })
12    }
13}
14
15/// Evaluate the body into a single group: `{}`.
16impl Eval<Option<Model>> for Body {
17    fn eval(&self, context: &mut EvalContext) -> EvalResult<Option<Model>> {
18        context
19            .scope(StackFrame::Body(SymbolMap::default()), |context| {
20                Ok(ModelBuilder::new(Element::Group, self.src_ref())
21                    .add_children(self.statements.eval(context)?)?
22                    .attributes(self.statements.eval(context)?)
23                    .build())
24            })
25            .map(Some)
26    }
27}