wip: slowly remembering where i was
Some checks failed
/ build (push) Has been cancelled

This commit is contained in:
🪞👃🪞 2025-06-13 11:42:20 +03:00
parent 17506726cb
commit c8827b43c3
9 changed files with 114 additions and 135 deletions

View file

@ -2,8 +2,9 @@ use crate::*;
use Value::*;
impl<S, A> Dsl<S> for When<A> where S: Eval<Ast, bool> + Eval<Ast, A> {
fn try_provide (state: &S, source: Ast) -> Perhaps<Self> {
if let Exp(_, mut exp) = source.0 && let Some(Ast(Key(id))) = exp.peek() && *id == *"when" {
fn try_provide (state: &S, source: impl DslValue) -> Perhaps<Self> {
if let Exp(_, mut exp) = source.value()
&& let Some(Ast(Key(id))) = exp.peek() && *id == *"when" {
let _ = exp.next();
return Ok(Some(Self(
state.eval(exp.next().unwrap(), ||"when: expected condition")?,
@ -15,8 +16,9 @@ impl<S, A> Dsl<S> for When<A> where S: Eval<Ast, bool> + Eval<Ast, A> {
}
impl<S, A, B> Dsl<S> for Either<A, B> where S: Eval<Ast, bool> + Eval<Ast, A> + Eval<Ast, B> {
fn try_provide (state: &S, source: Ast) -> Perhaps<Self> {
if let Exp(_, mut exp) = source.0 && let Some(Ast(Key(id))) = exp.peek() && *id == *"either" {
fn try_provide (state: &S, source: impl DslValue) -> Perhaps<Self> {
if let Exp(_, mut exp) = source.value()
&& let Some(Ast(Key(id))) = exp.peek() && *id == *"either" {
let _ = exp.next();
return Ok(Some(Self(
state.eval(exp.next().unwrap(), ||"either: expected condition")?,
@ -29,8 +31,8 @@ impl<S, A, B> Dsl<S> for Either<A, B> where S: Eval<Ast, bool> + Eval<Ast, A> +
}
impl<S, A> Dsl<S> for Align<A> where S: Eval<Option<Ast>, A> {
fn try_provide (state: &S, source: Ast) -> Perhaps<Self> {
if let Exp(_, source) = source.0 {
fn try_provide (state: &S, source: impl DslValue) -> Perhaps<Self> {
if let Exp(_, source) = source.value() {
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")?),
@ -52,8 +54,8 @@ impl<S, A> Dsl<S> for Align<A> where S: Eval<Option<Ast>, A> {
}
impl<S, A, B> Dsl<S> for Bsp<A, B> where S: Eval<Option<Ast>, A> + Eval<Option<Ast>, B> {
fn try_provide (state: &S, source: Ast) -> Perhaps<Self> {
if let Exp(_, exp) = source.0 {
fn try_provide (state: &S, source: impl DslValue) -> Perhaps<Self> {
if let Exp(_, exp) = source.value() {
let mut rest = exp.clone();
return Ok(Some(match rest.next().as_ref().and_then(|x|x.key()) {
Some("bsp/n") => Self::n(