mirror of
https://github.com/typst/typst
synced 2025-06-28 16:22:53 +08:00
Remove @ syntax in diagnostics macros 🗑
This commit is contained in:
parent
2df8b964d0
commit
fa3e2920c0
@ -46,18 +46,13 @@ impl Display for Level {
|
||||
/// ```
|
||||
/// # use typstc::error;
|
||||
/// # use typstc::syntax::Span;
|
||||
/// # use typstc::Feedback;
|
||||
/// # let span = Span::ZERO;
|
||||
/// # let mut feedback = Feedback::new();
|
||||
/// # let name = "";
|
||||
/// // Create formatted error values.
|
||||
/// let error = error!("expected {}", name);
|
||||
///
|
||||
/// // Create spanned errors.
|
||||
/// let spanned = error!(span, "there is an error here");
|
||||
///
|
||||
/// // Create an error and directly add it to existing feedback.
|
||||
/// error!(@feedback, span, "oh no!");
|
||||
/// ```
|
||||
///
|
||||
/// [`Error`]: diagnostic/enum.Level.html#variant.Error
|
||||
@ -85,10 +80,6 @@ macro_rules! warning {
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
macro_rules! __impl_diagnostic {
|
||||
($level:expr; @$feedback:expr, $($tts:tt)*) => {
|
||||
$feedback.diags.push($crate::__impl_diagnostic!($level; $($tts)*));
|
||||
};
|
||||
|
||||
($level:expr; $fmt:literal $($tts:tt)*) => {
|
||||
$crate::diag::Diag::new($level, format!($fmt $($tts)*))
|
||||
};
|
||||
|
@ -129,7 +129,7 @@ impl Args {
|
||||
pub fn done(&self, ctx: &mut LayoutContext) {
|
||||
for entry in self.0.v.values() {
|
||||
let span = entry.key_span.join(entry.value.span);
|
||||
error!(@ctx.f, span, "unexpected argument");
|
||||
ctx.diag(error!(span, "unexpected argument"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ impl Eval for ExprCall {
|
||||
(func.clone())(args, ctx).await
|
||||
} else {
|
||||
if !name.is_empty() {
|
||||
error!(@ctx.f, span, "unknown function");
|
||||
ctx.diag(error!(span, "unknown function"));
|
||||
ctx.f.decos.push(Deco::Unresolved.span_with(span));
|
||||
}
|
||||
Value::Dict(dict)
|
||||
@ -159,7 +159,7 @@ fn neg(ctx: &mut LayoutContext, span: Span, value: Value) -> Value {
|
||||
Relative(v) => Relative(-v),
|
||||
Linear(v) => Linear(-v),
|
||||
v => {
|
||||
error!(@ctx.f, span, "cannot negate {}", v.ty());
|
||||
ctx.diag(error!(span, "cannot negate {}", v.ty()));
|
||||
Value::Error
|
||||
}
|
||||
}
|
||||
@ -196,7 +196,7 @@ fn add(ctx: &mut LayoutContext, span: Span, lhs: Value, rhs: Value) -> Value {
|
||||
(Commands(a), Commands(b)) => Commands(concat(a, b)),
|
||||
|
||||
(a, b) => {
|
||||
error!(@ctx.f, span, "cannot add {} and {}", a.ty(), b.ty());
|
||||
ctx.diag(error!(span, "cannot add {} and {}", a.ty(), b.ty()));
|
||||
Value::Error
|
||||
}
|
||||
}
|
||||
@ -225,7 +225,7 @@ fn sub(ctx: &mut LayoutContext, span: Span, lhs: Value, rhs: Value) -> Value {
|
||||
(Linear(a), Linear(b)) => Linear(a - b),
|
||||
|
||||
(a, b) => {
|
||||
error!(@ctx.f, span, "cannot subtract {1} from {0}", a.ty(), b.ty());
|
||||
ctx.diag(error!(span, "cannot subtract {1} from {0}", a.ty(), b.ty()));
|
||||
Value::Error
|
||||
}
|
||||
}
|
||||
@ -260,7 +260,7 @@ fn mul(ctx: &mut LayoutContext, span: Span, lhs: Value, rhs: Value) -> Value {
|
||||
(Str(a), Int(b)) => Str(a.repeat(b.max(0) as usize)),
|
||||
|
||||
(a, b) => {
|
||||
error!(@ctx.f, span, "cannot multiply {} with {}", a.ty(), b.ty());
|
||||
ctx.diag(error!(span, "cannot multiply {} with {}", a.ty(), b.ty()));
|
||||
Value::Error
|
||||
}
|
||||
}
|
||||
@ -285,7 +285,7 @@ fn div(ctx: &mut LayoutContext, span: Span, lhs: Value, rhs: Value) -> Value {
|
||||
(Linear(a), Float(b)) => Linear(a / b),
|
||||
|
||||
(a, b) => {
|
||||
error!(@ctx.f, span, "cannot divide {} by {}", a.ty(), b.ty());
|
||||
ctx.diag(error!(span, "cannot divide {} by {}", a.ty(), b.ty()));
|
||||
Value::Error
|
||||
}
|
||||
}
|
||||
|
@ -13,10 +13,11 @@ pub use tree::*;
|
||||
|
||||
use crate::geom::{Insets, Point, Rect, RectExt, Sides, Size, SizeExt};
|
||||
|
||||
use crate::diag::Diag;
|
||||
use crate::eval::{PageState, State, TextState};
|
||||
use crate::font::SharedFontLoader;
|
||||
use crate::shaping::Shaped;
|
||||
use crate::syntax::SynTree;
|
||||
use crate::syntax::{Deco, Spanned, SynTree};
|
||||
use crate::{Feedback, Pass};
|
||||
|
||||
/// Layout a syntax tree and return the produced layout.
|
||||
@ -98,6 +99,18 @@ pub struct LayoutContext {
|
||||
pub f: Feedback,
|
||||
}
|
||||
|
||||
impl LayoutContext {
|
||||
/// Add a diagnostic to the feedback.
|
||||
pub fn diag(&mut self, diag: Spanned<Diag>) {
|
||||
self.f.diags.push(diag);
|
||||
}
|
||||
|
||||
/// Add a decoration to the feedback.
|
||||
pub fn deco(&mut self, deco: Spanned<Deco>) {
|
||||
self.f.decos.push(deco);
|
||||
}
|
||||
}
|
||||
|
||||
/// The constraints for layouting a single node.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct LayoutConstraints {
|
||||
|
@ -198,10 +198,10 @@ impl<'a> TreeLayouter<'a> {
|
||||
if self.constraints.root {
|
||||
self.layouter.finish_space(true)
|
||||
} else {
|
||||
error!(
|
||||
@self.ctx.f, span,
|
||||
self.ctx.diag(error!(
|
||||
span,
|
||||
"page break can only be issued from root context",
|
||||
);
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@ -224,10 +224,10 @@ impl<'a> TreeLayouter<'a> {
|
||||
self.constraints.base = space.usable();
|
||||
self.layouter.set_spaces(vec![space], true);
|
||||
} else {
|
||||
error!(
|
||||
@self.ctx.f, span,
|
||||
self.ctx.diag(error!(
|
||||
span,
|
||||
"page style can only be changed from root context",
|
||||
);
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,12 +53,12 @@ fn parse_aligns(
|
||||
// `deferred_center` to true and handle the situation once we know more.
|
||||
if let Some(axis) = axis {
|
||||
if align.v.axis().map_or(false, |a| a != axis) {
|
||||
error!(
|
||||
@ctx.f, align.span,
|
||||
ctx.diag(error!(
|
||||
align.span,
|
||||
"invalid alignment {} for {} axis", align.v, axis,
|
||||
);
|
||||
));
|
||||
} else if had[axis as usize] {
|
||||
error!(@ctx.f, align.span, "duplicate alignment for {} axis", axis);
|
||||
ctx.diag(error!(align.span, "duplicate alignment for {} axis", axis));
|
||||
} else {
|
||||
let gen_align = align.v.to_gen(ctx.state.sys);
|
||||
*aligns.get_mut(axis.to_gen(ctx.state.sys)) = gen_align;
|
||||
@ -66,7 +66,7 @@ fn parse_aligns(
|
||||
}
|
||||
} else {
|
||||
if had == [true, true] {
|
||||
error!(@ctx.f, align.span, "duplicate alignment");
|
||||
ctx.diag(error!(align.span, "duplicate alignment"));
|
||||
} else if deferred_center {
|
||||
// We have two unflushed centers, meaning we know that both axes
|
||||
// are to be centered.
|
||||
|
@ -12,7 +12,7 @@ pub async fn rgb(mut args: Args, ctx: &mut LayoutContext) -> Value {
|
||||
let mut clamp = |component: Option<Spanned<i64>>, default| {
|
||||
component.map_or(default, |c| {
|
||||
if c.v < 0 || c.v > 255 {
|
||||
error!(@ctx.f, c.span, "should be between 0 and 255")
|
||||
ctx.diag(error!(c.span, "should be between 0 and 255"));
|
||||
}
|
||||
c.v.max(0).min(255) as u8
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user