From fba9a90cfc6aca2a26cce72f55fb261789139781 Mon Sep 17 00:00:00 2001 From: JSDurand Date: Fri, 16 Oct 2026 14:01:01 +0800 Subject: new start Now I tested and discussed with claude, and had a working version of this project. The rest is to port the claude version to my own writings. So this serves as the starting point before that attempt. In the new attempt the design is better, and a number of bugs were found and supposedly fixed, so let us see how this goes at the end. --- graph_macro/src/lib.rs | 51 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 13 deletions(-) (limited to 'graph_macro/src') diff --git a/graph_macro/src/lib.rs b/graph_macro/src/lib.rs index 409e6db..5f82658 100644 --- a/graph_macro/src/lib.rs +++ b/graph_macro/src/lib.rs @@ -19,6 +19,7 @@ enum VisibilityMod { /// Since the restrictions can be given in a variety of ways, and /// since it does not matter to us, we just keep them as a /// tokentree. + #[allow(dead_code)] PubRes(TokenTree), #[default] Private, @@ -206,7 +207,7 @@ pub fn graph_derive(input: TokenStream) -> TokenStream { result }; - let result = format!( + let result = format!( " #[automatically_derived] impl{generics_impl_string} graph::Graph for {name}{generic_struct_string} {{ @@ -405,12 +406,7 @@ fn get_graph_field_name_type( return end_of_input; } - let mut result_type = get_until( - &mut cloned_body, - |tree| matches!(tree, TokenTree::Punct(p) if p.as_char() == ','), - true, - true, - )?; + let mut result_type = get_field_type(&mut cloned_body)?; let mut result = (result_name, result_type); @@ -448,12 +444,7 @@ fn get_graph_field_name_type( move_punct(&mut body, ':')?; - result_type = get_until( - &mut body, - |tree| matches!(tree, TokenTree::Punct(p) if p.as_char() == ','), - true, - true, - )?; + result_type = get_field_type(&mut body)?; result = (result_name, result_type); @@ -479,6 +470,40 @@ fn get_graph_field_name_type( } } +fn get_field_type( + input: &mut Peekable>, +) -> Result { + let mut trees: Vec = Vec::new(); + + let mut found_angle_bracket = 0usize; + + for tree in input.by_ref() { + match &tree { + TokenTree::Punct(p) => { + match p.as_char() { + '<' => { + found_angle_bracket += 1; + } + '>' => { + found_angle_bracket -= 1; + } + ',' if found_angle_bracket == 0 => { + break; + } + _ => {} + } + + trees.push(tree); + } + _ => { + trees.push(tree); + } + } + } + + Ok(trees.into_iter().collect()) +} + fn get_generics( input: &mut Peekable>, ) -> Result, CompileError> { -- cgit v1.2.3-18-g5258