syn icon indicating copy to clipboard operation
syn copied to clipboard

Methods to get name of visit, visit_mut, fold methods as ident

Open dtolnay opened this issue 5 years ago • 0 comments

As part of the library from #607 -- users will want to generate code that calls visitor / folder methods on specific syntax tree node types.

Something like:

impl Node {
    pub fn name_of_visit_method(&self) -> Ident;
    pub fn name_of_visit_mut_method(&self) -> Ident;
    pub fn name_of_fold_method(&self) -> Ident;
}

where e.g. the "Expr" node would return "visit_expr", "visit_expr_mut", "fold_expr".

A code generator could guess these method names by using the inflections crate and mirroring what our codegen does, but that is annoying.

Ident::new(&format!("visit_{}", node.ident.to_snake_case()), Span::call_site())

dtolnay avatar Mar 24 '19 22:03 dtolnay