diff options
Diffstat (limited to 'src/func')
| -rw-r--r-- | src/func/macros.rs | 41 | ||||
| -rw-r--r-- | src/func/mod.rs | 11 |
2 files changed, 22 insertions, 30 deletions
diff --git a/src/func/macros.rs b/src/func/macros.rs index 1083e53c..90c3b11e 100644 --- a/src/func/macros.rs +++ b/src/func/macros.rs @@ -52,46 +52,43 @@ macro_rules! function { }; // (1-arg) Parse a parse-definition with only the first argument. - (@parse $type:ident $meta:ty | parse($args:ident) $code:block $($rest:tt)*) => { - function!(@parse $type $meta | parse($args, _body, _ctx, _meta) $code $($rest)*); + (@parse $type:ident $meta:ty | parse($header:ident) $code:block $($rest:tt)*) => { + function!(@parse $type $meta | parse($header, _body, _ctx, _meta) $code $($rest)*); }; // (2-arg) Parse a parse-definition with only the first two arguments. (@parse $type:ident $meta:ty | - parse($args:ident, $body:pat) $code:block $($rest:tt)* + parse($header:ident, $body:pat) $code:block $($rest:tt)* ) => { - function!(@parse $type $meta | parse($args, $body, _ctx, _meta) $code $($rest)*); + function!(@parse $type $meta | parse($header, $body, _ctx, _meta) $code $($rest)*); }; // (3-arg) Parse a parse-definition with only the first three arguments. (@parse $type:ident $meta:ty | - parse($args:ident, $body:pat, $ctx:pat) $code:block $($rest:tt)* + parse($header:ident, $body:pat, $ctx:pat) $code:block $($rest:tt)* ) => { - function!(@parse $type $meta | parse($args, $body, $ctx, _meta) $code $($rest)*); + function!(@parse $type $meta | parse($header, $body, $ctx, _meta) $code $($rest)*); }; // (4-arg) Parse a parse-definition with all four arguments. (@parse $type:ident $meta:ty | - parse($args:ident, $body:pat, $ctx:pat, $metadata:pat) $code:block + parse($header:ident, $body:pat, $ctx:pat, $metadata:pat) $code:block $($rest:tt)* ) => { - use $crate::func::prelude::*; - impl $crate::func::ParseFunc for $type { type Meta = $meta; fn parse( - args: FuncArgs, + header: $crate::syntax::FuncHeader, $body: Option<&str>, - $ctx: ParseContext, + $ctx: $crate::syntax::ParseContext, $metadata: Self::Meta, - ) -> ParseResult<Self> where Self: Sized { + ) -> $crate::syntax::ParseResult<Self> where Self: Sized { #[allow(unused_mut)] - let mut $args = args; + let mut $header = header; let val = $code; - if !$args.is_empty() { - return Err($crate::TypesetError - ::with_message("unexpected arguments")); + if !$header.args.is_empty() { + return Err($crate::TypesetError::with_message("unexpected arguments")); } Ok(val) } @@ -112,14 +109,14 @@ macro_rules! function { // (2-arg) Parse a layout-definition with all arguments. (@layout $type:ident | layout($this:ident, $ctx:pat) $code:block) => { - use $crate::func::prelude::*; - - impl LayoutFunc for $type { + impl $crate::func::LayoutFunc for $type { fn layout<'a, 'life0, 'life1, 'async_trait>( &'a $this, - $ctx: LayoutContext<'life0, 'life1> - ) -> std::pin::Pin<Box< - dyn std::future::Future<Output = LayoutResult<Commands<'a>>> + 'async_trait + $ctx: $crate::layout::LayoutContext<'life0, 'life1> + ) -> std::pin::Pin<Box<dyn std::future::Future< + Output = $crate::layout::LayoutResult< + $crate::func::Commands<'a>> + > + 'async_trait >> where 'a: 'async_trait, diff --git a/src/func/mod.rs b/src/func/mod.rs index 90b2a31d..bfc2774c 100644 --- a/src/func/mod.rs +++ b/src/func/mod.rs @@ -14,12 +14,7 @@ mod macros; pub mod prelude { pub use crate::func::{Scope, ParseFunc, LayoutFunc, Command, Commands}; pub use crate::layout::prelude::*; - pub use crate::syntax::{ - ParseContext, ParseResult, - SyntaxTree, FuncCall, FuncArgs, - Expression, Ident, ExpressionKind, - Spanned, Span - }; + pub use crate::syntax::*; pub use crate::size::{Size, Size2D, SizeBox, ValueBox, ScaleSize, FSize, PSize}; pub use crate::style::{LayoutStyle, PageStyle, TextStyle}; pub use Command::*; @@ -31,7 +26,7 @@ pub trait ParseFunc { /// Parse the header and body into this function given a context. fn parse( - args: FuncArgs, + header: FuncHeader, body: Option<&str>, ctx: ParseContext, metadata: Self::Meta, @@ -125,7 +120,7 @@ pub struct Scope { /// A function which parses the source of a function into a function type which /// implements [`LayoutFunc`]. type Parser = dyn Fn( - FuncArgs, + FuncHeader, Option<&str>, ParseContext ) -> ParseResult<Box<dyn LayoutFunc>>; |
