diff --git a/src/eval/function.rs b/src/eval/function.rs index c45ac7ba4..205690dfb 100644 --- a/src/eval/function.rs +++ b/src/eval/function.rs @@ -16,13 +16,13 @@ struct Inner { func: T, } -type Func = dyn Fn(&mut EvalContext, &mut Arguments) -> TypResult; +type Func = dyn Fn(&mut EvalContext, &mut Args) -> TypResult; impl Function { /// Create a new function from a rust closure. pub fn new(name: Option, func: F) -> Self where - F: Fn(&mut EvalContext, &mut Arguments) -> TypResult + 'static, + F: Fn(&mut EvalContext, &mut Args) -> TypResult + 'static, { Self(Rc::new(Inner { name, func })) } @@ -33,7 +33,7 @@ impl Function { } /// Call the function in the context with the arguments. - pub fn call(&self, ctx: &mut EvalContext, args: &mut Arguments) -> TypResult { + pub fn call(&self, ctx: &mut EvalContext, args: &mut Args) -> TypResult { (&self.0.func)(ctx, args) } } @@ -58,16 +58,16 @@ impl PartialEq for Function { /// Evaluated arguments to a function. #[derive(Clone, PartialEq)] -pub struct Arguments { +pub struct Args { /// The span of the whole argument list. pub span: Span, /// The positional and named arguments. - pub items: Vec, + pub items: Vec, } /// An argument to a function call: `12` or `draw: false`. #[derive(Clone, PartialEq)] -pub struct Argument { +pub struct Arg { /// The span of the whole argument. pub span: Span, /// The name of the argument (`None` for positional arguments). @@ -76,7 +76,7 @@ pub struct Argument { pub value: Spanned, } -impl Arguments { +impl Args { /// Find and consume the first castable positional argument. pub fn eat(&mut self) -> Option where @@ -169,11 +169,11 @@ impl Arguments { { let mut iter = self.items.into_iter(); let value = match iter.next() { - Some(Argument { name: None, value, .. }) => value.v.cast().at(value.span)?, + Some(Arg { name: None, value, .. }) => value.v.cast().at(value.span)?, None => { bail!(self.span, "missing {}", what); } - Some(Argument { name: Some(_), span, .. }) => { + Some(Arg { name: Some(_), span, .. }) => { bail!(span, "named pair is not allowed here"); } }; @@ -186,7 +186,7 @@ impl Arguments { } } -impl Debug for Arguments { +impl Debug for Args { fn fmt(&self, f: &mut Formatter) -> fmt::Result { f.write_char('(')?; for (i, arg) in self.items.iter().enumerate() { @@ -199,7 +199,7 @@ impl Debug for Arguments { } } -impl Debug for Argument { +impl Debug for Arg { fn fmt(&self, f: &mut Formatter) -> fmt::Result { if let Some(name) = &self.name { f.write_str(name)?; @@ -210,5 +210,5 @@ impl Debug for Argument { } dynamic! { - Arguments: "arguments", + Args: "arguments", } diff --git a/src/eval/mod.rs b/src/eval/mod.rs index f48312c80..d88dd2bb8 100644 --- a/src/eval/mod.rs +++ b/src/eval/mod.rs @@ -393,7 +393,7 @@ impl Eval for CallExpr { } impl Eval for CallArgs { - type Output = Arguments; + type Output = Args; fn eval(&self, ctx: &mut EvalContext) -> TypResult { let mut items = Vec::with_capacity(self.items.len()); @@ -402,14 +402,14 @@ impl Eval for CallArgs { let span = arg.span(); match arg { CallArg::Pos(expr) => { - items.push(Argument { + items.push(Arg { span, name: None, value: Spanned::new(expr.eval(ctx)?, expr.span()), }); } CallArg::Named(Named { name, expr }) => { - items.push(Argument { + items.push(Arg { span, name: Some((&name.string).into()), value: Spanned::new(expr.eval(ctx)?, expr.span()), @@ -417,14 +417,14 @@ impl Eval for CallArgs { } CallArg::Spread(expr) => match expr.eval(ctx)? { Value::Array(array) => { - items.extend(array.into_iter().map(|value| Argument { + items.extend(array.into_iter().map(|value| Arg { span, name: None, value: Spanned::new(value, span), })); } Value::Dict(dict) => { - items.extend(dict.into_iter().map(|(key, value)| Argument { + items.extend(dict.into_iter().map(|(key, value)| Arg { span, name: Some(key), value: Spanned::new(value, span), @@ -432,7 +432,7 @@ impl Eval for CallArgs { } v => { if let Value::Dyn(dynamic) = &v { - if let Some(args) = dynamic.downcast_ref::() { + if let Some(args) = dynamic.downcast_ref::() { items.extend(args.items.iter().cloned()); continue; } @@ -444,7 +444,7 @@ impl Eval for CallArgs { } } - Ok(Arguments { span: self.span, items }) + Ok(Args { span: self.span, items }) } } diff --git a/src/eval/scope.rs b/src/eval/scope.rs index 0d7016873..eb057ae3b 100644 --- a/src/eval/scope.rs +++ b/src/eval/scope.rs @@ -4,7 +4,7 @@ use std::fmt::{self, Debug, Formatter}; use std::iter; use std::rc::Rc; -use super::{Arguments, EvalContext, Function, Value}; +use super::{Args, EvalContext, Function, Value}; use crate::diag::TypResult; use crate::util::EcoString; @@ -91,7 +91,7 @@ impl Scope { /// Define a constant function. pub fn def_func(&mut self, name: impl Into, f: F) where - F: Fn(&mut EvalContext, &mut Arguments) -> TypResult + 'static, + F: Fn(&mut EvalContext, &mut Args) -> TypResult + 'static, { let name = name.into(); self.def_const(name.clone(), Function::new(Some(name), f)); diff --git a/src/library/elements.rs b/src/library/elements.rs index 6e71626a3..75a43282d 100644 --- a/src/library/elements.rs +++ b/src/library/elements.rs @@ -10,7 +10,7 @@ use crate::layout::{ }; /// `image`: An image. -pub fn image(ctx: &mut EvalContext, args: &mut Arguments) -> TypResult { +pub fn image(ctx: &mut EvalContext, args: &mut Args) -> TypResult { let path = args.expect::>("path to image file")?; let width = args.named("width")?; let height = args.named("height")?; @@ -31,7 +31,7 @@ pub fn image(ctx: &mut EvalContext, args: &mut Arguments) -> TypResult { } /// `rect`: A rectangle with optional content. -pub fn rect(_: &mut EvalContext, args: &mut Arguments) -> TypResult { +pub fn rect(_: &mut EvalContext, args: &mut Args) -> TypResult { let width = args.named("width")?; let height = args.named("height")?; let fill = args.named("fill")?; @@ -40,7 +40,7 @@ pub fn rect(_: &mut EvalContext, args: &mut Arguments) -> TypResult { } /// `square`: A square with optional content. -pub fn square(_: &mut EvalContext, args: &mut Arguments) -> TypResult { +pub fn square(_: &mut EvalContext, args: &mut Args) -> TypResult { let length = args.named::("length")?.map(Linear::from); let width = match length { Some(length) => Some(length), @@ -84,7 +84,7 @@ fn rect_impl( } /// `ellipse`: An ellipse with optional content. -pub fn ellipse(_: &mut EvalContext, args: &mut Arguments) -> TypResult { +pub fn ellipse(_: &mut EvalContext, args: &mut Args) -> TypResult { let width = args.named("width")?; let height = args.named("height")?; let fill = args.named("fill")?; @@ -93,7 +93,7 @@ pub fn ellipse(_: &mut EvalContext, args: &mut Arguments) -> TypResult { } /// `circle`: A circle with optional content. -pub fn circle(_: &mut EvalContext, args: &mut Arguments) -> TypResult { +pub fn circle(_: &mut EvalContext, args: &mut Args) -> TypResult { let diameter = args.named("radius")?.map(|r: Length| 2.0 * Linear::from(r)); let width = match diameter { None => args.named("width")?, diff --git a/src/library/layout.rs b/src/library/layout.rs index a62be646c..8f6458699 100644 --- a/src/library/layout.rs +++ b/src/library/layout.rs @@ -3,7 +3,7 @@ use crate::layout::{FixedNode, GridNode, PadNode, StackChild, StackNode, TrackSi use crate::paper::{Paper, PaperClass}; /// `page`: Configure pages. -pub fn page(ctx: &mut EvalContext, args: &mut Arguments) -> TypResult { +pub fn page(ctx: &mut EvalContext, args: &mut Args) -> TypResult { let paper = match args.eat::>() { Some(name) => match Paper::from_name(&name.v) { None => bail!(name.span, "invalid paper name"), @@ -70,27 +70,27 @@ pub fn page(ctx: &mut EvalContext, args: &mut Arguments) -> TypResult { } /// `pagebreak`: Start a new page. -pub fn pagebreak(ctx: &mut EvalContext, _: &mut Arguments) -> TypResult { +pub fn pagebreak(ctx: &mut EvalContext, _: &mut Args) -> TypResult { ctx.template.pagebreak(true); Ok(Value::None) } /// `h`: Horizontal spacing. -pub fn h(ctx: &mut EvalContext, args: &mut Arguments) -> TypResult { +pub fn h(ctx: &mut EvalContext, args: &mut Args) -> TypResult { let spacing = args.expect("spacing")?; ctx.template.spacing(GenAxis::Inline, spacing); Ok(Value::None) } /// `v`: Vertical spacing. -pub fn v(ctx: &mut EvalContext, args: &mut Arguments) -> TypResult { +pub fn v(ctx: &mut EvalContext, args: &mut Args) -> TypResult { let spacing = args.expect("spacing")?; ctx.template.spacing(GenAxis::Block, spacing); Ok(Value::None) } /// `align`: Configure the alignment along the layouting axes. -pub fn align(ctx: &mut EvalContext, args: &mut Arguments) -> TypResult { +pub fn align(ctx: &mut EvalContext, args: &mut Args) -> TypResult { let first = args.eat::(); let second = args.eat::(); let body = args.eat::