mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-08 04:36:49 +01:00
parent
c8827b43c3
commit
91dc77cfea
16 changed files with 931 additions and 823 deletions
31
dsl/src/ast.rs
Normal file
31
dsl/src/ast.rs
Normal 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()),
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue