mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 03:36:42 +01:00
wip: dsl: continuing to offload to Ast
This commit is contained in:
parent
e9d4c7e0bc
commit
08a8dff93d
4 changed files with 19 additions and 20 deletions
|
|
@ -1,16 +1,8 @@
|
|||
use crate::*;
|
||||
use std::sync::Arc;
|
||||
use std::borrow::Cow;
|
||||
|
||||
#[derive(Debug, Copy, Clone, Default, PartialEq)]
|
||||
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>;
|
||||
#[derive(Debug, Clone, Default, PartialEq)]
|
||||
pub struct Ast(pub Value<Arc<str>, AstIter>);
|
||||
impl<'source> From<CstToken<'source>> for Ast {
|
||||
fn from (token: CstToken<'source>) -> Self {
|
||||
token.value().into()
|
||||
|
|
@ -19,7 +11,7 @@ impl<'source> From<CstToken<'source>> for Ast {
|
|||
impl<'source> From<CstValue<'source>> for Ast {
|
||||
fn from (value: CstValue<'source>) -> Self {
|
||||
use Value::*;
|
||||
match value {
|
||||
Self(match value {
|
||||
Nil => Nil,
|
||||
Err(e) => Err(e),
|
||||
Num(u) => Num(u),
|
||||
|
|
@ -27,6 +19,14 @@ impl<'source> From<CstValue<'source>> for Ast {
|
|||
Key(s) => Key(s.into()),
|
||||
Str(s) => Str(s.into()),
|
||||
Exp(d, x) => Exp(d, x.into()),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Default, PartialEq)]
|
||||
pub struct AstIter; // TODO
|
||||
impl<'source> From<SourceIter<'source>> for AstIter {
|
||||
fn from (source: SourceIter<'source>) -> Self {
|
||||
Self // TODO
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
use crate::*;
|
||||
|
||||
/// Keeps the reference to the source slice.
|
||||
/// CST stores strings as source references and expressions as new [SourceIter] instances.
|
||||
pub type CstValue<'source> = Value<&'source str, SourceIter<'source>>;
|
||||
/// Token sharing memory with source reference.
|
||||
#[derive(Debug, Copy, Clone, Default, PartialEq)]
|
||||
pub struct CstToken<'source>(pub CstValue<'source>, pub CstMeta<'source>);
|
||||
|
||||
/// Reference to the source slice.
|
||||
#[derive(Debug, Copy, Clone, Default, PartialEq)] pub struct CstMeta<'source> {
|
||||
pub source: &'source str,
|
||||
pub start: usize,
|
||||
pub length: usize,
|
||||
}
|
||||
|
||||
pub type CstValue<'source> = Value<&'source str, SourceIter<'source>>;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use std::fmt::{Debug, Display, Formatter, Error as FormatError};
|
|||
impl Display for Ast {
|
||||
fn fmt (&self, out: &mut Formatter) -> Result<(), FormatError> {
|
||||
use Value::*;
|
||||
write!(out, "{}", match self {
|
||||
write!(out, "{}", match &self.0 {
|
||||
Nil => String::new(),
|
||||
Err(e) => format!("[error: {e}]"),
|
||||
Num(n) => format!("{n}"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue