Skip to content

Commit

Permalink
recursively process generic args
Browse files Browse the repository at this point in the history
  • Loading branch information
StuartHarris committed Oct 28, 2024
1 parent b4aff89 commit 4f104e2
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions crux_cli/src/codegen/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,8 @@ pub fn parse(crate_: &Crate) -> Result<String> {
prog.edge
.push((source.clone(), dest.clone(), Edge::ForType));

// TODO: make recursive
if let Some(args) = &path.args {
if let GenericArgs::AngleBracketed { args, .. } = args.as_ref() {
for arg in args {
if let GenericArg::Type(t) = arg {
if let Type::ResolvedPath(path) = t {
let Some(dest) = node_by_id(&path.id) else {
continue;
};
prog.edge.push((
source.clone(),
dest.clone(),
Edge::ForType,
));
};
}
}
}
process_args(source, args.as_ref(), &node_by_id, &mut prog);
}
}
_ => (),
Expand Down Expand Up @@ -282,6 +266,32 @@ pub fn parse(crate_: &Crate) -> Result<String> {
Ok(format!(""))
}

fn process_args<'a>(
source: &Node,
args: &GenericArgs,
node_by_id: &impl Fn(&Id) -> Option<&'a Node>,
prog: &mut AscentProgram,
) {
if let GenericArgs::AngleBracketed { args, .. } = args {
for arg in args {
if let GenericArg::Type(t) = arg {
if let Type::ResolvedPath(path) = t {
let Some(dest) = node_by_id(&path.id) else {
continue;
};
prog.edge
.push((source.clone(), dest.clone(), Edge::ForType));

if let Some(args) = &path.args {
let generic_args = args.as_ref();
process_args(source, generic_args, node_by_id, prog);
}
};
}
}
}
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
struct Node {
id: Id,
Expand Down

0 comments on commit 4f104e2

Please sign in to comment.