From dbfb3d2ced91e56314dfabbb4df9a338926c0a7a Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 3 Aug 2020 16:01:23 +0200 Subject: =?UTF-8?q?Formatting,=20documentation=20and=20small=20improvement?= =?UTF-8?q?s=20=F0=9F=A7=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/library/mod.rs | 50 ++++++++++++++++---------------------------------- 1 file changed, 16 insertions(+), 34 deletions(-) (limited to 'src/library/mod.rs') diff --git a/src/library/mod.rs b/src/library/mod.rs index 7240e42b..0f61b901 100644 --- a/src/library/mod.rs +++ b/src/library/mod.rs @@ -1,16 +1,19 @@ //! The standard library. +mod font; +mod layout; +mod page; +mod spacing; + +pub use font::*; +pub use layout::*; +pub use page::*; +pub use spacing::*; + use crate::func::prelude::*; -use crate::layout::{LayoutContext, Commands}; use crate::syntax::scope::Scope; -macro_rules! lib { ($name:ident) => { mod $name; pub use $name::*; }} -lib!(font); -lib!(layout); -lib!(page); -lib!(spacing); - -/// Create a scope with all standard functions. +/// Create a scope with all standard library functions. pub fn std() -> Scope { let mut std = Scope::new::(); @@ -28,7 +31,10 @@ pub fn std() -> Scope { } function! { - /// `val`: Layouts the body with no special effect. + /// `val`: Ignores all arguments and layouts the body flatly. + /// + /// This is also the fallback function, which is used when a function name + /// could not be resolved. #[derive(Debug, Clone, PartialEq)] pub struct ValFunc { body: Option, @@ -37,7 +43,7 @@ function! { parse(header, body, state, f) { header.args.pos.0.clear(); header.args.key.0.clear(); - ValFunc { body: parse_maybe_body(body, state, f), } + Self { body: parse_maybe_body(body, state, f), } } layout(self, ctx, f) { @@ -47,27 +53,3 @@ function! { } } } - -/// Layout an optional body with a change of the text style. -fn styled<'a, T, F>( - body: &'a Option, - ctx: LayoutContext<'_>, - data: Option, - f: F, -) -> Commands<'a> where F: FnOnce(&mut TextStyle, T) { - if let Some(data) = data { - let mut style = ctx.style.text.clone(); - f(&mut style, data); - - match body { - Some(tree) => vec![ - SetTextStyle(style), - LayoutSyntaxTree(tree), - SetTextStyle(ctx.style.text.clone()), - ], - None => vec![SetTextStyle(style)], - } - } else { - vec![] - } -} -- cgit v1.2.3