| 1 | // Copyright (c) Meta Platforms, Inc. and affiliates. |
| 2 | // |
| 3 | // This source code is licensed under the MIT license found in the |
| 4 | // LICENSE file in the root directory of this source tree |
| 5 | |
| 6 | mod inflate; |
| 7 | use inflate::impl_inflate; |
| 8 | mod parenthesized_node; |
| 9 | use parenthesized_node::impl_parenthesized_node; |
| 10 | mod codegen; |
| 11 | use codegen::impl_codegen; |
| 12 | mod into_py; |
| 13 | use into_py::impl_into_py; |
| 14 | mod cstnode; |
| 15 | use cstnode::{impl_cst_node, CSTNodeParams}; |
| 16 | |
| 17 | use proc_macro::TokenStream; |
| 18 | use syn::{parse_macro_input, DeriveInput}; |
| 19 | |
| 20 | #[proc_macro_derive(Inflate)] |
| 21 | pub fn inflate_derive(input: TokenStream) -> TokenStream { |
| 22 | let ast = syn::parse(input).unwrap(); |
| 23 | impl_inflate(&ast) |
| 24 | } |
| 25 | |
| 26 | #[proc_macro_derive(ParenthesizedNode)] |
| 27 | pub fn parenthesized_node_derive(input: TokenStream) -> TokenStream { |
| 28 | impl_parenthesized_node(&syn::parse(input).unwrap(), false) |
| 29 | } |
| 30 | |
| 31 | #[proc_macro_derive(ParenthesizedDeflatedNode)] |
| 32 | pub fn parenthesized_deflated_node_derive(input: TokenStream) -> TokenStream { |
| 33 | impl_parenthesized_node(&syn::parse(input).unwrap(), true) |
| 34 | } |
| 35 | |
| 36 | #[proc_macro_derive(Codegen)] |
| 37 | pub fn codegen_derive(input: TokenStream) -> TokenStream { |
| 38 | impl_codegen(&syn::parse(input).unwrap()) |
| 39 | } |
| 40 | |
| 41 | #[proc_macro_derive(TryIntoPy, attributes(skip_py, no_py_default))] |
| 42 | pub fn into_py(input: TokenStream) -> TokenStream { |
| 43 | impl_into_py(&syn::parse(input).unwrap()) |
| 44 | } |
| 45 | |
| 46 | #[proc_macro_attribute] |
| 47 | pub fn cst_node(args: TokenStream, input: TokenStream) -> TokenStream { |
| 48 | let args = parse_macro_input!(args as CSTNodeParams); |
| 49 | impl_cst_node(parse_macro_input!(input as DeriveInput), args) |
| 50 | } |