Skip to content

Commit

Permalink
feat(ast_tools): support #[scope(exit_after)]
Browse files Browse the repository at this point in the history
  • Loading branch information
DonIsaac committed Oct 7, 2024
1 parent a1e0d30 commit 35d6a35
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions tasks/ast_tools/src/generators/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ impl<'a> VisitBuilder<'a> {
let visit_args = markers.visit.visit_args.clone();

let have_enter_scope = markers.scope.enter_before;
let have_exit_scope = markers.scope.exit_after;
let have_enter_node = markers.visit.enter_before;

let (args_def, args) = visit_args
Expand Down Expand Up @@ -525,6 +526,13 @@ impl<'a> VisitBuilder<'a> {
};
enter_scope_at = ix;
}
if have_exit_scope {
let scope_leave = &scope_events.1;
result = quote! {
#result
#scope_leave
};
}

#[expect(unreachable_code)]
if have_enter_node {
Expand Down
8 changes: 7 additions & 1 deletion tasks/ast_tools/src/markers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ pub struct VisitMarkers {
/// A struct representing `#[scope(...)]` markers
#[derive(Default, Debug)]
pub struct ScopeMarkers {
/// `#[scope(enter_before)]`
pub enter_before: bool,
/// `#[scope(exit_after)]`
pub exit_after: bool,
}

/// A struct representing all the helper attributes that might be used with `#[generate_derive(...)]`
Expand Down Expand Up @@ -204,7 +207,10 @@ where
|| Ok(ScopeMarkers::default()),
|attr| {
attr.parse_args_with(Ident::parse)
.map(|id| ScopeMarkers { enter_before: id == "enter_before" })
.map(|id| ScopeMarkers {
enter_before: id == "enter_before",
exit_after: id == "exit_after",
})
.normalize()
},
)
Expand Down

0 comments on commit 35d6a35

Please sign in to comment.