diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-08-03 16:01:23 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-08-03 16:04:55 +0200 |
| commit | dbfb3d2ced91e56314dfabbb4df9a338926c0a7a (patch) | |
| tree | 678264cb18f8abc81ebe28077f5aef2df4e5a4bd /src/lib.rs | |
| parent | 5a8f2fb73ddafba9fdbe952385ae2676126183ae (diff) | |
Formatting, documentation and small improvements 🧽
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 93 |
1 files changed, 49 insertions, 44 deletions
@@ -2,49 +2,54 @@ //! //! # Steps //! - **Parsing:** The parsing step first transforms a plain string into an -//! [iterator of tokens](crate::syntax::Tokens). Then, a parser constructs a -//! syntax tree from the token stream. The structures describing the tree can -//! be found in the [syntax](crate::syntax) module. +//! [iterator of tokens][tokens]. Then, a parser constructs a syntax tree from +//! the token stream. The structures describing the tree can be found in the +//! [syntax] module. //! - **Layouting:** The next step is to transform the syntax tree into a //! portable representation of the typesetted document. Types for these can be -//! found in the [layout](crate::layout) module. A finished layout reading for -//! exporting is a [MultiLayout](crate::layout::MultiLayout) consisting of -//! multiple boxes (or pages). +//! found in the [layout] module. A finished layout ready for exporting is a +//! [`MultiLayout`] consisting of multiple boxes (or pages). //! - **Exporting:** The finished layout can then be exported into a supported -//! format. Submodules for these formats are located in the -//! [export](crate::export) module. Currently, the only supported output -//! 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::tree::SyntaxTree; -use crate::syntax::parsing::{parse, ParseState}; -use crate::syntax::scope::Scope; -use crate::syntax::span::{Offset, Pos}; +//! format. Submodules for these formats are located in the [export] module. +//! Currently, the only supported output format is [_PDF_]. +//! +//! [tokens]: syntax/tokens/struct.Tokens.html +//! [syntax]: syntax/index.html +//! [layout]: layout/index.html +//! [export]: export/index.html +//! [_PDF_]: export/pdf/index.html +//! [`MultiLayout`]: layout/type.MultiLayout.html #[macro_use] mod macros; #[macro_use] pub mod diagnostic; -pub mod export; -pub mod font; #[macro_use] pub mod func; + +pub mod export; +pub mod font; pub mod geom; pub mod layout; -pub mod library; pub mod length; +pub mod library; pub mod paper; pub mod style; pub mod syntax; +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::parsing::{parse, ParseState}; +use crate::syntax::span::{Offset, Pos}; +use crate::syntax::tree::SyntaxTree; + /// Transforms source code into typesetted layouts. /// /// A typesetter can be configured through various methods. @@ -59,11 +64,11 @@ pub struct Typesetter { impl Typesetter { /// Create a new typesetter. - pub fn new(loader: SharedFontLoader) -> Typesetter { - Typesetter { + pub fn new(loader: SharedFontLoader) -> Self { + Self { loader, style: LayoutStyle::default(), - parse_state: ParseState { scope: Scope::with_std() }, + parse_state: ParseState { scope: crate::library::std() }, } } @@ -100,9 +105,9 @@ impl Typesetter { expansion: LayoutExpansion::new(true, true), }], repeat: true, - axes: LayoutAxes::new(LTT, TTB), + axes: LayoutAxes::new(LTR, TTB), align: LayoutAlign::new(Start, Start), - nested: false, + root: true, }, ).await } @@ -119,7 +124,7 @@ 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<Box<dyn Future<Output=T> + 'a>>; +pub type DynFuture<'a, T> = Pin<Box<dyn Future<Output = T> + 'a>>; /// The result of some pass: Some output `T` and feedback data. #[derive(Debug, Clone, Eq, PartialEq)] @@ -132,12 +137,12 @@ pub struct Pass<T> { impl<T> Pass<T> { /// Create a new pass from output and feedback data. - pub fn new(output: T, feedback: Feedback) -> Pass<T> { - Pass { output, feedback } + pub fn new(output: T, feedback: Feedback) -> Self { + Self { output, feedback } } /// Map the output type and keep the feedback data. - pub fn map<F, U>(self, f: F) -> Pass<U> where F: FnOnce(T) -> U { + pub fn map<U>(self, f: impl FnOnce(T) -> U) -> Pass<U> { Pass { output: f(self.output), feedback: self.feedback, @@ -145,10 +150,10 @@ impl<T> Pass<T> { } } -/// User feedback data accumulated during a compilation pass. +/// Diagnostic and semantic syntax highlighting data. #[derive(Debug, Default, Clone, Eq, PartialEq)] pub struct Feedback { - /// Diagnostics in the source code. + /// Diagnostics about the source code. pub diagnostics: Diagnostics, /// Decorations of the source code for semantic syntax highlighting. pub decorations: Decorations, @@ -156,28 +161,28 @@ pub struct Feedback { impl Feedback { /// Create a new feedback instance without errors and decos. - pub fn new() -> Feedback { - Feedback { + pub fn new() -> Self { + Self { diagnostics: vec![], decorations: vec![], } } /// Merged two feedbacks into one. - pub fn merge(mut a: Feedback, b: Feedback) -> Feedback { + pub fn merge(mut a: Self, b: Self) -> Self { a.extend(b); a } /// Add other feedback data to this feedback. - pub fn extend(&mut self, other: Feedback) { - self.diagnostics.extend(other.diagnostics); - self.decorations.extend(other.decorations); + pub fn extend(&mut self, more: Self) { + self.diagnostics.extend(more.diagnostics); + self.decorations.extend(more.decorations); } /// Add more feedback whose spans are local and need to be offset by an /// `offset` to be correct in this feedback's context. - pub fn extend_offset(&mut self, more: Feedback, offset: Pos) { + pub fn extend_offset(&mut self, more: Self, offset: Pos) { self.diagnostics.extend(more.diagnostics.offset(offset)); self.decorations.extend(more.decorations.offset(offset)); } |
