From 266d457292e7461d448f9141030028ea68b573d1 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sun, 2 Aug 2020 22:05:49 +0200 Subject: =?UTF-8?q?Refactor=20model=20into=20tree=20=F0=9F=9B=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib.rs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 67b94adf..5a0b8d0b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,25 +16,19 @@ //! format is [_PDF_](crate::export::pdf). use std::fmt::Debug; +use std::future::Future; +use std::pin::Pin; use crate::diagnostic::Diagnostics; use crate::font::SharedFontLoader; use crate::layout::MultiLayout; use crate::style::{LayoutStyle, PageStyle, TextStyle}; use crate::syntax::decoration::Decorations; -use crate::syntax::model::SyntaxModel; +use crate::syntax::tree::SyntaxTree; use crate::syntax::parsing::{parse, ParseState}; use crate::syntax::scope::Scope; use crate::syntax::span::{Offset, Pos}; -/// Declare a module and reexport all its contents. -macro_rules! pub_use_mod { - ($name:ident) => { - mod $name; - pub use $name::*; - }; -} - #[macro_use] mod macros; #[macro_use] @@ -84,23 +78,24 @@ impl Typesetter { } /// Parse source code into a syntax tree. - pub fn parse(&self, src: &str) -> Pass { + pub fn parse(&self, src: &str) -> Pass { parse(src, Pos::ZERO, &self.parse_state) } /// Layout a syntax tree and return the produced layout. - pub async fn layout(&self, model: &SyntaxModel) -> Pass { + pub async fn layout(&self, tree: &SyntaxTree) -> Pass { use crate::layout::prelude::*; + use crate::layout::{LayoutContext, LayoutSpace}; let margins = self.style.page.margins(); - crate::layout::layout( - &model, + layout( + &tree, LayoutContext { loader: &self.loader, style: &self.style, - base: self.style.page.dimensions.unpadded(margins), + base: self.style.page.size.unpadded(margins), spaces: vec![LayoutSpace { - dimensions: self.style.page.dimensions, + size: self.style.page.size, padding: margins, expansion: LayoutExpansion::new(true, true), }], @@ -121,6 +116,11 @@ impl Typesetter { } } +/// A dynamic future type which allows recursive invocation of async functions +/// when used as the return type. This is also how the async trait functions +/// work internally. +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 { -- cgit v1.2.3