compose_eval/expression/
range.rs1use crate::{Eval, Evaluated, Machine};
2use compose_library::diag::{At, SourceResult};
3use compose_library::{RangeValue, Value};
4use compose_syntax::ast;
5use compose_syntax::ast::AstNode;
6
7impl Eval for ast::Range<'_> {
8 fn eval(self, vm: &mut Machine) -> SourceResult<Evaluated> {
9 let start = self
10 .start()
11 .map(|e| e.eval(vm))
12 .transpose()?
13 .map(Evaluated::into_value);
14 let end = self
15 .end()
16 .map(|e| e.eval(vm))
17 .transpose()?
18 .map(Evaluated::into_value);
19 let include_end = self.is_inclusive();
20
21 Ok(Evaluated::mutable(Value::Range(
22 RangeValue::new(start, end, include_end).at(self.span())?,
23 )))
24 }
25}