diff options
Diffstat (limited to 'src/library')
| -rw-r--r-- | src/library/align.rs | 10 | ||||
| -rw-r--r-- | src/library/boxed.rs | 8 | ||||
| -rw-r--r-- | src/library/font.rs | 42 | ||||
| -rw-r--r-- | src/library/page.rs | 22 | ||||
| -rw-r--r-- | src/library/spacing.rs | 4 | ||||
| -rw-r--r-- | src/library/val.rs | 2 |
6 files changed, 41 insertions, 47 deletions
diff --git a/src/library/align.rs b/src/library/align.rs index 115793b1..b4cfd2e2 100644 --- a/src/library/align.rs +++ b/src/library/align.rs @@ -14,12 +14,12 @@ pub fn align(call: FuncCall, _: &ParseState) -> Pass<SyntaxNode> { let mut f = Feedback::new(); let mut args = call.args; let node = AlignNode { - content: args.pos.get::<SyntaxTree>(), - aligns: args.pos.all::<Spanned<SpecAlign>>().collect(), - h: args.key.get::<Spanned<SpecAlign>>("horizontal", &mut f), - v: args.key.get::<Spanned<SpecAlign>>("vertical", &mut f), + content: args.take::<SyntaxTree>(), + aligns: args.take_all_num_vals::<Spanned<SpecAlign>>().collect(), + h: args.take_with_key::<_, Spanned<SpecAlign>>("horizontal", &mut f), + v: args.take_with_key::<_, Spanned<SpecAlign>>("vertical", &mut f), }; - drain_args(args, &mut f); + args.unexpected(&mut f); Pass::node(node, f) } diff --git a/src/library/boxed.rs b/src/library/boxed.rs index 3ca3ae44..3637f072 100644 --- a/src/library/boxed.rs +++ b/src/library/boxed.rs @@ -10,11 +10,11 @@ pub fn boxed(call: FuncCall, _: &ParseState) -> Pass<SyntaxNode> { let mut f = Feedback::new(); let mut args = call.args; let node = BoxNode { - content: args.pos.get::<SyntaxTree>().unwrap_or(SyntaxTree::new()), - width: args.key.get::<ScaleLength>("width", &mut f), - height: args.key.get::<ScaleLength>("height", &mut f), + content: args.take::<SyntaxTree>().unwrap_or(SyntaxTree::new()), + width: args.take_with_key::<_, ScaleLength>("width", &mut f), + height: args.take_with_key::<_, ScaleLength>("height", &mut f), }; - drain_args(args, &mut f); + args.unexpected(&mut f); Pass::node(node, f) } diff --git a/src/library/font.rs b/src/library/font.rs index d445a246..8787cc91 100644 --- a/src/library/font.rs +++ b/src/library/font.rs @@ -13,7 +13,7 @@ use super::*; /// - `style`: `normal`, `italic` or `oblique`. /// - `weight`: `100` - `900` or a name like `thin`. /// - `width`: `1` - `9` or a name like `condensed`. -/// - Any other keyword argument whose value is a tuple of strings is a class +/// - Any other keyword argument whose value is a table of strings is a class /// fallback definition like: /// ```typst /// serif = ("Source Serif Pro", "Noto Serif") @@ -23,31 +23,25 @@ pub fn font(call: FuncCall, _: &ParseState) -> Pass<SyntaxNode> { let mut args = call.args; let node = FontNode { - content: args.pos.get::<SyntaxTree>(), - size: args.pos.get::<ScaleLength>(), - style: args.key.get::<FontStyle>("style", &mut f), - weight: args.key.get::<FontWeight>("weight", &mut f), - width: args.key.get::<FontWidth>("width", &mut f), - list: { - args.pos.all::<StringLike>() - .map(|s| s.0.to_lowercase()) - .collect() - }, - classes: { - args.key.all::<Tuple>() - .collect::<Vec<_>>() - .into_iter() - .map(|(class, mut tuple)| { - let fallback = tuple.all::<StringLike>() - .map(|s| s.0.to_lowercase()) - .collect(); - (class.v.0, fallback) - }) - .collect() - }, + content: args.take::<SyntaxTree>(), + size: args.take::<ScaleLength>(), + style: args.take_with_key::<_, FontStyle>("style", &mut f), + weight: args.take_with_key::<_, FontWeight>("weight", &mut f), + width: args.take_with_key::<_, FontWidth>("width", &mut f), + list: args.take_all_num_vals::<StringLike>() + .map(|s| s.0.to_lowercase()) + .collect(), + classes: args.take_all_str::<TableExpr>() + .map(|(class, mut table)| { + let fallback = table.take_all_num_vals::<StringLike>() + .map(|s| s.0.to_lowercase()) + .collect(); + (class, fallback) + }) + .collect() }; - drain_args(args, &mut f); + args.unexpected(&mut f); Pass::node(node, f) } diff --git a/src/library/page.rs b/src/library/page.rs index b47749ea..7e4e6e54 100644 --- a/src/library/page.rs +++ b/src/library/page.rs @@ -20,17 +20,17 @@ pub fn page(call: FuncCall, _: &ParseState) -> Pass<SyntaxNode> { let mut f = Feedback::new(); let mut args = call.args; let node = PageNode { - paper: args.pos.get::<Paper>(), - width: args.key.get::<Length>("width", &mut f), - height: args.key.get::<Length>("height", &mut f), - margins: args.key.get::<ScaleLength>("margins", &mut f), - left: args.key.get::<ScaleLength>("left", &mut f), - right: args.key.get::<ScaleLength>("right", &mut f), - top: args.key.get::<ScaleLength>("top", &mut f), - bottom: args.key.get::<ScaleLength>("bottom", &mut f), - flip: args.key.get::<bool>("flip", &mut f).unwrap_or(false), + paper: args.take::<Paper>(), + width: args.take_with_key::<_, Length>("width", &mut f), + height: args.take_with_key::<_, Length>("height", &mut f), + margins: args.take_with_key::<_, ScaleLength>("margins", &mut f), + left: args.take_with_key::<_, ScaleLength>("left", &mut f), + right: args.take_with_key::<_, ScaleLength>("right", &mut f), + top: args.take_with_key::<_, ScaleLength>("top", &mut f), + bottom: args.take_with_key::<_, ScaleLength>("bottom", &mut f), + flip: args.take_with_key::<_, bool>("flip", &mut f).unwrap_or(false), }; - drain_args(args, &mut f); + args.unexpected(&mut f); Pass::node(node, f) } @@ -78,7 +78,7 @@ impl Layout for PageNode { /// `pagebreak`: Ends the current page. pub fn pagebreak(call: FuncCall, _: &ParseState) -> Pass<SyntaxNode> { let mut f = Feedback::new(); - drain_args(call.args, &mut f); + call.args.unexpected(&mut f); Pass::node(PageBreakNode, f) } diff --git a/src/library/spacing.rs b/src/library/spacing.rs index ad30a122..81112cbd 100644 --- a/src/library/spacing.rs +++ b/src/library/spacing.rs @@ -22,11 +22,11 @@ fn spacing(call: FuncCall, axis: SpecAxis) -> Pass<SyntaxNode> { let mut f = Feedback::new(); let mut args = call.args; let node = SpacingNode { - spacing: args.pos.expect::<ScaleLength>(&mut f) + spacing: args.expect::<ScaleLength>(&mut f) .map(|s| (axis, s)) .or_missing(call.name.span, "spacing", &mut f), }; - drain_args(args, &mut f); + args.unexpected(&mut f); Pass::node(node, f) } diff --git a/src/library/val.rs b/src/library/val.rs index 6e83571a..9df55401 100644 --- a/src/library/val.rs +++ b/src/library/val.rs @@ -7,7 +7,7 @@ use super::*; pub fn val(call: FuncCall, _: &ParseState) -> Pass<SyntaxNode> { let mut args = call.args; let node = ValNode { - content: args.pos.get::<SyntaxTree>(), + content: args.take::<SyntaxTree>(), }; Pass::node(node, Feedback::new()) } |
