use macro_types::{ expr::{ConstructorFields, MatchVariant}, name::{Name, Path}, tyref::TyRef, }; use macro_types_helpers::{Combinator, ToTokens}; use proc_macro2::TokenStream; use quote::ToTokens; #[derive(Combinator, ToTokens)] pub enum Expr { #[to_tokens = "()"] Unit, String(String), Number(usize), Variable(Path), #[to_tokens = "#value.#field"] Field { value: Box, field: Name, }, #[to_tokens = "#value.#index"] Index { value: Box, index: syn::Index, }, #[to_tokens = "#0?"] Unwrap(Box), #[to_tokens = "##0"] PrependPound(Box), #[to_tokens = "$#0"] PrependDollar(Box), #[to_tokens = "#variable = #value"] Assign { variable: Box, value: Box, }, #[to_tokens = "let #variable = #value"] LetAssign { variable: Box, value: Box, }, #[to_tokens = "#func(#(#args),*)"] Call { func: Box, args: Vec, }, #[to_tokens = "#func!(#(#args),*)"] CallMacro { func: Box, args: Vec, }, #[to_tokens = "&#value"] Reference { value: Box, }, #[to_tokens = "()"] Block(Vec), #[to_tokens = "#owner #fields"] Constructor { owner: TyRef, fields: ConstructorFields, }, #[to_tokens = "match #value { #(#variants),* }"] MatchExpr { value: Box, variants: Vec, }, TokensStream(TokenStream), } impl<'a> From<&'a str> for Expr { fn from(value: &'a str) -> Self { Expr::Variable(value.into()) } } fn main() { let value = Expr::Unit; let value = value .field("Hello") .index(0) .assign("bonjour".unwrap()); println!("{}", value.into_token_stream()); }