From d2e220245d9c17a0ac8c3474984924f65ed6b835 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 7 Oct 2020 18:24:47 +0200 Subject: =?UTF-8?q?Move=20deco,=20pass=20and=20feedback=20into=20diagnosti?= =?UTF-8?q?cs=20module=20=E2=86=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib.rs | 80 ++------------------------------------------------------------ 1 file changed, 2 insertions(+), 78 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 6380b929..22e3b988 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,11 +28,8 @@ //! [export]: export/index.html //! [_PDF_]: export/pdf/index.html -#![allow(unused)] - #[macro_use] pub mod diag; - pub mod color; pub mod eval; pub mod export; @@ -47,17 +44,12 @@ pub mod prelude; pub mod shaping; pub mod syntax; -use std::fmt::Debug; -use std::future::Future; -use std::pin::Pin; - -use crate::diag::Diag; +use crate::diag::{Feedback, Pass}; use crate::eval::State; use crate::font::SharedFontLoader; use crate::layout::BoxLayout; -use crate::syntax::{Deco, Offset, Pos, SpanVec}; -/// Process source code directly into a collection of layouts. +/// Process _Typst_ source code directly into a collection of layouts. pub async fn typeset( src: &str, state: State, @@ -68,71 +60,3 @@ pub async fn typeset( let layouts = layout::layout(&document, loader).await; Pass::new(layouts, Feedback::join(f1, f2)) } - -/// A dynamic future type which allows recursive invocation of async functions -/// when used as the return type. -pub type DynFuture<'a, T> = Pin + 'a>>; - -/// The result of some pass: Some output `T` and feedback data. -#[derive(Debug, Clone, Eq, PartialEq)] -pub struct Pass { - /// The output of this compilation pass. - pub output: T, - /// User feedback data accumulated in this pass. - pub feedback: Feedback, -} - -impl Pass { - /// Create a new pass from output and feedback data. - pub fn new(output: T, feedback: Feedback) -> Self { - Self { output, feedback } - } - - /// Create a new pass with empty feedback. - pub fn okay(output: T) -> Self { - Self { output, feedback: Feedback::new() } - } - - /// Map the output type and keep the feedback data. - pub fn map(self, f: impl FnOnce(T) -> U) -> Pass { - Pass { - output: f(self.output), - feedback: self.feedback, - } - } -} - -/// Diagnostic and semantic syntax highlighting data. -#[derive(Debug, Default, Clone, Eq, PartialEq)] -pub struct Feedback { - /// Diagnostics about the source code. - pub diags: SpanVec, - /// Decorations of the source code for semantic syntax highlighting. - pub decos: SpanVec, -} - -impl Feedback { - /// Create a new feedback instance without errors and decos. - pub fn new() -> Self { - Self { diags: vec![], decos: vec![] } - } - - /// Merge two feedbacks into one. - pub fn join(mut a: Self, b: Self) -> Self { - a.extend(b); - a - } - - /// Add other feedback data to this feedback. - pub fn extend(&mut self, more: Self) { - self.diags.extend(more.diags); - self.decos.extend(more.decos); - } - - /// Add more feedback whose spans are local and need to be translated by an - /// `offset` to be correct in this feedback's context. - pub fn extend_offset(&mut self, more: Self, offset: Pos) { - self.diags.extend(more.diags.offset(offset)); - self.decos.extend(more.decos.offset(offset)); - } -} -- cgit v1.2.3