From 78da2bdd5d77d1b8572e5e9da119bfa68127a3fa Mon Sep 17 00:00:00 2001 From: Laurenz Date: Tue, 21 Jan 2020 17:09:31 +0100 Subject: =?UTF-8?q?Decoupled=20function=20parser=20=F0=9F=94=97=20[WIP]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/func/mod.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/func/mod.rs') diff --git a/src/func/mod.rs b/src/func/mod.rs index 1ca226c3..e3399903 100644 --- a/src/func/mod.rs +++ b/src/func/mod.rs @@ -1,6 +1,5 @@ //! Dynamic typesetting functions. -use std::any::Any; use std::collections::HashMap; use std::fmt::{self, Debug, Formatter}; @@ -12,6 +11,7 @@ mod macros; /// Useful imports for creating your own functions. pub mod prelude { pub use super::{Scope, Parse, Command, Commands}; + pub use crate::error::Error; pub use crate::layout::prelude::*; pub use crate::syntax::prelude::*; pub use crate::size::{Size, Size2D, SizeBox, ValueBox, ScaleSize, FSize, PSize}; @@ -26,7 +26,7 @@ pub trait Parse { /// Parse the header and body into this function given a context. fn parse( header: FuncHeader, - body: Option>, + body: Option<(Position, &str)>, ctx: ParseContext, metadata: Self::Meta, ) -> Parsed where Self: Sized; @@ -36,7 +36,7 @@ pub trait Parse { /// implements [`Model`]. type Parser = dyn Fn( FuncHeader, - Option>, + Option<(Position, &str)>, ParseContext, ) -> Parsed>; @@ -102,11 +102,16 @@ impl Scope { } /// Return the parser with the given name if there is one. - pub(crate) fn get_parser(&self, name: &str) -> Result<&Parser, &Parser> { + pub fn get_parser(&self, name: &str) -> Result<&Parser, &Parser> { self.parsers.get(name) .map(|x| &**x) .ok_or_else(|| &*self.fallback) } + + /// Return the fallback parser. + pub fn get_fallback_parser(&self) -> &Parser { + &*self.fallback + } } impl Debug for Scope { -- cgit v1.2.3