From 95e6b078fecddeaa3d6f2c920b617201b74bf01e Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sun, 19 Jan 2020 21:50:20 +0100 Subject: =?UTF-8?q?Move=20to=20non-fatal=20errors=20=F0=9F=AA=82=20[WIP]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Dynamic models instead of SyntaxTrees - No more ParseResult/LayoutResult - Errors and Decorations which are propagated to parent contexts - Models are finally clonable --- src/layout/mod.rs | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) (limited to 'src/layout/mod.rs') diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 49551945..75d34409 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -4,23 +4,20 @@ use std::io::{self, Write}; use smallvec::SmallVec; use toddle::query::{SharedFontLoader, FontIndex}; +use crate::error::Error; +use crate::syntax::SpanVec; use crate::size::{Size, Size2D, SizeBox}; use crate::style::LayoutStyle; mod actions; -mod tree; +mod model; mod line; mod stack; mod text; /// Common types for layouting. pub mod prelude { - pub use super::{ - layout, LayoutResult, - MultiLayout, Layout, LayoutContext, LayoutSpaces, LayoutSpace, - LayoutExpansion, LayoutAxes, GenericAxis, SpecificAxis, Direction, - LayoutAlignment, Alignment, SpacingKind, - }; + pub use super::*; pub use GenericAxis::*; pub use SpecificAxis::*; pub use Direction::*; @@ -29,7 +26,7 @@ pub mod prelude { /// Different kinds of layouters (fully re-exported). pub mod layouters { - pub use super::tree::layout; + pub use super::model::layout; pub use super::line::{LineLayouter, LineContext}; pub use super::stack::{StackLayouter, StackContext}; pub use super::text::{layout_text, TextContext}; @@ -40,8 +37,19 @@ pub use self::layouters::*; pub use self::prelude::*; -/// The result type for layouting. -pub type LayoutResult = crate::TypesetResult; +pub struct Layouted { + pub output: T, + pub errors: SpanVec, +} + +impl Layouted { + pub fn map(self, f: F) -> Layouted where F: FnOnce(T) -> U { + Layouted { + output: f(self.output), + errors: self.errors, + } + } +} /// A collection of layouts. pub type MultiLayout = Vec; @@ -361,14 +369,16 @@ pub enum SpacingKind { Soft(u32), } -/// The standard spacing kind used for paragraph spacing. -const PARAGRAPH_KIND: SpacingKind = SpacingKind::Soft(1); +impl SpacingKind { + /// The standard spacing kind used for paragraph spacing. + pub const PARAGRAPH: SpacingKind = SpacingKind::Soft(1); -/// The standard spacing kind used for line spacing. -const LINE_KIND: SpacingKind = SpacingKind::Soft(2); + /// The standard spacing kind used for line spacing. + pub const LINE: SpacingKind = SpacingKind::Soft(2); -/// The standard spacing kind used for word spacing. -const WORD_KIND: SpacingKind = SpacingKind::Soft(1); + /// The standard spacing kind used for word spacing. + pub const WORD: SpacingKind = SpacingKind::Soft(1); +} /// The last appeared spacing. #[derive(Debug, Copy, Clone, PartialEq)] -- cgit v1.2.3