2 releases

0.0.2 Aug 25, 2023
0.0.1 Feb 25, 2023

#2041 in Procedural macros

Download history 15/week @ 2023-05-14 5/week @ 2023-05-21 26/week @ 2023-05-28 15/week @ 2023-06-04 7/week @ 2023-06-11 36/week @ 2023-06-18 22/week @ 2023-06-25 28/week @ 2023-07-02 12/week @ 2023-07-09 20/week @ 2023-07-16 16/week @ 2023-07-23 9/week @ 2023-07-30 17/week @ 2023-08-06 21/week @ 2023-08-13 48/week @ 2023-08-20 24/week @ 2023-08-27

110 downloads per month
Used in 4 crates (via ezno-parser)

MIT license

7KB
106 lines

visiting-proc-macro lines of code

A package which generates mutable and immutable visiting implementations for AST nodes.

A visitor is a implementor a trait of which the a function is called of a each node.

This module is specific for the parser module and contains the ability to extend with data.

Usage

use visitable_derive::Visitable;

#[derive(Visitable)]
struct MyAstNode {
    ...
}

Attributes

visit_self

Will visit all fields first then self

#[derive(Visitable)]
#[visit_self]
struct MyAstNode {
    ...
}

Options:

  • also_visit_first_if Will visit self additionally before if predicate is true
#[derive(Visitable)]
#[visit_self(also_visit_first_if="self.predicate()"]
struct MyAstNode {
    ...
}

impl MyAstNode {
    fn predicate(&self) -> bool {
        ...
    }
}

visit_skip_field

Skips visiting the field. Used if type does not implement Visitable

#[derive(Visitable)]
struct MyAstNode {
    #[visit_skip_field]
    a: String
}

Dependencies

~1.5MB
~32K SLoC