pub fn eval_body(self, body: &[Item]) -> Result<Option<Value>, Error>
    where
        Self: Sized,
    {
        for b in body {
            let result = match *b {
                Item::IfStatement(ref cond, ref do_if, ref do_else) => {
                    if cond.evaluate(self.clone())?.is_true() {
                        self.clone().eval_body(do_if)?
                    } else {
                        self.clone().eval_body(do_else)?
                    }
                }
                Item::Each(ref names, ref values, ref body) => {
                    let s = self.clone();
                    for value in values.evaluate(s.clone())?.iter_items() {
                        s.define_multi(names, &value);
                        if let Some(r) = s.clone().eval_body(body)? {
                            return Ok(Some(r));
                        }
                    }
                    None
                }
                Item::For {
                    ref name,
                    ref from,
                    ref to,
                    inclusive,
                    ref body,
                } => {
                    let range = crate::value::ValueRange::new(
                        from.evaluate(self.clone())?,
                        to.evaluate(self.clone())?,
                        inclusive,
                    )?;
                    let s = self.clone();
                    for value in range {
                        s.define(name.clone(), &value);
                        if let Some(r) = s.clone().eval_body(body)? {
                            return Ok(Some(r));
                        }
                    }
                    None
                }
                Item::VariableDeclaration {
                    ref name,
                    ref val,
                    default,
                    global,
                } => {
                    let val = val.evaluate(self.clone())?;
                    self.set_variable(name.into(), val, default, global);
                    None
                }
                Item::Return(ref v) => {
                    Some(v.do_evaluate(self.clone(), true)?)
                }
                Item::While(ref cond, ref body) => {
                    let scope = ScopeRef::sub(self.clone());
                    while cond.evaluate(scope.clone())?.is_true() {
                        if let Some(r) = scope.clone().eval_body(body)? {
                            return Ok(Some(r));
                        }
                    }
                    None
                }
                Item::Warn(ref value) => {
                    eprintln!(
                        "WARNING: {}",
                        value
                            .evaluate(self.clone())?
                            .format(self.get_format())
                    );
                    None
                }
                Item::Error(ref value, ref pos) => {
                    return Err(Error::AtError(
                        value
                            .evaluate(self)?
                            .format(Format::introspect())
                            .to_string(),
                        pos.clone(),
                    ));
                }
                Item::None => None,
                Item::Comment(..) => None,
                ref x => {
                    return Err(Error::S(format!(
                        "Not implemented in function: {:?}",
                        x
                    )))
                }
            };
            if let Some(result) = result {
                return Ok(Some(result));
            }
        }
        Ok(None)
    }
/// Evaluate a body of items in this scope.
Evaluate a body of items in this scope.
Evaluate a body of items in this scope .
pub fn eval_body(self, body: &[Item]) -> Result<Option<Value>, Error>
    where
        Self: Sized,
    {
        for b in body {
            let result = match *b {
                Item::IfStatement(ref cond, ref do_if, ref do_else) => {
                    if cond.evaluate(self.clone())?.is_true() {
                        self.clone().eval_body(do_if)?
                    } else {
                        self.clone().eval_body(do_else)?
                    }
                }
                Item::Each(ref names, ref values, ref body) => {
                    let s = self.clone();
                    for value in values.evaluate(s.clone())?.iter_items() {
                        s.define_multi(names, &value);
                        if let Some(r) = s.clone().eval_body(body)? {
                            return Ok(Some(r));
                        }
                    }
                    None
                }
                Item::For {
                    ref name,
                    ref from,
                    ref to,
                    inclusive,
                    ref body,
                } => {
                    let range = crate::value::ValueRange::new(
                        from.evaluate(self.clone())?,
                        to.evaluate(self.clone())?,
                        inclusive,
                    )?;
                    let s = self.clone();
                    for value in range {
                        s.define(name.clone(), &value);
                        if let Some(r) = s.clone().eval_body(body)? {
                            return Ok(Some(r));
                        }
                    }
                    None
                }
                Item::VariableDeclaration {
                    ref name,
                    ref val,
                    default,
                    global,
                } => {
                    let val = val.evaluate(self.clone())?;
                    self.set_variable(name.into(), val, default, global);
                    None
                }
                Item::Return(ref v) => {
                    Some(v.do_evaluate(self.clone(), true)?)
                }
                Item::While(ref cond, ref body) => {
                    let scope = ScopeRef::sub(self.clone());
                    while cond.evaluate(scope.clone())?.is_true() {
                        if let Some(r) = scope.clone().eval_body(body)? {
                            return Ok(Some(r));
                        }
                    }
                    None
                }
                Item::Warn(ref value) => {
                    eprintln!(
                        "WARNING: {}",
                        value
                            .evaluate(self.clone())?
                            .format(self.get_format())
                    );
                    None
                }
                Item::Error(ref value, ref pos) => {
                    return Err(Error::AtError(
                        value
                            .evaluate(self)?
                            .format(Format::introspect())
                            .to_string(),
                        pos.clone(),
                    ));
                }
                Item::None => None,
                Item::Comment(..) => None,
                ref x => {
                    return Err(Error::S(format!(
                        "Not implemented in function: {:?}",
                        x
                    )))
                }
            };
            if let Some(result) = result {
                return Ok(Some(result));
            }
        }
        Ok(None)
    }
pub fn eval_body ( self , body : & [ Item ] ) -> Result < Option < Value > , Error > where Self : Sized , { for b in body { let result = match * b { Item :: IfStatement ( ref cond , ref do_if , ref do_else ) => { if cond . evaluate ( self . clone ( ) ) ? . is_true ( ) { self . clone ( ) . eval_body ( do_if ) ? } else { self . clone ( ) . eval_body ( do_else ) ? } } Item :: Each ( ref names , ref values , ref body ) => { let s = self . clone ( ) ; for value in values . evaluate ( s . clone ( ) ) ? . iter_items ( ) { s . define_multi ( names , & value ) ; if let Some ( r ) = s . clone ( ) . eval_body ( body ) ? { return Ok ( Some ( r ) ) ; } } None } Item :: For { ref name , ref from , ref to , inclusive , ref body , } => { let range = crate :: value :: ValueRange :: new ( from . evaluate ( self . clone ( ) ) ? , to . evaluate ( self . clone ( ) ) ? , inclusive , ) ? ; let s = self . clone ( ) ; for value in range { s . define ( name . clone ( ) , & value ) ; if let Some ( r ) = s . clone ( ) . eval_body ( body ) ? { return Ok ( Some ( r ) ) ; } } None } Item :: VariableDeclaration { ref name , ref val , default , global , } => { let val = val . evaluate ( self . clone ( ) ) ? ; self . set_variable ( name . into ( ) , val , default , global ) ; None } Item :: Return ( ref v ) => { Some ( v . do_evaluate ( self . clone ( ) , true ) ? ) } Item :: While ( ref cond , ref body ) => { let scope = ScopeRef :: sub ( self . clone ( ) ) ; while cond . evaluate ( scope . clone ( ) ) ? . is_true ( ) { if let Some ( r ) = scope . clone ( ) . eval_body ( body ) ? { return Ok ( Some ( r ) ) ; } } None } Item :: Warn ( ref value ) => { eprintln ! ( " " value evaluate ( self clone ( ) ) format ( self get_format ( ) ) ) ; None } Item :: Error ( ref value , ref pos ) => { return Err ( Error :: AtError ( value . evaluate ( self ) ? . format ( Format :: introspect ( ) ) . to_string ( ) , pos . clone ( ) , ) ) ; } Item :: None => None , Item :: Comment ( .. ) => None , ref x => { return Err ( Error :: S ( format ! ( " " x ) ) ) } } ; if let Some ( result ) = result { return Ok ( Some ( result ) ) ; } } Ok ( None ) }
Evaluate a body of items in this scope.
Evaluate a body of items in this scope .
self
body
&[Item]
self
body
&[Item]