@@ -42,6 +42,25 @@ pub fn descendent_annotations<A: AnnotationFn>(
4242 let mut visitor = AnnotationVisitor {
4343 annotations : Default :: default ( ) ,
4444 annotate,
45+ propagate_up : true ,
46+ } ;
47+ expr. accept ( & mut visitor) . vortex_expect ( "Infallible" ) ;
48+ visitor. annotations
49+ }
50+
51+ /// Walk the expression tree and annotate each expression with zero or more
52+ /// annotations.
53+ ///
54+ /// Returns a map of each expression to all annotations. Annotations of
55+ /// children are not propagated to parents.
56+ pub fn direct_annotations < A : AnnotationFn > (
57+ expr : & Expression ,
58+ annotate : A ,
59+ ) -> Annotations < ' _ , A :: Annotation > {
60+ let mut visitor = AnnotationVisitor {
61+ annotations : Default :: default ( ) ,
62+ annotate,
63+ propagate_up : false ,
4564 } ;
4665 expr. accept ( & mut visitor) . vortex_expect ( "Infallible" ) ;
4766 visitor. annotations
@@ -50,6 +69,7 @@ pub fn descendent_annotations<A: AnnotationFn>(
5069struct AnnotationVisitor < ' a , A : AnnotationFn > {
5170 annotations : Annotations < ' a , A :: Annotation > ,
5271 annotate : A ,
72+ propagate_up : bool ,
5373}
5474
5575impl < ' a , A : AnnotationFn > NodeVisitor < ' a > for AnnotationVisitor < ' a , A > {
@@ -70,6 +90,9 @@ impl<'a, A: AnnotationFn> NodeVisitor<'a> for AnnotationVisitor<'a, A> {
7090 }
7191
7292 fn visit_up ( & mut self , node : & ' a Expression ) -> VortexResult < TraversalOrder > {
93+ if !self . propagate_up {
94+ return Ok ( TraversalOrder :: Continue ) ;
95+ }
7396 let child_annotations = node
7497 . children ( )
7598 . iter ( )
0 commit comments