aboutsummaryrefslogtreecommitdiff
path: root/graph_macro
diff options
context:
space:
mode:
Diffstat (limited to 'graph_macro')
-rw-r--r--graph_macro/src/lib.rs51
1 files changed, 38 insertions, 13 deletions
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<impl Iterator<Item = TokenTree>>,
+) -> Result<TokenStream, CompileError> {
+ let mut trees: Vec<TokenTree> = 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<impl Iterator<Item = TokenTree>>,
) -> Result<Vec<Generic>, CompileError> {