diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-01-21 17:09:31 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-01-21 17:09:31 +0100 |
| commit | 78da2bdd5d77d1b8572e5e9da119bfa68127a3fa (patch) | |
| tree | 020c8c39268690d34226eb7e33e75f86304988d6 /src/func/mod.rs | |
| parent | 1c1c994c46f7dc30ee34dbc99b02f2342c4617f3 (diff) | |
Decoupled function parser 🔗 [WIP]
Diffstat (limited to 'src/func/mod.rs')
| -rw-r--r-- | src/func/mod.rs | 13 |
1 files changed, 9 insertions, 4 deletions
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<Spanned<&str>>, + body: Option<(Position, &str)>, ctx: ParseContext, metadata: Self::Meta, ) -> Parsed<Self> where Self: Sized; @@ -36,7 +36,7 @@ pub trait Parse { /// implements [`Model`]. type Parser = dyn Fn( FuncHeader, - Option<Spanned<&str>>, + Option<(Position, &str)>, ParseContext, ) -> Parsed<Box<dyn Model>>; @@ -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 { |
