wip: refactor dsl
Some checks failed
/ build (push) Has been cancelled

This commit is contained in:
🪞👃🪞 2025-06-14 16:08:02 +03:00
parent c8827b43c3
commit 91dc77cfea
16 changed files with 931 additions and 823 deletions

31
dsl/src/ast.rs Normal file
View file

@ -0,0 +1,31 @@
use crate::*;
#[derive(Debug, Clone, Default, PartialEq)]
pub struct Ast(pub AstValue);
/// The abstract syntax tree (AST) can be produced from the CST
/// by cloning source slices into owned [Arc] values.
pub type AstValue = DslValue<Arc<str>, VecDeque<Ast>>;
//#[derive(Debug, Clone, Default, PartialEq)]
//pub struct AstIter();
impl<'src> From<Cst<'src>> for Ast {
fn from (token: Cst<'src>) -> Self {
token.value().into()
}
}
impl<'src> From<CstValue<'src>> for Ast {
fn from (value: CstValue<'src>) -> Self {
Self(match value {
DslValue::Nil => DslValue::Nil,
DslValue::Err(e) => DslValue::Err(e),
DslValue::Num(u) => DslValue::Num(u),
DslValue::Sym(s) => DslValue::Sym(s.into()),
DslValue::Key(s) => DslValue::Key(s.into()),
DslValue::Str(s) => DslValue::Str(s.into()),
DslValue::Exp(d, x) => DslValue::Exp(d, x.map(|x|x.into()).collect()),
})
}
}