|
12 | 12 |
|
13 | 13 | //! Recursive visitors for ast Nodes. See [`Visitor`] for more details.
|
14 | 14 |
|
15 |
| -use crate::ast::{Expr, ObjectName, Statement}; |
| 15 | +use crate::ast::{Expr, FunctionArgExpr, ObjectName, Statement}; |
16 | 16 | use core::ops::ControlFlow;
|
17 |
| - |
18 | 17 | /// A type that can be visited by a [`Visitor`]. See [`Visitor`] for
|
19 | 18 | /// recursively visiting parsed SQL statements.
|
20 | 19 | ///
|
@@ -199,6 +198,15 @@ pub trait Visitor {
|
199 | 198 | ControlFlow::Continue(())
|
200 | 199 | }
|
201 | 200 |
|
| 201 | + /// Invoked for function arguments that appear in the AST before visiting children |
| 202 | + fn pre_visit_function_arg(&mut self, _expr: &FunctionArgExpr) -> ControlFlow<Self::Break> { |
| 203 | + ControlFlow::Continue(()) |
| 204 | + } |
| 205 | + |
| 206 | + /// Invoked for any function arguments that appear in the AST after visiting children |
| 207 | + fn post_visit_function_arg(&mut self, _expr: &FunctionArgExpr) -> ControlFlow<Self::Break> { |
| 208 | + ControlFlow::Continue(()) |
| 209 | + } |
202 | 210 | /// Invoked for any statements that appear in the AST before visiting children
|
203 | 211 | fn pre_visit_statement(&mut self, _statement: &Statement) -> ControlFlow<Self::Break> {
|
204 | 212 | ControlFlow::Continue(())
|
@@ -277,6 +285,16 @@ pub trait VisitorMut {
|
277 | 285 | ControlFlow::Continue(())
|
278 | 286 | }
|
279 | 287 |
|
| 288 | + /// Invoked for function arguments that appear in the AST before visiting children |
| 289 | + fn pre_visit_function_arg(&mut self, _expr: &mut FunctionArgExpr) -> ControlFlow<Self::Break> { |
| 290 | + ControlFlow::Continue(()) |
| 291 | + } |
| 292 | + |
| 293 | + /// Invoked for any function arguments that appear in the AST after visiting children |
| 294 | + fn post_visit_function_arg(&mut self, _expr: &mut FunctionArgExpr) -> ControlFlow<Self::Break> { |
| 295 | + ControlFlow::Continue(()) |
| 296 | + } |
| 297 | + |
280 | 298 | /// Invoked for any statements that appear in the AST before visiting children
|
281 | 299 | fn pre_visit_statement(&mut self, _statement: &mut Statement) -> ControlFlow<Self::Break> {
|
282 | 300 | ControlFlow::Continue(())
|
@@ -376,6 +394,42 @@ where
|
376 | 394 | ControlFlow::Continue(())
|
377 | 395 | }
|
378 | 396 |
|
| 397 | +struct FunctionArgExprVisitor<F>(F); |
| 398 | + |
| 399 | +impl<E, F: FnMut(&FunctionArgExpr) -> ControlFlow<E>> Visitor for FunctionArgExprVisitor<F> { |
| 400 | + type Break = E; |
| 401 | + |
| 402 | + fn pre_visit_function_arg(&mut self, expr: &FunctionArgExpr) -> ControlFlow<Self::Break> { |
| 403 | + self.0(expr) |
| 404 | + } |
| 405 | +} |
| 406 | + |
| 407 | +impl<E, F: FnMut(&mut FunctionArgExpr) -> ControlFlow<E>> VisitorMut for FunctionArgExprVisitor<F> { |
| 408 | + type Break = E; |
| 409 | + |
| 410 | + fn post_visit_function_arg(&mut self, expr: &mut FunctionArgExpr) -> ControlFlow<Self::Break> { |
| 411 | + self.0(expr) |
| 412 | + } |
| 413 | +} |
| 414 | + |
| 415 | +pub fn visit_function_arguments<V, E, F>(v: &V, f: F) -> ControlFlow<E> |
| 416 | +where |
| 417 | + V: Visit, |
| 418 | + F: FnMut(&FunctionArgExpr) -> ControlFlow<E>, |
| 419 | +{ |
| 420 | + let mut visitor = FunctionArgExprVisitor(f); |
| 421 | + v.visit(&mut visitor)?; |
| 422 | + ControlFlow::Continue(()) |
| 423 | +} |
| 424 | +pub fn visit_function_arguments_mut<V, E, F>(v: &mut V, f: F) -> ControlFlow<E> |
| 425 | +where |
| 426 | + V: VisitMut, |
| 427 | + F: FnMut(&mut FunctionArgExpr) -> ControlFlow<E>, |
| 428 | +{ |
| 429 | + v.visit(&mut FunctionArgExprVisitor(f))?; |
| 430 | + ControlFlow::Continue(()) |
| 431 | +} |
| 432 | + |
379 | 433 | struct ExprVisitor<F>(F);
|
380 | 434 |
|
381 | 435 | impl<E, F: FnMut(&Expr) -> ControlFlow<E>> Visitor for ExprVisitor<F> {
|
@@ -432,7 +486,6 @@ where
|
432 | 486 | v.visit(&mut visitor)?;
|
433 | 487 | ControlFlow::Continue(())
|
434 | 488 | }
|
435 |
| - |
436 | 489 | /// Invokes the provided closure iteratively with a mutable reference to all expressions
|
437 | 490 | /// present in `v`.
|
438 | 491 | ///
|
|
0 commit comments