mirror of
https://github.com/typst/typst
synced 2025-06-28 08:12:53 +08:00
Adjust macros to new version
This commit is contained in:
parent
6ae6d86b9c
commit
7e6e7e928c
@ -7,11 +7,11 @@ use crate::syntax::{Span, Spanned};
|
|||||||
/// Early-return with a vec-boxed [`Error`].
|
/// Early-return with a vec-boxed [`Error`].
|
||||||
macro_rules! bail {
|
macro_rules! bail {
|
||||||
($span:expr, $message:expr $(,)?) => {
|
($span:expr, $message:expr $(,)?) => {
|
||||||
return Err($crate::diag::Error::boxed($span, $message,));
|
return Err($crate::diag::Error::boxed($span, $message,))
|
||||||
};
|
};
|
||||||
|
|
||||||
($span:expr, $fmt:expr, $($arg:expr),+ $(,)?) => {
|
($span:expr, $fmt:expr, $($arg:expr),+ $(,)?) => {
|
||||||
bail!($span, format!($fmt, $($arg),+));
|
bail!($span, format!($fmt, $($arg),+))
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ use Value::*;
|
|||||||
/// Bail with a type mismatch error.
|
/// Bail with a type mismatch error.
|
||||||
macro_rules! mismatch {
|
macro_rules! mismatch {
|
||||||
($fmt:expr, $($value:expr),* $(,)?) => {
|
($fmt:expr, $($value:expr),* $(,)?) => {
|
||||||
return Err(format!($fmt, $($value.type_name()),*));
|
return Err(format!($fmt, $($value.type_name()),*))
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,10 +11,9 @@ macro_rules! impl_visitors {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl_visitor! {
|
impl_visitor! {
|
||||||
/// Walk syntax trees immutably.
|
|
||||||
Visit,
|
Visit,
|
||||||
/// Immutable visitor functions.
|
|
||||||
immutable,
|
immutable,
|
||||||
|
immutably,
|
||||||
[$(($name($($tts)*) $body))*]
|
[$(($name($($tts)*) $body))*]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,10 +23,9 @@ macro_rules! impl_visitors {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl_visitor! {
|
impl_visitor! {
|
||||||
/// Walk syntax trees mutably.
|
|
||||||
VisitMut,
|
VisitMut,
|
||||||
/// Mutable visitor functions.
|
|
||||||
mutable,
|
mutable,
|
||||||
|
mutably,
|
||||||
[$(($name($($tts)*) $body mut))*] mut
|
[$(($name($($tts)*) $body mut))*] mut
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -36,8 +34,9 @@ macro_rules! impl_visitors {
|
|||||||
/// Implement an immutable or mutable visitor.
|
/// Implement an immutable or mutable visitor.
|
||||||
macro_rules! impl_visitor {
|
macro_rules! impl_visitor {
|
||||||
(
|
(
|
||||||
#[doc = $visit_doc:expr] $visit:ident,
|
$visit:ident,
|
||||||
#[doc = $module_doc:expr] $module:ident,
|
$mutability:ident,
|
||||||
|
$adjective:ident,
|
||||||
[$((
|
[$((
|
||||||
$name:ident($v:ident, $node:ident: $ty:ty)
|
$name:ident($v:ident, $node:ident: $ty:ty)
|
||||||
$body:block
|
$body:block
|
||||||
@ -45,7 +44,7 @@ macro_rules! impl_visitor {
|
|||||||
))*]
|
))*]
|
||||||
$($mut:tt)?
|
$($mut:tt)?
|
||||||
) => {
|
) => {
|
||||||
#[doc = $visit_doc]
|
#[doc = concat!("Visit syntax trees ", stringify!($adjective), ".")]
|
||||||
pub trait $visit<'ast> {
|
pub trait $visit<'ast> {
|
||||||
/// Visit a definition of a binding.
|
/// Visit a definition of a binding.
|
||||||
///
|
///
|
||||||
@ -60,14 +59,15 @@ macro_rules! impl_visitor {
|
|||||||
fn visit_exit(&mut self) {}
|
fn visit_exit(&mut self) {}
|
||||||
|
|
||||||
$(fn $name(&mut self, $node: &'ast $($fmut)? $ty) {
|
$(fn $name(&mut self, $node: &'ast $($fmut)? $ty) {
|
||||||
$module::$name(self, $node);
|
$mutability::$name(self, $node);
|
||||||
})*
|
})*
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc = $module_doc]
|
#[doc = concat!("Visitor functions that are ", stringify!($mutability), ".")]
|
||||||
pub mod $module {
|
pub mod $mutability {
|
||||||
use super::*;
|
use super::*;
|
||||||
$(
|
$(
|
||||||
|
#[doc = concat!("Visit a node of type [`", stringify!($ty), "`].")]
|
||||||
pub fn $name<'ast, V>($v: &mut V, $node: &'ast $($fmut)? $ty)
|
pub fn $name<'ast, V>($v: &mut V, $node: &'ast $($fmut)? $ty)
|
||||||
where
|
where
|
||||||
V: $visit<'ast> + ?Sized
|
V: $visit<'ast> + ?Sized
|
||||||
|
Loading…
x
Reference in New Issue
Block a user