use super::{Capture, Reject};
use crate::value::{RefValue, Value};
extern crate self as tokay;
#[derive(Debug, Clone)]
pub enum Accept {
Next, Hold, Repeat, Push(Capture), Return(Capture), }
impl Accept {
pub fn into_push(self, severity: u8) -> Accept {
match self {
Self::Next | Self::Hold => Self::Push(Capture::Empty),
Self::Push(mut capture) | Self::Return(mut capture) => {
if capture.get_severity() > severity {
capture.set_severity(severity);
}
Self::Push(capture)
}
Self::Repeat => Self::Push(Capture::Empty),
}
}
pub fn into_refvalue(self) -> RefValue {
match self {
Self::Push(capture) | Self::Return(capture) => capture.get_value(),
_ => tokay::value!(void),
}
}
}
impl From<RefValue> for Result<Accept, Reject> {
fn from(value: RefValue) -> Self {
Ok(Accept::Push(value.into()))
}
}
impl From<Value> for Result<Accept, Reject> {
fn from(value: Value) -> Self {
Ok(Accept::Push(RefValue::from(value).into()))
}
}