mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 19:56:44 +01:00
why implement Dsl for &Dsl otherwise?
This commit is contained in:
parent
4f1131744b
commit
ad2d7c38b1
2 changed files with 8 additions and 8 deletions
|
|
@ -248,21 +248,21 @@ pub trait DslNs<'t, T: 't>: 't {
|
|||
/// Known expressions.
|
||||
const EXPRS: DslExprs<'t, Self, T> = DslNsMap::new(&[]);
|
||||
/// Resolve an expression or symbol.
|
||||
fn from <D: Dsl> (&'t self, dsl: &D) -> Perhaps<T> {
|
||||
if let Ok(Some(literal)) = self.from_literal(dsl) {
|
||||
fn from (&'t self, dsl: impl Dsl) -> Perhaps<T> {
|
||||
if let Ok(Some(literal)) = self.from_literal(&dsl) {
|
||||
Ok(Some(literal))
|
||||
} else if let Ok(Some(meaning)) = self.from_word(dsl) {
|
||||
} else if let Ok(Some(meaning)) = self.from_word(&dsl) {
|
||||
Ok(Some(meaning))
|
||||
} else {
|
||||
self.from_expr(dsl)
|
||||
self.from_expr(&dsl)
|
||||
}
|
||||
}
|
||||
/// Resolve as literal if valid.
|
||||
fn from_literal <D: Dsl> (&self, _: &D) -> Perhaps<T> {
|
||||
fn from_literal (&self, _: impl Dsl) -> Perhaps<T> {
|
||||
Ok(None)
|
||||
}
|
||||
/// Resolve a symbol if known.
|
||||
fn from_word <D: Dsl> (&'t self, dsl: &D) -> Perhaps<T> {
|
||||
fn from_word (&'t self, dsl: impl Dsl) -> Perhaps<T> {
|
||||
if let Some(dsl) = dsl.word()? {
|
||||
for (key, get) in Self::WORDS.0.iter() {
|
||||
if dsl == *key {
|
||||
|
|
@ -274,7 +274,7 @@ pub trait DslNs<'t, T: 't>: 't {
|
|||
return Ok(None)
|
||||
}
|
||||
/// Resolve an expression if known.
|
||||
fn from_expr <D: Dsl> (&'t self, dsl: &D) -> Perhaps<T> {
|
||||
fn from_expr (&'t self, dsl: impl Dsl) -> Perhaps<T> {
|
||||
if let Some(expr) = dsl.expr()? {
|
||||
for (key, get) in Self::EXPRS.0.iter() {
|
||||
if Some(*key) == expr.head()? {
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@
|
|||
$(dsl_ns!{@word ($state: $State) -> $Type { $pat => $body }}),*]);
|
||||
const EXPRS: DslExprs<'t, $State, $Type> = DslNsMap::new(&[
|
||||
$(dsl_ns!{@exp ($state: $State) -> $Type { $pat => $body }}),*]);
|
||||
fn from_literal <D: Dsl> (&self, dsl: &D) -> Perhaps<$Type> {
|
||||
fn from_literal (&self, dsl: impl Dsl) -> Perhaps<$Type> {
|
||||
Ok(if let Some(src) = dsl.src()? {
|
||||
Some(to_number(src)? as $Type)
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue