From ecf0ff4d054f11c79ec0ddbbdf45f3dfcf9fc8d7 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 23 Oct 2019 00:14:43 +0200 Subject: =?UTF-8?q?Introduce=20a=20set=20of=20macros=20for=20writing=20fun?= =?UTF-8?q?ctions=20more=20concisely=20=F0=9F=8E=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/library/boxed.rs | 51 --------------------------------------------------- 1 file changed, 51 deletions(-) delete mode 100644 src/library/boxed.rs (limited to 'src/library/boxed.rs') diff --git a/src/library/boxed.rs b/src/library/boxed.rs deleted file mode 100644 index 71a184a6..00000000 --- a/src/library/boxed.rs +++ /dev/null @@ -1,51 +0,0 @@ -use super::prelude::*; -use crate::layout::Flow; - -/// Wraps content into a box. -#[derive(Debug, PartialEq)] -pub struct BoxFunc { - body: SyntaxTree, - flow: Flow, -} - -impl Function for BoxFunc { - fn parse(header: &FuncHeader, body: Option<&str>, ctx: ParseContext) -> ParseResult - where Self: Sized { - let flow = if header.args.is_empty() { - Flow::Vertical - } else if header.args.len() == 1 { - if let Expression::Ident(ident) = &header.args[0] { - match ident.as_str() { - "vertical" => Flow::Vertical, - "horizontal" => Flow::Horizontal, - f => return err(format!("invalid flow specifier: '{}'", f)), - } - } else { - return err(format!( - "expected alignment specifier, found: '{}'", - header.args[0] - )); - } - } else { - return err("box: expected flow specifier or no arguments"); - }; - - if let Some(body) = body { - Ok(BoxFunc { - body: parse(body, ctx)?, - flow, - }) - } else { - err("box: expected body") - } - } - - fn layout(&self, ctx: LayoutContext) -> LayoutResult { - let layout = layout_tree(&self.body, LayoutContext { - flow: self.flow, - .. ctx - })?; - - Ok(commands![Command::AddMany(layout)]) - } -} -- cgit v1.2.3