summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-07-26 17:41:07 +0200
committerGitHub <noreply@github.com>2020-07-26 17:41:07 +0200
commite7ffdde43d09f60238590723c2829554806e23d5 (patch)
tree616ae4474f0dec5cc70fe3fa46b5f3c4b305a1be /src/library
parent0e8c2cad6e4fee283f8f2d6fb9a571173b59fda2 (diff)
parente2ef4f64e777f293a0408d0f60cfed9de69c7bb6 (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')
-rw-r--r--src/library/font.rs34
-rw-r--r--src/library/layout.rs26
-rw-r--r--src/library/mod.rs2
-rw-r--r--src/library/page.rs12
-rw-r--r--src/library/spacing.rs20
5 files changed, 50 insertions, 44 deletions
diff --git a/src/library/font.rs b/src/library/font.rs
index ba778693..9f7902f6 100644
--- a/src/library/font.rs
+++ b/src/library/font.rs
@@ -13,17 +13,17 @@ function! {
}
parse(header, body, ctx, f) {
- let list = header.args.pos.get_all::<StringLike>(&mut f.errors)
+ let list = header.args.pos.get_all::<StringLike>(&mut f.problems)
.map(|s| s.0.to_lowercase())
.collect();
let tuples: Vec<_> = header.args.key
- .get_all::<String, Tuple>(&mut f.errors)
+ .get_all::<String, Tuple>(&mut f.problems)
.collect();
let classes = tuples.into_iter()
.map(|(class, mut tuple)| {
- let fallback = tuple.get_all::<StringLike>(&mut f.errors)
+ let fallback = tuple.get_all::<StringLike>(&mut f.problems)
.map(|s| s.0.to_lowercase())
.collect();
(class.to_lowercase(), fallback)
@@ -37,7 +37,7 @@ function! {
}
}
- layout(self, ctx, errors) {
+ layout(self, ctx, f) {
styled(&self.body, ctx, Some(()),
|s, _| {
if !self.list.is_empty() {
@@ -64,12 +64,12 @@ function! {
parse(header, body, ctx, f) {
FontStyleFunc {
body: body!(opt: body, ctx, f),
- style: header.args.pos.get::<FontStyle>(&mut f.errors)
- .or_missing(&mut f.errors, header.name.span, "style"),
+ style: header.args.pos.get::<FontStyle>(&mut f.problems)
+ .or_missing(&mut f.problems, header.name.span, "style"),
}
}
- layout(self, ctx, errors) {
+ layout(self, ctx, f) {
styled(&self.body, ctx, self.style, |t, s| t.variant.style = s)
}
}
@@ -84,22 +84,24 @@ function! {
parse(header, body, ctx, f) {
let body = body!(opt: body, ctx, f);
- let weight = header.args.pos.get::<Spanned<(FontWeight, bool)>>(&mut f.errors)
+ let weight = header.args.pos.get::<Spanned<(FontWeight, bool)>>(&mut f.problems)
.map(|Spanned { v: (weight, is_clamped), span }| {
if is_clamped {
- f.errors.push(err!(@Warning: span;
- "weight should be between \
- 100 and 900, clamped to {}", weight.0));
+ warning!(
+ @f, span,
+ "weight should be between 100 and 900, clamped to {}",
+ weight.0,
+ );
}
weight
})
- .or_missing(&mut f.errors, header.name.span, "weight");
+ .or_missing(&mut f.problems, header.name.span, "weight");
FontWeightFunc { body, weight }
}
- layout(self, ctx, errors) {
+ layout(self, ctx, f) {
styled(&self.body, ctx, self.weight, |t, w| t.variant.weight = w)
}
}
@@ -115,12 +117,12 @@ function! {
parse(header, body, ctx, f) {
FontSizeFunc {
body: body!(opt: body, ctx, f),
- size: header.args.pos.get::<FSize>(&mut f.errors)
- .or_missing(&mut f.errors, header.name.span, "size")
+ size: header.args.pos.get::<FSize>(&mut f.problems)
+ .or_missing(&mut f.problems, header.name.span, "size")
}
}
- layout(self, ctx, errors) {
+ layout(self, ctx, f) {
styled(&self.body, ctx, self.size, |t, s| {
match s {
FSize::Absolute(size) => {
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));
diff --git a/src/library/mod.rs b/src/library/mod.rs
index 08608d05..c8ca374d 100644
--- a/src/library/mod.rs
+++ b/src/library/mod.rs
@@ -59,7 +59,7 @@ function! {
ValFunc { body: body!(opt: body, ctx, f) }
}
- layout(self, ctx, errors) {
+ layout(self, ctx, f) {
match &self.body {
Some(model) => vec![LayoutSyntaxModel(model)],
None => vec![],
diff --git a/src/library/page.rs b/src/library/page.rs
index 07e43026..4d92ea91 100644
--- a/src/library/page.rs
+++ b/src/library/page.rs
@@ -15,9 +15,9 @@ function! {
parse(header, body, ctx, f) {
body!(nope: body, f);
PageSizeFunc {
- paper: header.args.pos.get::<Paper>(&mut f.errors),
- extents: AxisMap::parse::<ExtentKey>(&mut f.errors, &mut header.args.key),
- flip: header.args.key.get::<bool>(&mut f.errors, "flip").unwrap_or(false),
+ paper: header.args.pos.get::<Paper>(&mut f.problems),
+ extents: AxisMap::parse::<ExtentKey>(&mut f.problems, &mut header.args.key),
+ flip: header.args.key.get::<bool>(&mut f.problems, "flip").unwrap_or(false),
}
}
@@ -31,7 +31,7 @@ function! {
style.class = PaperClass::Custom;
}
- let map = self.extents.dedup(&mut f.errors, ctx.axes);
+ let map = self.extents.dedup(&mut f.problems, ctx.axes);
map.with(Horizontal, |&width| style.dimensions.x = width);
map.with(Vertical, |&height| style.dimensions.y = height);
@@ -53,13 +53,13 @@ function! {
parse(header, body, ctx, f) {
body!(nope: body, f);
PageMarginsFunc {
- padding: PaddingMap::parse(&mut f.errors, &mut header.args),
+ padding: PaddingMap::parse(&mut f.problems, &mut header.args),
}
}
layout(self, ctx, f) {
let mut style = ctx.style.page;
- self.padding.apply(&mut f.errors, ctx.axes, &mut style.margins);
+ self.padding.apply(&mut f.problems, ctx.axes, &mut style.margins);
vec![SetPageStyle(style)]
}
}
diff --git a/src/library/spacing.rs b/src/library/spacing.rs
index a6db162a..8d9c46aa 100644
--- a/src/library/spacing.rs
+++ b/src/library/spacing.rs
@@ -11,7 +11,7 @@ function! {
pub struct LineBreakFunc;
parse(default)
- layout(self, ctx, errors) { vec![BreakLine] }
+ layout(self, ctx, f) { vec![BreakLine] }
}
function! {
@@ -22,7 +22,7 @@ function! {
pub struct ParBreakFunc;
parse(default)
- layout(self, ctx, errors) { vec![BreakParagraph] }
+ layout(self, ctx, f) { vec![BreakParagraph] }
}
function! {
@@ -31,7 +31,7 @@ function! {
pub struct PageBreakFunc;
parse(default)
- layout(self, ctx, errors) { vec![BreakPage] }
+ layout(self, ctx, f) { vec![BreakPage] }
}
function! {
@@ -50,13 +50,13 @@ function! {
ContentSpacingFunc {
body: body!(opt: body, ctx, f),
content: meta,
- spacing: header.args.pos.get::<f64>(&mut f.errors)
+ spacing: header.args.pos.get::<f64>(&mut f.problems)
.map(|num| num as f32)
- .or_missing(&mut f.errors, header.name.span, "spacing"),
+ .or_missing(&mut f.problems, header.name.span, "spacing"),
}
}
- layout(self, ctx, errors) {
+ layout(self, ctx, f) {
styled(&self.body, ctx, self.spacing, |t, s| match self.content {
Word => t.word_spacing_scale = s,
Line => t.line_spacing_scale = s,
@@ -88,15 +88,15 @@ function! {
body!(nope: body, f);
SpacingFunc {
spacing: if let Some(axis) = meta {
- header.args.pos.get::<FSize>(&mut f.errors)
+ header.args.pos.get::<FSize>(&mut f.problems)
.map(|s| (AxisKey::Specific(axis), s))
} else {
- header.args.key.get_with_key::<AxisKey, FSize>(&mut f.errors)
- }.or_missing(&mut f.errors, header.name.span, "spacing"),
+ header.args.key.get_with_key::<AxisKey, FSize>(&mut f.problems)
+ }.or_missing(&mut f.problems, header.name.span, "spacing"),
}
}
- layout(self, ctx, errors) {
+ layout(self, ctx, f) {
if let Some((axis, spacing)) = self.spacing {
let axis = axis.to_generic(ctx.axes);
let spacing = spacing.scaled(ctx.style.text.font_size());