diff --git a/syndicate-server/src/script/mod.rs b/syndicate-server/src/script/mod.rs index fdfa57b..355b569 100644 --- a/syndicate-server/src/script/mod.rs +++ b/syndicate-server/src/script/mod.rs @@ -64,6 +64,9 @@ pub enum Instruction { pattern_template: AnyValue, body: Box, }, + OnStop { + body: Box, + }, Sequence { instructions: Vec, }, @@ -425,6 +428,10 @@ impl Env { observer, }); } + Instruction::OnStop { body } => { + let mut env = self.clone(); + t.on_stop(enclose!((body) move |t| Ok(env.eval(t, &*body)?))); + } Instruction::Sequence { instructions } => { for i in instructions { self.eval(t, i)?; @@ -682,6 +689,12 @@ impl<'t> Parser<'t> { Instruction::During { target, pattern_template, body } }, "?" => |target, pattern_template, body| { Instruction::OnMessage { target, pattern_template, body } }, + "-" => match self.parse(target) { + Parsed::Value(i) => return Parsed::Value(Instruction::OnStop { + body: Box::new(i), + }), + other => return other, + }, _ => return self.error(format!( "Invalid use of pattern binder in target: ?{}", s)), };