use crate::*; use Value::*; impl Dsl for When where S: Eval + Eval { fn try_provide (state: &S, source: Ast) -> Perhaps { if let Exp(_, mut exp) = source.0 && let Some(Ast(Key(id))) = exp.peek() && *id == *"when" { let _ = exp.next(); return Ok(Some(Self( state.eval(exp.next().unwrap(), ||"when: expected condition")?, state.eval(exp.next().unwrap(), ||"when: expected content")?, ))) } Ok(None) } } impl Dsl for Either where S: Eval + Eval + Eval { fn try_provide (state: &S, source: Ast) -> Perhaps { if let Exp(_, mut exp) = source.0 && let Some(Ast(Key(id))) = exp.peek() && *id == *"either" { let _ = exp.next(); return Ok(Some(Self( state.eval(exp.next().unwrap(), ||"either: expected condition")?, state.eval(exp.next().unwrap(), ||"either: expected content 1")?, state.eval(exp.next().unwrap(), ||"either: expected content 2")?, ))) } Ok(None) } } impl Dsl for Align where S: Eval, A> { fn try_provide (state: &S, source: Ast) -> Perhaps { if let Exp(_, source) = source.0 { let mut rest = source.clone(); return Ok(Some(match rest.next().as_ref().and_then(|x|x.key()) { Some("align/c") => Self::c(state.eval(rest.next(), ||"align/c: expected content")?), Some("align/x") => Self::x(state.eval(rest.next(), ||"align/x: expected content")?), Some("align/y") => Self::y(state.eval(rest.next(), ||"align/y: expected content")?), Some("align/n") => Self::n(state.eval(rest.next(), ||"align/n: expected content")?), Some("align/s") => Self::s(state.eval(rest.next(), ||"align/s: expected content")?), Some("align/e") => Self::e(state.eval(rest.next(), ||"align/e: expected content")?), Some("align/w") => Self::w(state.eval(rest.next(), ||"align/w: expected content")?), Some("align/nw") => Self::nw(state.eval(rest.next(), ||"align/nw: expected content")?), Some("align/ne") => Self::ne(state.eval(rest.next(), ||"align/ne: expected content")?), Some("align/sw") => Self::sw(state.eval(rest.next(), ||"align/sw: expected content")?), Some("align/se") => Self::se(state.eval(rest.next(), ||"align/se: expected content")?), _ => return Ok(None), })) } Ok(None) } } impl Dsl for Bsp where S: Eval, A> + Eval, B> { fn try_provide (state: &S, source: Ast) -> Perhaps { if let Exp(_, exp) = source.0 { let mut rest = exp.clone(); return Ok(Some(match rest.next().as_ref().and_then(|x|x.key()) { Some("bsp/n") => Self::n( state.eval(rest.next(), ||"bsp/n: expected content 1")?, state.eval(rest.next(), ||"bsp/n: expected content 2")?, ), Some("bsp/s") => Self::s( state.eval(rest.next(), ||"bsp/s: expected content 1")?, state.eval(rest.next(), ||"bsp/s: expected content 2")?, ), Some("bsp/e") => Self::e( state.eval(rest.next(), ||"bsp/e: expected content 1")?, state.eval(rest.next(), ||"bsp/e: expected content 2")?, ), Some("bsp/w") => Self::w( state.eval(rest.next(), ||"bsp/w: expected content 1")?, state.eval(rest.next(), ||"bsp/w: expected content 2")?, ), Some("bsp/a") => Self::a( state.eval(rest.next(), ||"bsp/a: expected content 1")?, state.eval(rest.next(), ||"bsp/a: expected content 2")?, ), Some("bsp/b") => Self::b( state.eval(rest.next(), ||"bsp/b: expected content 1")?, state.eval(rest.next(), ||"bsp/b: expected content 2")?, ), _ => return Ok(None), })) } Ok(None) } } //#[cfg(feature = "dsl")] take!($Enum, A|state, words|Ok( //if let Some(Token { value: Key(k), .. }) = words.peek() { //let mut base = words.clone(); //let content = state.give_or_fail(words, ||format!("{k}: no content"))?; //return Ok(Some(match words.next() { //Some(Token{value: Key($x),..}) => Self::x(content), //Some(Token{value: Key($y),..}) => Self::y(content), //Some(Token{value: Key($xy),..}) => Self::xy(content), //_ => unreachable!() //})) //} else { //None //})); //#[cfg(feature = "dsl")] take!($Enum, U, A|state, words|Ok( //if let Some(Token { value: Key($x|$y|$xy), .. }) = words.peek() { //let mut base = words.clone(); //Some(match words.next() { //Some(Token { value: Key($x), .. }) => Self::x( //state.give_or_fail(words, ||"x: no unit")?, //state.give_or_fail(words, ||"x: no content")?, //), //Some(Token { value: Key($y), .. }) => Self::y( //state.give_or_fail(words, ||"y: no unit")?, //state.give_or_fail(words, ||"y: no content")?, //), //Some(Token { value: Key($x), .. }) => Self::xy( //state.give_or_fail(words, ||"xy: no unit x")?, //state.give_or_fail(words, ||"xy: no unit y")?, //state.give_or_fail(words, ||"xy: no content")? //), //_ => unreachable!(), //}) //} else { //None //}));