summaryrefslogtreecommitdiff
path: root/macros/src/lib.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-12-19 01:16:35 +0100
committerLaurenz <laurmaedje@gmail.com>2022-12-19 01:16:35 +0100
commitb4b022940b908d8fe490b9f4f68bc60dcfb76cd2 (patch)
treebc93a2f51295f97f971466ab87bdd763c0ed6002 /macros/src/lib.rs
parentba384e5bb6c2455eb431f6e1fcc8b98aca1e9879 (diff)
Syntax and example sections
Diffstat (limited to 'macros/src/lib.rs')
-rw-r--r--macros/src/lib.rs23
1 files changed, 18 insertions, 5 deletions
diff --git a/macros/src/lib.rs b/macros/src/lib.rs
index a03dc30e..23b03712 100644
--- a/macros/src/lib.rs
+++ b/macros/src/lib.rs
@@ -4,12 +4,18 @@ extern crate proc_macro;
/// Return an error at the given item.
macro_rules! bail {
+ (callsite, $fmt:literal $($tts:tt)*) => {
+ return Err(syn::Error::new(
+ proc_macro2::Span::call_site(),
+ format!(concat!("typst: ", $fmt) $($tts)*)
+ ))
+ };
($item:expr, $fmt:literal $($tts:tt)*) => {
- return Err(Error::new_spanned(
+ return Err(syn::Error::new_spanned(
&$item,
format!(concat!("typst: ", $fmt) $($tts)*)
))
- }
+ };
}
mod capable;
@@ -19,9 +25,8 @@ mod node;
use proc_macro::TokenStream as BoundaryStream;
use proc_macro2::{TokenStream, TokenTree};
-use quote::{quote, quote_spanned};
-use syn::parse_quote;
-use syn::{Error, Ident, Result};
+use quote::{quote, quote_spanned, ToTokens};
+use syn::{parse_quote, Ident, Result};
/// Implement `FuncType` for a type or function.
#[proc_macro_attribute]
@@ -88,3 +93,11 @@ fn documentation(attrs: &[syn::Attribute]) -> String {
fn dedent(text: &str) -> String {
text.lines().map(str::trim).collect::<Vec<_>>().join("\n")
}
+
+/// Quote an optional value.
+fn quote_option<T: ToTokens>(option: Option<T>) -> TokenStream {
+ match option {
+ Some(value) => quote! { Some(#value) },
+ None => quote! { None },
+ }
+}