1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
use crate::runtime::actiondispatch::dispatchable::*; use crate::structure::xflow::*; use crate::runtime::xfstate::XFState; use crate::parser::flox; #[derive(Serialize, Deserialize, Debug)] struct FloxParameters { expression: String, returns: XFlowVariableDefinition, } #[derive(Debug)] pub struct Flox; impl Flox { fn process_node(&self, node: &XFlowNode, state: &mut XFState) -> () { debug!("Flox: {} - {}", node.id, state); match node.parameters { XFlowNodeParameters::Flox(ref node_params) => { match node.action.as_ref() { "evalexpr" => { debug!( "Flox: evalexpr: '{}' - state: '{}' - params: '{:?}'", node.id, state, node_params ); let expr = node_params.expression.as_str(); debug!("Expression: '{}'", expr); match flox::parse_context(node_params.expression.as_str(), state) { Ok(res) => { debug!("Expression: '{}' - Result: '{:?}'", expr, res); state.add(&XFlowVariable { name: node_params.returns.name.clone(), vtype: node_params.returns.vtype.clone(), value: res.clone(), }); } Err(err) => { error!("Expression: '{}' - Result: '{:?}'", expr, err); } } } _ => { error!( "Unimplemented/unhandled action id: '{}' - state: '{}'", node.id, state ); } } } _ => { error!( "Incorrect NodeType dispatched to Flox processor {:?}!", node ); } } } } impl Default for Flox { fn default() -> Self { Flox {} } } impl Dispatchable for Flox { fn init(&mut self) -> Result<(), ()> { Ok(()) } fn dispatch(&self, node: &XFlowNode, state: &mut XFState) -> Result<(), ()> { self.process_node(node, state); Ok(()) } }