tengri/dsl/src/ast.rs
unspeaker 91dc77cfea
Some checks failed
/ build (push) Has been cancelled
wip: refactor dsl
2025-06-18 21:32:46 +03:00

31 lines
1,004 B
Rust

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()),
})
}
}