diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-07-26 17:41:07 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-26 17:41:07 +0200 |
| commit | e7ffdde43d09f60238590723c2829554806e23d5 (patch) | |
| tree | 616ae4474f0dec5cc70fe3fa46b5f3c4b305a1be /src/library/layout.rs | |
| parent | 0e8c2cad6e4fee283f8f2d6fb9a571173b59fda2 (diff) | |
| parent | e2ef4f64e777f293a0408d0f60cfed9de69c7bb6 (diff) | |
Merge pull request #5 from typst/problems-and-error-macro
Rename errors to problems and make error! macro more ergonomic
Diffstat (limited to 'src/library/layout.rs')
| -rw-r--r-- | src/library/layout.rs | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/library/layout.rs b/src/library/layout.rs index da1652b0..9fac37b7 100644 --- a/src/library/layout.rs +++ b/src/library/layout.rs @@ -13,14 +13,14 @@ function! { parse(header, body, ctx, f) { AlignFunc { body: body!(opt: body, ctx, f), - map: PosAxisMap::parse::<AxisKey>(&mut f.errors, &mut header.args), + map: PosAxisMap::parse::<AxisKey>(&mut f.problems, &mut header.args), } } layout(self, ctx, f) { ctx.base = ctx.spaces[0].dimensions; - let map = self.map.dedup(&mut f.errors, ctx.axes, |alignment| { + let map = self.map.dedup(&mut f.problems, ctx.axes, |alignment| { alignment.axis().map(|s| s.to_generic(ctx.axes)) }); @@ -29,8 +29,10 @@ function! { if let Some(generic) = alignment.to_generic(ctx.axes, axis) { *ctx.alignment.get_mut(axis) = generic; } else { - f.errors.push(err!(span; - "invalid alignment `{}` for {} axis", alignment, axis)); + error!( + @f, span, + "invalid alignment `{}` for {} axis", alignment, axis, + ); } } } @@ -59,14 +61,14 @@ function! { DirectionFunc { name_span: header.name.span, body: body!(opt: body, ctx, f), - map: PosAxisMap::parse::<AxisKey>(&mut f.errors, &mut header.args), + map: PosAxisMap::parse::<AxisKey>(&mut f.problems, &mut header.args), } } layout(self, ctx, f) { ctx.base = ctx.spaces[0].dimensions; - let map = self.map.dedup(&mut f.errors, ctx.axes, |direction| { + let map = self.map.dedup(&mut f.problems, ctx.axes, |direction| { Some(direction.axis().to_generic(ctx.axes)) }); @@ -76,9 +78,11 @@ function! { map.with(Secondary, |&dir| axes.secondary = dir); if axes.primary.axis() == axes.secondary.axis() { - f.errors.push(err!(self.name_span; + error!( + @f, self.name_span, "invalid aligned primary and secondary axes: `{}`, `{}`", - ctx.axes.primary, ctx.axes.secondary)); + ctx.axes.primary, ctx.axes.secondary, + ); } else { ctx.axes = axes; } @@ -106,8 +110,8 @@ function! { parse(header, body, ctx, f) { BoxFunc { body: body!(opt: body, ctx, f).unwrap_or(SyntaxModel::new()), - extents: AxisMap::parse::<ExtentKey>(&mut f.errors, &mut header.args.key), - debug: header.args.key.get::<bool>(&mut f.errors, "debug"), + extents: AxisMap::parse::<ExtentKey>(&mut f.problems, &mut header.args.key), + debug: header.args.key.get::<bool>(&mut f.problems, "debug"), } } @@ -119,7 +123,7 @@ function! { ctx.debug = debug; } - let map = self.extents.dedup(&mut f.errors, ctx.axes); + let map = self.extents.dedup(&mut f.problems, ctx.axes); for &axis in &[Horizontal, Vertical] { if let Some(psize) = map.get(axis) { let size = psize.scaled(ctx.base.get(axis)); |
