Add OnStop (though I'm not sure about it as a permanent feature! The syntax is gross)
This commit is contained in:
parent
d5f14ab761
commit
13a0100ad8
|
@ -64,6 +64,9 @@ pub enum Instruction {
|
||||||
pattern_template: AnyValue,
|
pattern_template: AnyValue,
|
||||||
body: Box<Instruction>,
|
body: Box<Instruction>,
|
||||||
},
|
},
|
||||||
|
OnStop {
|
||||||
|
body: Box<Instruction>,
|
||||||
|
},
|
||||||
Sequence {
|
Sequence {
|
||||||
instructions: Vec<Instruction>,
|
instructions: Vec<Instruction>,
|
||||||
},
|
},
|
||||||
|
@ -425,6 +428,10 @@ impl Env {
|
||||||
observer,
|
observer,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Instruction::OnStop { body } => {
|
||||||
|
let mut env = self.clone();
|
||||||
|
t.on_stop(enclose!((body) move |t| Ok(env.eval(t, &*body)?)));
|
||||||
|
}
|
||||||
Instruction::Sequence { instructions } => {
|
Instruction::Sequence { instructions } => {
|
||||||
for i in instructions {
|
for i in instructions {
|
||||||
self.eval(t, i)?;
|
self.eval(t, i)?;
|
||||||
|
@ -682,6 +689,12 @@ impl<'t> Parser<'t> {
|
||||||
Instruction::During { target, pattern_template, body } },
|
Instruction::During { target, pattern_template, body } },
|
||||||
"?" => |target, pattern_template, body| {
|
"?" => |target, pattern_template, body| {
|
||||||
Instruction::OnMessage { 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!(
|
_ => return self.error(format!(
|
||||||
"Invalid use of pattern binder in target: ?{}", s)),
|
"Invalid use of pattern binder in target: ?{}", s)),
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue