This commit is contained in:
🪞👃🪞 2025-05-26 23:21:38 +03:00
parent d6e8be6ce5
commit f77139c8fd
5 changed files with 68 additions and 59 deletions

View file

@ -3,12 +3,13 @@ use std::sync::Arc;
use std::borrow::Cow;
/// Owns its values, and has no metadata.
pub type AstToken = Token<AstValue, AstMeta>;
#[derive(PartialEq, Clone, Default, Debug)]
pub struct AstToken(pub AstValue, pub AstMeta);
#[derive(Debug, Copy, Clone, Default, PartialEq)]
pub struct AstMeta;
pub type AstValue = Value<Arc<str>, AstExp>;
pub type AstValue = Value<Arc<str>, Vec<AstToken>>;
impl<'source> From<CstValue<'source>> for AstValue {
fn from (value: CstValue<'source>) -> Self {
use Value::*;
@ -19,18 +20,15 @@ impl<'source> From<CstValue<'source>> for AstValue {
Sym(s) => Sym(s.into()),
Key(s) => Key(s.into()),
Str(s) => Str(s.into()),
Exp(x) => Exp(x.into()),
Exp(d, x) => Exp(d, x.into()),
}
}
}
#[derive(Clone, Default, PartialEq)]
pub struct AstExp(pub Vec<AstToken>);
impl<'source> From<CstExp<'source>> for AstExp {
fn from (exp: CstExp<'source>) -> AstExp {
AstExp(exp.words.map(|token|Token(
AstValue::from(token.value()),
AstMeta,
)).collect())
}
}
pub trait AstIter: DslIter<Token = AstToken> {}
//impl<'source> From<CstExp<'source>> for AstExp {
//fn from (exp: CstExp<'source>) -> AstExp {
//AstExp(exp.words.map(|token|Token(AstValue::from(token.value()), AstMeta,)).collect())
//}
//}