Remove eat_ prefix
This commit is contained in:
parent
6967c6c80a
commit
8b6391040e
@ -537,8 +537,7 @@ impl Eval for ClosureExpr {
|
||||
|
||||
for param in params.iter() {
|
||||
// Set the parameter to `none` if the argument is missing.
|
||||
let value =
|
||||
args.eat_expect::<Value>(ctx, param.as_str()).unwrap_or_default();
|
||||
let value = args.expect::<Value>(ctx, param.as_str()).unwrap_or_default();
|
||||
ctx.scopes.def_mut(param.as_str(), value);
|
||||
}
|
||||
|
||||
|
@ -308,7 +308,7 @@ impl FuncArgs {
|
||||
|
||||
/// Find and consume the first castable positional argument, producing a
|
||||
/// `missing argument: {what}` error if no match was found.
|
||||
pub fn eat_expect<T>(&mut self, ctx: &mut EvalContext, what: &str) -> Option<T>
|
||||
pub fn expect<T>(&mut self, ctx: &mut EvalContext, what: &str) -> Option<T>
|
||||
where
|
||||
T: Cast<Spanned<Value>>,
|
||||
{
|
||||
@ -325,7 +325,7 @@ impl FuncArgs {
|
||||
/// iterator would require unique access to the context, rendering it rather
|
||||
/// unusable. If you need to process arguments one-by-one, you probably want
|
||||
/// to use a while-let loop together with [`eat()`](Self::eat).
|
||||
pub fn eat_all<T>(&mut self, ctx: &mut EvalContext) -> Vec<T>
|
||||
pub fn all<T>(&mut self, ctx: &mut EvalContext) -> Vec<T>
|
||||
where
|
||||
T: Cast<Spanned<Value>>,
|
||||
{
|
||||
@ -334,7 +334,7 @@ impl FuncArgs {
|
||||
|
||||
/// Cast and remove the value for the given named argument, producing an
|
||||
/// error if the conversion fails.
|
||||
pub fn eat_named<T>(&mut self, ctx: &mut EvalContext, name: &str) -> Option<T>
|
||||
pub fn named<T>(&mut self, ctx: &mut EvalContext, name: &str) -> Option<T>
|
||||
where
|
||||
T: Cast<Spanned<Value>>,
|
||||
{
|
||||
|
@ -26,8 +26,8 @@ use super::*;
|
||||
pub fn align(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
|
||||
let first = args.eat::<AlignValue>(ctx);
|
||||
let second = args.eat::<AlignValue>(ctx);
|
||||
let mut horizontal = args.eat_named::<AlignValue>(ctx, "horizontal");
|
||||
let mut vertical = args.eat_named::<AlignValue>(ctx, "vertical");
|
||||
let mut horizontal = args.named::<AlignValue>(ctx, "horizontal");
|
||||
let mut vertical = args.named::<AlignValue>(ctx, "vertical");
|
||||
let body = args.eat::<TemplateValue>(ctx);
|
||||
|
||||
for value in first.into_iter().chain(second) {
|
||||
|
@ -11,7 +11,7 @@ use super::*;
|
||||
/// # Return value
|
||||
/// The name of the value's type as a string.
|
||||
pub fn type_(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
|
||||
match args.eat_expect::<Value>(ctx, "value") {
|
||||
match args.expect::<Value>(ctx, "value") {
|
||||
Some(value) => value.type_name().into(),
|
||||
None => Value::Error,
|
||||
}
|
||||
@ -25,7 +25,7 @@ pub fn type_(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
|
||||
/// # Return value
|
||||
/// The string representation of the value.
|
||||
pub fn repr(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
|
||||
match args.eat_expect::<Value>(ctx, "value") {
|
||||
match args.expect::<Value>(ctx, "value") {
|
||||
Some(value) => pretty(&value).into(),
|
||||
None => Value::Error,
|
||||
}
|
||||
@ -33,7 +33,7 @@ pub fn repr(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
|
||||
|
||||
/// `len`: The length of a string, an array or a dictionary.
|
||||
pub fn len(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
|
||||
match args.eat_expect::<Spanned<Value>>(ctx, "collection") {
|
||||
match args.expect::<Spanned<Value>>(ctx, "collection") {
|
||||
Some(Spanned { v: Value::Str(v), .. }) => Value::Int(v.len() as i64),
|
||||
Some(Spanned { v: Value::Array(v), .. }) => Value::Int(v.len() as i64),
|
||||
Some(Spanned { v: Value::Dict(v), .. }) => Value::Int(v.len() as i64),
|
||||
@ -56,9 +56,9 @@ pub fn len(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
|
||||
/// # Return value
|
||||
/// The color with the given components.
|
||||
pub fn rgb(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
|
||||
let r = args.eat_expect(ctx, "red component");
|
||||
let g = args.eat_expect(ctx, "green component");
|
||||
let b = args.eat_expect(ctx, "blue component");
|
||||
let r = args.expect(ctx, "red component");
|
||||
let g = args.expect(ctx, "green component");
|
||||
let b = args.expect(ctx, "blue component");
|
||||
let a = args.eat(ctx);
|
||||
|
||||
let mut clamp = |component: Option<Spanned<f64>>, default| {
|
||||
|
@ -57,10 +57,10 @@ fn line_impl(
|
||||
args: &mut FuncArgs,
|
||||
substate: fn(&mut FontState) -> &mut Option<Rc<LineState>>,
|
||||
) -> Value {
|
||||
let color = args.eat_named(ctx, "color");
|
||||
let position = args.eat_named(ctx, "position");
|
||||
let strength = args.eat_named::<Linear>(ctx, "strength");
|
||||
let extent = args.eat_named(ctx, "extent").unwrap_or_default();
|
||||
let color = args.named(ctx, "color");
|
||||
let position = args.named(ctx, "position");
|
||||
let strength = args.named::<Linear>(ctx, "strength");
|
||||
let extent = args.named(ctx, "extent").unwrap_or_default();
|
||||
let body = args.eat::<TemplateValue>(ctx);
|
||||
|
||||
// Suppress any existing strikethrough if strength is explicitly zero.
|
||||
|
@ -50,16 +50,16 @@ use super::*;
|
||||
/// - `descender`
|
||||
pub fn font(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
|
||||
let size = args.eat::<Linear>(ctx);
|
||||
let list = args.eat_all::<FontFamily>(ctx);
|
||||
let style = args.eat_named(ctx, "style");
|
||||
let weight = args.eat_named(ctx, "weight");
|
||||
let stretch = args.eat_named(ctx, "stretch");
|
||||
let top_edge = args.eat_named(ctx, "top-edge");
|
||||
let bottom_edge = args.eat_named(ctx, "bottom-edge");
|
||||
let color = args.eat_named(ctx, "color");
|
||||
let serif = args.eat_named(ctx, "serif");
|
||||
let sans_serif = args.eat_named(ctx, "sans-serif");
|
||||
let monospace = args.eat_named(ctx, "monospace");
|
||||
let list = args.all::<FontFamily>(ctx);
|
||||
let style = args.named(ctx, "style");
|
||||
let weight = args.named(ctx, "weight");
|
||||
let stretch = args.named(ctx, "stretch");
|
||||
let top_edge = args.named(ctx, "top-edge");
|
||||
let bottom_edge = args.named(ctx, "bottom-edge");
|
||||
let color = args.named(ctx, "color");
|
||||
let serif = args.named(ctx, "serif");
|
||||
let sans_serif = args.named(ctx, "sans-serif");
|
||||
let monospace = args.named(ctx, "monospace");
|
||||
let body = args.eat::<TemplateValue>(ctx);
|
||||
|
||||
Value::template("font", move |ctx| {
|
||||
|
@ -34,17 +34,17 @@ use super::*;
|
||||
/// - `ttb`
|
||||
/// - `btt`
|
||||
pub fn grid(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
|
||||
let columns = args.eat_named::<Tracks>(ctx, "columns").unwrap_or_default();
|
||||
let rows = args.eat_named::<Tracks>(ctx, "rows").unwrap_or_default();
|
||||
let columns = args.named::<Tracks>(ctx, "columns").unwrap_or_default();
|
||||
let rows = args.named::<Tracks>(ctx, "rows").unwrap_or_default();
|
||||
let gutter = args
|
||||
.eat_named::<Linear>(ctx, "gutter")
|
||||
.named::<Linear>(ctx, "gutter")
|
||||
.map(|v| vec![TrackSizing::Linear(v)])
|
||||
.unwrap_or_default();
|
||||
let gutter_columns = args.eat_named::<Tracks>(ctx, "gutter-columns");
|
||||
let gutter_rows = args.eat_named::<Tracks>(ctx, "gutter-rows");
|
||||
let column_dir = args.eat_named(ctx, "column-dir");
|
||||
let row_dir = args.eat_named(ctx, "row-dir");
|
||||
let children = args.eat_all::<TemplateValue>(ctx);
|
||||
let gutter_columns = args.named::<Tracks>(ctx, "gutter-columns");
|
||||
let gutter_rows = args.named::<Tracks>(ctx, "gutter-rows");
|
||||
let column_dir = args.named(ctx, "column-dir");
|
||||
let row_dir = args.named(ctx, "row-dir");
|
||||
let children = args.all::<TemplateValue>(ctx);
|
||||
|
||||
Value::template("grid", move |ctx| {
|
||||
let children = children
|
||||
|
@ -14,9 +14,9 @@ use crate::layout::{AnyNode, Constrained, Constraints, Element, Frame, Layout, L
|
||||
/// # Return value
|
||||
/// A template that inserts an image.
|
||||
pub fn image(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
|
||||
let path = args.eat_expect::<Spanned<String>>(ctx, "path to image file");
|
||||
let width = args.eat_named(ctx, "width");
|
||||
let height = args.eat_named(ctx, "height");
|
||||
let path = args.expect::<Spanned<String>>(ctx, "path to image file");
|
||||
let width = args.named(ctx, "width");
|
||||
let height = args.named(ctx, "height");
|
||||
|
||||
let mut node = None;
|
||||
if let Some(path) = &path {
|
||||
|
@ -17,7 +17,7 @@ use super::*;
|
||||
/// - `rtl`
|
||||
pub fn lang(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
|
||||
let iso = args.eat::<String>(ctx).map(|s| lang_dir(&s));
|
||||
let dir = match args.eat_named::<Spanned<Dir>>(ctx, "dir") {
|
||||
let dir = match args.named::<Spanned<Dir>>(ctx, "dir") {
|
||||
Some(dir) if dir.v.axis() == SpecAxis::Horizontal => Some(dir.v),
|
||||
Some(dir) => {
|
||||
ctx.diag(error!(dir.span, "must be horizontal"));
|
||||
|
@ -51,7 +51,7 @@ fn minmax(ctx: &mut EvalContext, args: &mut FuncArgs, goal: Ordering) -> Value {
|
||||
}
|
||||
|
||||
extremum.unwrap_or_else(|| {
|
||||
args.eat_expect::<Value>(ctx, "value");
|
||||
args.expect::<Value>(ctx, "value");
|
||||
Value::Error
|
||||
})
|
||||
}
|
||||
|
@ -17,11 +17,11 @@ use crate::layout::PadNode;
|
||||
/// A template that pads its region and sets the body into it.
|
||||
pub fn pad(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
|
||||
let all = args.eat(ctx);
|
||||
let left = args.eat_named(ctx, "left");
|
||||
let top = args.eat_named(ctx, "top");
|
||||
let right = args.eat_named(ctx, "right");
|
||||
let bottom = args.eat_named(ctx, "bottom");
|
||||
let body = args.eat_expect::<TemplateValue>(ctx, "body").unwrap_or_default();
|
||||
let left = args.named(ctx, "left");
|
||||
let top = args.named(ctx, "top");
|
||||
let right = args.named(ctx, "right");
|
||||
let bottom = args.named(ctx, "bottom");
|
||||
let body = args.expect::<TemplateValue>(ctx, "body").unwrap_or_default();
|
||||
|
||||
let padding = Sides::new(
|
||||
left.or(all).unwrap_or_default(),
|
||||
|
@ -29,14 +29,14 @@ pub fn page(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
|
||||
})
|
||||
});
|
||||
|
||||
let width = args.eat_named(ctx, "width");
|
||||
let height = args.eat_named(ctx, "height");
|
||||
let margins = args.eat_named(ctx, "margins");
|
||||
let left = args.eat_named(ctx, "left");
|
||||
let top = args.eat_named(ctx, "top");
|
||||
let right = args.eat_named(ctx, "right");
|
||||
let bottom = args.eat_named(ctx, "bottom");
|
||||
let flip = args.eat_named(ctx, "flip");
|
||||
let width = args.named(ctx, "width");
|
||||
let height = args.named(ctx, "height");
|
||||
let margins = args.named(ctx, "margins");
|
||||
let left = args.named(ctx, "left");
|
||||
let top = args.named(ctx, "top");
|
||||
let right = args.named(ctx, "right");
|
||||
let bottom = args.named(ctx, "bottom");
|
||||
let flip = args.named(ctx, "flip");
|
||||
let body = args.eat::<TemplateValue>(ctx);
|
||||
let span = args.span;
|
||||
|
||||
|
@ -10,9 +10,9 @@ use super::*;
|
||||
/// # Return value
|
||||
/// A template that configures paragraph properties.
|
||||
pub fn par(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
|
||||
let spacing = args.eat_named(ctx, "spacing");
|
||||
let leading = args.eat_named(ctx, "leading");
|
||||
let word_spacing = args.eat_named(ctx, "word-spacing");
|
||||
let spacing = args.named(ctx, "spacing");
|
||||
let leading = args.named(ctx, "leading");
|
||||
let word_spacing = args.named(ctx, "word-spacing");
|
||||
|
||||
Value::template("par", move |ctx| {
|
||||
if let Some(spacing) = spacing {
|
||||
|
@ -19,9 +19,9 @@ use crate::layout::{BackgroundNode, BackgroundShape, Fill, FixedNode, PadNode};
|
||||
/// # Return value
|
||||
/// A template that inserts a rectangle and sets the body into it.
|
||||
pub fn rect(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
|
||||
let width = args.eat_named(ctx, "width");
|
||||
let height = args.eat_named(ctx, "height");
|
||||
let fill = args.eat_named(ctx, "fill");
|
||||
let width = args.named(ctx, "width");
|
||||
let height = args.named(ctx, "height");
|
||||
let fill = args.named(ctx, "fill");
|
||||
let body = args.eat::<TemplateValue>(ctx).unwrap_or_default();
|
||||
rect_impl("rect", width, height, None, fill, body)
|
||||
}
|
||||
@ -44,10 +44,10 @@ pub fn rect(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
|
||||
/// # Return value
|
||||
/// A template that inserts a square and sets the body into it.
|
||||
pub fn square(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
|
||||
let length = args.eat_named::<Length>(ctx, "length").map(Linear::from);
|
||||
let width = length.or_else(|| args.eat_named(ctx, "width"));
|
||||
let height = width.is_none().then(|| args.eat_named(ctx, "height")).flatten();
|
||||
let fill = args.eat_named(ctx, "fill");
|
||||
let length = args.named::<Length>(ctx, "length").map(Linear::from);
|
||||
let width = length.or_else(|| args.named(ctx, "width"));
|
||||
let height = width.is_none().then(|| args.named(ctx, "height")).flatten();
|
||||
let fill = args.named(ctx, "fill");
|
||||
let body = args.eat::<TemplateValue>(ctx).unwrap_or_default();
|
||||
rect_impl("square", width, height, Some(N64::from(1.0)), fill, body)
|
||||
}
|
||||
@ -91,9 +91,9 @@ fn rect_impl(
|
||||
/// # Return value
|
||||
/// A template that inserts an ellipse and sets the body into it.
|
||||
pub fn ellipse(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
|
||||
let width = args.eat_named(ctx, "width");
|
||||
let height = args.eat_named(ctx, "height");
|
||||
let fill = args.eat_named(ctx, "fill");
|
||||
let width = args.named(ctx, "width");
|
||||
let height = args.named(ctx, "height");
|
||||
let fill = args.named(ctx, "fill");
|
||||
let body = args.eat::<TemplateValue>(ctx).unwrap_or_default();
|
||||
ellipse_impl("ellipse", width, height, None, fill, body)
|
||||
}
|
||||
@ -116,10 +116,10 @@ pub fn ellipse(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
|
||||
/// # Return value
|
||||
/// A template that inserts a circle and sets the body into it.
|
||||
pub fn circle(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
|
||||
let radius = args.eat_named::<Length>(ctx, "radius").map(|r| 2.0 * Linear::from(r));
|
||||
let width = radius.or_else(|| args.eat_named(ctx, "width"));
|
||||
let height = width.is_none().then(|| args.eat_named(ctx, "height")).flatten();
|
||||
let fill = args.eat_named(ctx, "fill");
|
||||
let radius = args.named::<Length>(ctx, "radius").map(|r| 2.0 * Linear::from(r));
|
||||
let width = radius.or_else(|| args.named(ctx, "width"));
|
||||
let height = width.is_none().then(|| args.named(ctx, "height")).flatten();
|
||||
let fill = args.named(ctx, "fill");
|
||||
let body = args.eat::<TemplateValue>(ctx).unwrap_or_default();
|
||||
ellipse_impl("circle", width, height, Some(N64::from(1.0)), fill, body)
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ fn spacing_impl(
|
||||
args: &mut FuncArgs,
|
||||
axis: GenAxis,
|
||||
) -> Value {
|
||||
let spacing: Option<Linear> = args.eat_expect(ctx, "spacing");
|
||||
let spacing: Option<Linear> = args.expect(ctx, "spacing");
|
||||
Value::template(name, move |ctx| {
|
||||
if let Some(linear) = spacing {
|
||||
// TODO: Should this really always be font-size relative?
|
||||
|
@ -19,8 +19,8 @@ use crate::layout::{StackChild, StackNode};
|
||||
/// - `ttb`
|
||||
/// - `btt`
|
||||
pub fn stack(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
|
||||
let dir = args.eat_named::<Dir>(ctx, "dir").unwrap_or(Dir::TTB);
|
||||
let children = args.eat_all::<TemplateValue>(ctx);
|
||||
let dir = args.named::<Dir>(ctx, "dir").unwrap_or(Dir::TTB);
|
||||
let children = args.all::<TemplateValue>(ctx);
|
||||
|
||||
Value::template("stack", move |ctx| {
|
||||
let children = children
|
||||
|
@ -323,8 +323,8 @@ fn register_helpers(scope: &mut Scope, panics: Rc<RefCell<Vec<Panic>>>) {
|
||||
}
|
||||
|
||||
let test = move |ctx: &mut EvalContext, args: &mut FuncArgs| -> Value {
|
||||
let lhs = args.eat_expect::<Value>(ctx, "left-hand side");
|
||||
let rhs = args.eat_expect::<Value>(ctx, "right-hand side");
|
||||
let lhs = args.expect::<Value>(ctx, "left-hand side");
|
||||
let rhs = args.expect::<Value>(ctx, "right-hand side");
|
||||
if lhs != rhs {
|
||||
panics.borrow_mut().push(Panic { pos: args.span.start, lhs, rhs });
|
||||
Value::Str(format!("(panic)"))
|
||||
|
Loading…
x
Reference in New Issue
Block a user