From 0a087cd28bbee5fcdffbb9d49b0ba9f413ad7f92 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Fri, 24 Jan 2020 16:23:57 +0100 Subject: =?UTF-8?q?Reorganize=20modules=20=F0=9F=A7=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/syntax/mod.rs | 119 +++++++++++++++++++++++++----------------------------- 1 file changed, 54 insertions(+), 65 deletions(-) (limited to 'src/syntax/mod.rs') diff --git a/src/syntax/mod.rs b/src/syntax/mod.rs index 356535ae..d5afbca6 100644 --- a/src/syntax/mod.rs +++ b/src/syntax/mod.rs @@ -1,77 +1,25 @@ //! Tokenization and parsing of source code. use std::any::Any; -use std::fmt::{self, Debug, Display, Formatter}; -use std::future::Future; -use std::pin::Pin; +use std::fmt::Debug; +use async_trait::async_trait; use serde::Serialize; -use crate::error::{Error, Errors}; -use crate::func::{Commands, Command}; -use crate::layout::{Layouted, LayoutContext}; -use crate::size::Size; +use crate::layout::{LayoutContext, Layouted, Commands, Command}; +use self::span::{Spanned, SpanVec}; -pub_use_mod!(expr); -pub_use_mod!(func); -pub_use_mod!(tokens); -pub_use_mod!(parsing); -pub_use_mod!(span); +pub mod expr; +pub mod func; +pub mod span; -/// Common syntax types. -pub mod prelude { - pub use super::*; -} +pub_use_mod!(scope); +pub_use_mod!(parsing); +pub_use_mod!(tokens); -#[async_trait::async_trait(?Send)] +#[async_trait(?Send)] pub trait Model: Debug + ModelBounds { - async fn layout<'a>( - &'a self, - ctx: LayoutContext<'_, '_> - ) -> Layouted>; -} - -pub type DynFuture<'a, T> = Pin + 'a>>; - -impl dyn Model { - pub fn downcast(&self) -> Option<&T> where T: Model + 'static { - self.as_any().downcast_ref::() - } -} - -impl PartialEq for dyn Model { - fn eq(&self, other: &dyn Model) -> bool { - self.bound_eq(other) - } -} - -impl Clone for Box { - fn clone(&self) -> Self { - self.bound_clone() - } -} - -pub trait ModelBounds { - fn as_any(&self) -> &dyn Any; - fn bound_eq(&self, other: &dyn Model) -> bool; - fn bound_clone(&self) -> Box; -} - -impl ModelBounds for T where T: Model + PartialEq + Clone + 'static { - fn as_any(&self) -> &dyn Any { - self - } - - fn bound_eq(&self, other: &dyn Model) -> bool { - match other.as_any().downcast_ref::() { - Some(other) => self == other, - None => false, - } - } - - fn bound_clone(&self) -> Box { - Box::new(self.clone()) - } + async fn layout<'a>(&'a self, ctx: LayoutContext<'_, '_>) -> Layouted>; } /// A tree representation of source code. @@ -92,7 +40,7 @@ impl SyntaxModel { } } -#[async_trait::async_trait(?Send)] +#[async_trait(?Send)] impl Model for SyntaxModel { async fn layout<'a>(&'a self, _: LayoutContext<'_, '_>) -> Layouted> { Layouted { @@ -144,3 +92,44 @@ pub enum Decoration { InvalidFuncName, ArgumentKey, } + +impl dyn Model { + pub fn downcast(&self) -> Option<&T> where T: Model + 'static { + self.as_any().downcast_ref::() + } +} + +impl PartialEq for dyn Model { + fn eq(&self, other: &dyn Model) -> bool { + self.bound_eq(other) + } +} + +impl Clone for Box { + fn clone(&self) -> Self { + self.bound_clone() + } +} + +pub trait ModelBounds { + fn as_any(&self) -> &dyn Any; + fn bound_eq(&self, other: &dyn Model) -> bool; + fn bound_clone(&self) -> Box; +} + +impl ModelBounds for T where T: Model + PartialEq + Clone + 'static { + fn as_any(&self) -> &dyn Any { + self + } + + fn bound_eq(&self, other: &dyn Model) -> bool { + match other.as_any().downcast_ref::() { + Some(other) => self == other, + None => false, + } + } + + fn bound_clone(&self) -> Box { + Box::new(self.clone()) + } +} -- cgit v1.2.3