Skip to content

Add replace methods to VisitorMut for node substitution - #365

Open
PY44N wants to merge 1 commit into
Kampfkarren:mainfrom
PY44N:feature/visitor-mut-replace
Open

PY44N wants to merge 1 commit into
Kampfkarren:mainfrom
PY44N:feature/visitor-mut-replace

Conversation

@PY44N

@PY44N PY44N commented Sep 4, 2026

Copy link
Copy Markdown

Adds a replace_X method for every AST node type on VisitorMut (e.g. replace_local_assignment, replace_expression). Returning Some(replacement) substitutes the node and skips it entirely — visit_X, visit_X_end, and recursion into both the original node and the replacement's own children are all skipped. Returning None (the default) falls through to the normal visit_X / recurse / visit_X_end flow.

This is something I wanted for a project I was working on. I fully understand if this isn't something you want upstream, but also happy to adjust the design/implementation if it is something you'd be interested in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant