mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-07 04:06:48 +01:00
31 lines
1,004 B
Rust
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()),
|
|
})
|
|
}
|
|
}
|