diff --git a/dsl/src/dsl_ast.rs b/dsl/src/dsl_ast.rs index 866e15f..fca3fd6 100644 --- a/dsl/src/dsl_ast.rs +++ b/dsl/src/dsl_ast.rs @@ -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> for AstIter { - fn from (source: SourceIter<'source>) -> Self { - Self // TODO - } -} -/// Owns its values, and has no metadata. -pub type Ast = Value, AstIter>; +#[derive(Debug, Clone, Default, PartialEq)] +pub struct Ast(pub Value, AstIter>); impl<'source> From> for Ast { fn from (token: CstToken<'source>) -> Self { token.value().into() @@ -19,7 +11,7 @@ impl<'source> From> for Ast { impl<'source> From> 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> 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> for AstIter { + fn from (source: SourceIter<'source>) -> Self { + Self // TODO } } diff --git a/dsl/src/dsl_cst.rs b/dsl/src/dsl_cst.rs index 1c896b5..1af6f8f 100644 --- a/dsl/src/dsl_cst.rs +++ b/dsl/src/dsl_cst.rs @@ -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>>; diff --git a/dsl/src/dsl_display.rs b/dsl/src/dsl_display.rs index 44def5d..aaae8c7 100644 --- a/dsl/src/dsl_display.rs +++ b/dsl/src/dsl_display.rs @@ -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}"), diff --git a/input/src/input_dsl.rs b/input/src/input_dsl.rs index 6f6b24b..bff457d 100644 --- a/input/src/input_dsl.rs +++ b/input/src/input_dsl.rs @@ -23,14 +23,14 @@ impl InputLayers { self.0.push(InputLayer(condition, binding)); self } - pub fn handle > (&self, state: &mut S, input: I) -> Perhaps { + pub fn handle , I, O: Command> (&self, state: &mut S, input: I) -> Perhaps { InputHandle(state, self.0.as_slice()).try_eval(input) } } pub struct InputHandle<'a, S>(&'a mut S, &'a [InputLayer]); -impl<'a, S, I, O: Command> Eval for InputHandle<'a, S> { +impl<'a, S: Eval, I, O: Command> Eval for InputHandle<'a, S> { fn try_eval (&self, input: I) -> Perhaps { let Self(state, layers) = self; for InputLayer(condition, binding) in layers.iter() {