blob: c1a8b2ae108f7230430be7cea55193b9048d8c2d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
//! Procedural macros for Typst.
extern crate proc_macro;
#[macro_use]
mod util;
mod castable;
mod func;
mod node;
mod symbols;
use proc_macro::TokenStream as BoundaryStream;
use proc_macro2::TokenStream;
use quote::quote;
use syn::ext::IdentExt;
use syn::parse::{Parse, ParseStream, Parser};
use syn::punctuated::Punctuated;
use syn::{parse_quote, Ident, Result, Token};
use unscanny::Scanner;
use self::util::*;
/// Implement `FuncType` for a type or function.
#[proc_macro_attribute]
pub fn func(_: BoundaryStream, item: BoundaryStream) -> BoundaryStream {
let item = syn::parse_macro_input!(item as syn::Item);
func::func(item).unwrap_or_else(|err| err.to_compile_error()).into()
}
/// Implement `Node` for a struct.
#[proc_macro_attribute]
pub fn node(stream: BoundaryStream, item: BoundaryStream) -> BoundaryStream {
let item = syn::parse_macro_input!(item as syn::ItemStruct);
node::node(stream.into(), item)
.unwrap_or_else(|err| err.to_compile_error())
.into()
}
/// Implement `Cast` and optionally `Type` for a type.
#[proc_macro]
pub fn cast_from_value(stream: BoundaryStream) -> BoundaryStream {
castable::cast_from_value(stream.into())
.unwrap_or_else(|err| err.to_compile_error())
.into()
}
/// Implement `From<T> for Value` for a type `T`.
#[proc_macro]
pub fn cast_to_value(stream: BoundaryStream) -> BoundaryStream {
castable::cast_to_value(stream.into())
.unwrap_or_else(|err| err.to_compile_error())
.into()
}
/// Define a list of symbols.
#[proc_macro]
pub fn symbols(stream: BoundaryStream) -> BoundaryStream {
symbols::symbols(stream.into())
.unwrap_or_else(|err| err.to_compile_error())
.into()
}
|