mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 11:46:42 +01:00
This commit is contained in:
parent
7097333993
commit
93b1cf1a5c
1 changed files with 86 additions and 94 deletions
|
|
@ -2,137 +2,129 @@ use crate::*;
|
||||||
|
|
||||||
impl<S, A> Dsl<S> for When<A> where S: Eval<Ast, bool> + Eval<Ast, A> {
|
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> {
|
fn try_provide (state: S, source: Ast) -> Perhaps<Self> {
|
||||||
Ok(match source.peek() {
|
if let Ast::Exp(source) = source {
|
||||||
Some(Value::Key("when")) => Some(Self(
|
if let Some(Ast::Key(id)) = source.next() && *id == *"when" {
|
||||||
state.eval(source, ||"when: expected condition")?,
|
return Ok(Some(Self(
|
||||||
state.eval(source, ||"when: expected content")?,
|
state.eval(source.next().unwrap(), ||"when: expected condition")?,
|
||||||
)),
|
state.eval(source.next().unwrap(), ||"when: expected content")?,
|
||||||
_ => None
|
)))
|
||||||
})
|
}
|
||||||
|
}
|
||||||
|
Ok(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, A, B> Dsl<S> for Either<A, B> where S: Eval<Ast, bool> + Eval<Ast, A> + Eval<Ast, B> {
|
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> {
|
fn try_provide (state: S, mut source: Ast) -> Perhaps<Self> {
|
||||||
Ok(match source.peek() {
|
if let Ast::Exp(mut source) = source {
|
||||||
Some(Value::Key("either")) => Some(Self(
|
if let Some(Ast::Key(id)) = source.next() && *id == *"either" {
|
||||||
state.eval(source, ||"either: expected condition")?,
|
return Ok(Some(Self(
|
||||||
state.eval(source, ||"either: expected content 1")?,
|
state.eval(source.next().unwrap(), ||"either: expected condition")?,
|
||||||
state.eval(source, ||"either: expected content 2")?
|
state.eval(source.next().unwrap(), ||"either: expected content 1")?,
|
||||||
)),
|
state.eval(source.next().unwrap(), ||"either: expected content 2")?,
|
||||||
_ => None
|
)))
|
||||||
})
|
}
|
||||||
|
}
|
||||||
|
Ok(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, A, B> Dsl<S> for Bsp<A, B> where S: Eval<Ast, A> + Eval<Ast, B> {
|
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> {
|
fn try_provide (state: S, source: Ast) -> Perhaps<Self> {
|
||||||
Ok(Some(match source.peek() {
|
Ok(Some(if let Ast::Exp(source) = source {
|
||||||
Some(Value::Key("bsp/n")) => {
|
match source.next() {
|
||||||
let _ = source.next();
|
Some(Value::Key("bsp/n")) => {
|
||||||
let a: A = state.eval(source, ||"bsp/n: expected content 1")?;
|
let a: A = state.eval(source.next(), ||"bsp/n: expected content 1")?;
|
||||||
let b: B = state.eval(source, ||"bsp/n: expected content 2")?;
|
let b: B = state.eval(source.next(), ||"bsp/n: expected content 2")?;
|
||||||
Self::n(a, b)
|
Self::n(a, b)
|
||||||
},
|
},
|
||||||
Some(Value::Key("bsp/s")) => {
|
Some(Value::Key("bsp/s")) => {
|
||||||
let _ = source.next();
|
let a: A = state.eval(source.next(), ||"bsp/s: expected content 1")?;
|
||||||
let a: A = state.eval(source, ||"bsp/s: expected content 1")?;
|
let b: B = state.eval(source.next(), ||"bsp/s: expected content 2")?;
|
||||||
let b: B = state.eval(source, ||"bsp/s: expected content 2")?;
|
Self::s(a, b)
|
||||||
Self::s(a, b)
|
},
|
||||||
},
|
Some(Value::Key("bsp/e")) => {
|
||||||
Some(Value::Key("bsp/e")) => {
|
let a: A = state.eval(source.next(), ||"bsp/e: expected content 1")?;
|
||||||
let _ = source.next();
|
let b: B = state.eval(source.next(), ||"bsp/e: expected content 2")?;
|
||||||
let a: A = state.eval(source, ||"bsp/e: expected content 1")?;
|
Self::e(a, b)
|
||||||
let b: B = state.eval(source, ||"bsp/e: expected content 2")?;
|
},
|
||||||
Self::e(a, b)
|
Some(Value::Key("bsp/w")) => {
|
||||||
},
|
let a: A = state.eval(source.next(), ||"bsp/w: expected content 1")?;
|
||||||
Some(Value::Key("bsp/w")) => {
|
let b: B = state.eval(source.next(), ||"bsp/w: expected content 2")?;
|
||||||
let _ = source.next();
|
Self::w(a, b)
|
||||||
let a: A = state.eval(source, ||"bsp/w: expected content 1")?;
|
},
|
||||||
let b: B = state.eval(source, ||"bsp/w: expected content 2")?;
|
Some(Value::Key("bsp/a")) => {
|
||||||
Self::w(a, b)
|
let a: A = state.eval(source.next(), ||"bsp/a: expected content 1")?;
|
||||||
},
|
let b: B = state.eval(source.next(), ||"bsp/a: expected content 2")?;
|
||||||
Some(Value::Key("bsp/a")) => {
|
Self::a(a, b)
|
||||||
let _ = source.next();
|
},
|
||||||
let a: A = state.eval(source, ||"bsp/a: expected content 1")?;
|
Some(Value::Key("bsp/b")) => {
|
||||||
let b: B = state.eval(source, ||"bsp/a: expected content 2")?;
|
let a: A = state.eval(source.next(), ||"bsp/b: expected content 1")?;
|
||||||
Self::a(a, b)
|
let b: B = state.eval(source.next(), ||"bsp/b: expected content 2")?;
|
||||||
},
|
Self::b(a, b)
|
||||||
Some(Value::Key("bsp/b")) => {
|
},
|
||||||
let _ = source.next();
|
_ => return Ok(None),
|
||||||
let a: A = state.eval(source, ||"bsp/b: expected content 1")?;
|
}
|
||||||
let b: B = state.eval(source, ||"bsp/b: expected content 2")?;
|
} else {
|
||||||
Self::b(a, b)
|
return Ok(None)
|
||||||
},
|
|
||||||
_ => return Ok(None),
|
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, A> Dsl<S> for Align<A> where S: 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> {
|
fn try_provide (state: S, source: Ast) -> Perhaps<Self> {
|
||||||
Ok(if let Some(Value::Key(key)) = source.peek() {
|
Ok(Some(if let Ast::Exp(source) = source {
|
||||||
Some(match key {
|
match source.next() {
|
||||||
"align/c" => {
|
Some(Value::Key("align/c")) => {
|
||||||
let _ = source.next();
|
let content: A = state.eval(source.next(), ||"align/c: expected content")?;
|
||||||
let content: A = state.eval(source, ||"align/c: expected content")?;
|
|
||||||
Self::c(content)
|
Self::c(content)
|
||||||
},
|
},
|
||||||
"align/x" => {
|
Some(Value::Key("align/x")) => {
|
||||||
let _ = source.next();
|
let content: A = state.eval(source.next(), ||"align/x: expected content")?;
|
||||||
let content: A = state.eval(source, ||"align/x: expected content")?;
|
|
||||||
Self::x(content)
|
Self::x(content)
|
||||||
},
|
},
|
||||||
"align/y" => {
|
Some(Value::Key("align/y")) => {
|
||||||
let _ = source.next();
|
let content: A = state.eval(source.next(), ||"align/y: expected content")?;
|
||||||
let content: A = state.eval(source, ||"align/y: expected content")?;
|
|
||||||
Self::y(content)
|
Self::y(content)
|
||||||
},
|
},
|
||||||
"align/n" => {
|
Some(Value::Key("align/n")) => {
|
||||||
let _ = source.next();
|
let content: A = state.eval(source.next(), ||"align/n: expected content")?;
|
||||||
let content: A = state.eval(source, ||"align/n: expected content")?;
|
|
||||||
Self::n(content)
|
Self::n(content)
|
||||||
},
|
},
|
||||||
"align/s" => {
|
Some(Value::Key("align/s")) => {
|
||||||
let _ = source.next();
|
let content: A = state.eval(source.next(), ||"align/s: expected content")?;
|
||||||
let content: A = state.eval(source, ||"align/s: expected content")?;
|
|
||||||
Self::s(content)
|
Self::s(content)
|
||||||
},
|
},
|
||||||
"align/e" => {
|
Some(Value::Key("align/e")) => {
|
||||||
let _ = source.next();
|
let content: A = state.eval(source.next(), ||"align/e: expected content")?;
|
||||||
let content: A = state.eval(source, ||"align/e: expected content")?;
|
|
||||||
Self::e(content)
|
Self::e(content)
|
||||||
},
|
},
|
||||||
"align/w" => {
|
Some(Value::Key("align/w")) => {
|
||||||
let _ = source.next();
|
let content: A = state.eval(source.next(), ||"align/w: expected content")?;
|
||||||
let content: A = state.eval(source, ||"align/w: expected content")?;
|
|
||||||
Self::w(content)
|
Self::w(content)
|
||||||
},
|
},
|
||||||
"align/nw" => {
|
Some(Value::Key("align/nw")) => {
|
||||||
let _ = source.next();
|
let content: A = state.eval(source.next(), ||"align/nw: expected content")?;
|
||||||
let content: A = state.eval(source, ||"align/nw: expected content")?;
|
|
||||||
Self::nw(content)
|
Self::nw(content)
|
||||||
},
|
},
|
||||||
"align/ne" => {
|
Some(Value::Key("align/ne")) => {
|
||||||
let _ = source.next();
|
let content: A = state.eval(source.next(), ||"align/ne: expected content")?;
|
||||||
let content: A = state.eval(source, ||"align/ne: expected content")?;
|
|
||||||
Self::ne(content)
|
Self::ne(content)
|
||||||
},
|
},
|
||||||
"align/sw" => {
|
Some(Value::Key("align/sw")) => {
|
||||||
let _ = source.next();
|
let content: A = state.eval(source.next(), ||"align/sw: expected content")?;
|
||||||
let content: A = state.eval(source, ||"align/sw: expected content")?;
|
|
||||||
Self::sw(content)
|
Self::sw(content)
|
||||||
},
|
},
|
||||||
"align/se" => {
|
Some(Value::Key("align/se")) => {
|
||||||
let _ = source.next();
|
let content: A = state.eval(source.next(), ||"align/se: expected content")?;
|
||||||
let content: A = state.eval(source, ||"align/se: expected content")?;
|
|
||||||
Self::se(content)
|
Self::se(content)
|
||||||
},
|
},
|
||||||
_ => return Ok(None),
|
_ => return Ok(None),
|
||||||
})
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
return Ok(None)
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue