mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-07 12:16:44 +01:00
AstToken -> Ast <- AstValue
This commit is contained in:
parent
f77139c8fd
commit
e9d4c7e0bc
5 changed files with 30 additions and 40 deletions
|
|
@ -2,15 +2,21 @@ use crate::*;
|
|||
use std::sync::Arc;
|
||||
use std::borrow::Cow;
|
||||
|
||||
/// Owns its values, and has no metadata.
|
||||
#[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>, Vec<AstToken>>;
|
||||
impl<'source> From<CstValue<'source>> for AstValue {
|
||||
pub struct AstIter;
|
||||
impl<'source> From<SourceIter<'source>> for AstIter {
|
||||
fn from (source: SourceIter<'source>) -> Self {
|
||||
Self // TODO
|
||||
}
|
||||
}
|
||||
/// Owns its values, and has no metadata.
|
||||
pub type Ast = Value<Arc<str>, AstIter>;
|
||||
impl<'source> From<CstToken<'source>> for Ast {
|
||||
fn from (token: CstToken<'source>) -> Self {
|
||||
token.value().into()
|
||||
}
|
||||
}
|
||||
impl<'source> From<CstValue<'source>> for Ast {
|
||||
fn from (value: CstValue<'source>) -> Self {
|
||||
use Value::*;
|
||||
match value {
|
||||
|
|
@ -24,11 +30,3 @@ impl<'source> From<CstValue<'source>> for AstValue {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
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())
|
||||
//}
|
||||
//}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::*;
|
||||
use std::fmt::{Debug, Display, Formatter, Error as FormatError};
|
||||
impl Display for AstValue {
|
||||
impl Display for Ast {
|
||||
fn fmt (&self, out: &mut Formatter) -> Result<(), FormatError> {
|
||||
use Value::*;
|
||||
write!(out, "{}", match self {
|
||||
|
|
|
|||
|
|
@ -43,18 +43,12 @@ impl<'source> Into<Vec<CstToken<'source>>> for SourceIter<'source> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'source> Into<Vec<AstToken>> for SourceIter<'source> {
|
||||
fn into (self) -> Vec<AstToken> {
|
||||
impl<'source> Into<Vec<Ast>> for SourceIter<'source> {
|
||||
fn into (self) -> Vec<Ast> {
|
||||
self.map(Into::into).collect()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'source> From<CstToken<'source>> for AstToken {
|
||||
fn from (value: CstToken<'source>) -> Self {
|
||||
Self(value.0.into(), AstMeta)
|
||||
}
|
||||
}
|
||||
|
||||
/// Implement the const iterator pattern.
|
||||
#[macro_export] macro_rules! const_iter {
|
||||
($(<$l:lifetime>)?|$self:ident: $Struct:ty| => $Item:ty => $expr:expr) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue