|
17 | 17 |
|
18 | 18 | //! Recursive visitors for ast Nodes. See [`Visitor`] for more details. |
19 | 19 |
|
20 | | -use crate::ast::{Expr, ObjectName, Query, Statement, TableFactor, Value}; |
| 20 | +use crate::ast::{ |
| 21 | + Expr, Function, GroupByExpr, ObjectName, OrderBy, Query, SelectItem, Statement, TableFactor, |
| 22 | + Value, |
| 23 | +}; |
21 | 24 | use core::ops::ControlFlow; |
| 25 | +use sqlparser::ast::Ident; |
22 | 26 |
|
23 | 27 | /// A type that can be visited by a [`Visitor`]. See [`Visitor`] for |
24 | 28 | /// recursively visiting parsed SQL statements. |
@@ -243,6 +247,66 @@ pub trait Visitor { |
243 | 247 | fn post_visit_value(&mut self, _value: &Value) -> ControlFlow<Self::Break> { |
244 | 248 | ControlFlow::Continue(()) |
245 | 249 | } |
| 250 | + |
| 251 | + /// Invoked for any Identifier that appear in the AST before visiting children |
| 252 | + fn pre_visit_ident(&mut self, _ident: &Ident) -> ControlFlow<Self::Break> { |
| 253 | + ControlFlow::Continue(()) |
| 254 | + } |
| 255 | + |
| 256 | + /// Invoked for any Identifier that appear in the AST after visiting children |
| 257 | + fn post_visit_ident(&mut self, _ident: &Ident) -> ControlFlow<Self::Break> { |
| 258 | + ControlFlow::Continue(()) |
| 259 | + } |
| 260 | + |
| 261 | + /// Invoked for any functions that appear in the AST before visiting children |
| 262 | + fn pre_visit_function(&mut self, _function: &Function) -> ControlFlow<Self::Break> { |
| 263 | + ControlFlow::Continue(()) |
| 264 | + } |
| 265 | + |
| 266 | + /// Invoked for any functions that appear in the AST after visiting children |
| 267 | + fn post_visit_function(&mut self, _function: &Function) -> ControlFlow<Self::Break> { |
| 268 | + ControlFlow::Continue(()) |
| 269 | + } |
| 270 | + |
| 271 | + /// Invoked for any SelectItem that appear in the AST before visiting children |
| 272 | + fn pre_visit_select_item(&mut self, _select_item: &SelectItem) -> ControlFlow<Self::Break> { |
| 273 | + ControlFlow::Continue(()) |
| 274 | + } |
| 275 | + |
| 276 | + /// Invoked for any SelectItem that appear in the AST after visiting children |
| 277 | + fn post_visit_select_item(&mut self, _select_item: &SelectItem) -> ControlFlow<Self::Break> { |
| 278 | + ControlFlow::Continue(()) |
| 279 | + } |
| 280 | + |
| 281 | + /// Invoked for Where Expr that appear in the AST before visiting children |
| 282 | + fn pre_visit_where(&mut self, _where: &Expr) -> ControlFlow<Self::Break> { |
| 283 | + ControlFlow::Continue(()) |
| 284 | + } |
| 285 | + |
| 286 | + /// Invoked for Where Expr that appear in the AST after visiting children |
| 287 | + fn post_visit_where(&mut self, _where: &Expr) -> ControlFlow<Self::Break> { |
| 288 | + ControlFlow::Continue(()) |
| 289 | + } |
| 290 | + |
| 291 | + /// Invoked for any GroupBy Expr that appear in the AST before visiting children |
| 292 | + fn pre_visit_group_by_expr(&mut self, _group_by: &GroupByExpr) -> ControlFlow<Self::Break> { |
| 293 | + ControlFlow::Continue(()) |
| 294 | + } |
| 295 | + |
| 296 | + /// Invoked for any GroupBy Expr that appear in the AST after visiting children |
| 297 | + fn post_visit_group_by_expr(&mut self, _group_by: &GroupByExpr) -> ControlFlow<Self::Break> { |
| 298 | + ControlFlow::Continue(()) |
| 299 | + } |
| 300 | + |
| 301 | + /// Invoked for any OrderBy Expr that appear in the AST before visiting children |
| 302 | + fn pre_visit_order_by(&mut self, _order_by: &OrderBy) -> ControlFlow<Self::Break> { |
| 303 | + ControlFlow::Continue(()) |
| 304 | + } |
| 305 | + |
| 306 | + /// Invoked for any OrderBy Expr that appear in the AST after visiting children |
| 307 | + fn post_visit_order_by(&mut self, _order_by: &OrderBy) -> ControlFlow<Self::Break> { |
| 308 | + ControlFlow::Continue(()) |
| 309 | + } |
246 | 310 | } |
247 | 311 |
|
248 | 312 | /// A visitor that can be used to mutate an AST tree. |
@@ -357,6 +421,62 @@ pub trait VisitorMut { |
357 | 421 | fn post_visit_value(&mut self, _value: &mut Value) -> ControlFlow<Self::Break> { |
358 | 422 | ControlFlow::Continue(()) |
359 | 423 | } |
| 424 | + |
| 425 | + /// Invoked for any functions that appear in the AST before visiting children |
| 426 | + fn pre_visit_function(&mut self, _function: &mut Function) -> ControlFlow<Self::Break> { |
| 427 | + ControlFlow::Continue(()) |
| 428 | + } |
| 429 | + |
| 430 | + /// Invoked for any functions that appear in the AST after visiting children |
| 431 | + fn post_visit_function(&mut self, _function: &mut Function) -> ControlFlow<Self::Break> { |
| 432 | + ControlFlow::Continue(()) |
| 433 | + } |
| 434 | + |
| 435 | + /// Invoked for any SelectItem that appear in the AST before visiting children |
| 436 | + fn pre_visit_select_item(&mut self, _select_item: &mut SelectItem) -> ControlFlow<Self::Break> { |
| 437 | + ControlFlow::Continue(()) |
| 438 | + } |
| 439 | + |
| 440 | + /// Invoked for any SelectItem that appear in the AST after visiting children |
| 441 | + fn post_visit_select_item( |
| 442 | + &mut self, |
| 443 | + _select_item: &mut SelectItem, |
| 444 | + ) -> ControlFlow<Self::Break> { |
| 445 | + ControlFlow::Continue(()) |
| 446 | + } |
| 447 | + |
| 448 | + /// Invoked for Where Expr that appear in the AST before visiting children |
| 449 | + fn pre_visit_where(&mut self, _where: &mut Expr) -> ControlFlow<Self::Break> { |
| 450 | + ControlFlow::Continue(()) |
| 451 | + } |
| 452 | + |
| 453 | + /// Invoked for Where Expr that appear in the AST after visiting children |
| 454 | + fn post_visit_where(&mut self, _where: &mut Expr) -> ControlFlow<Self::Break> { |
| 455 | + ControlFlow::Continue(()) |
| 456 | + } |
| 457 | + |
| 458 | + /// Invoked for any GroupBy Expr that appear in the AST before visiting children |
| 459 | + fn pre_visit_group_by_expr(&mut self, _group_by: &mut GroupByExpr) -> ControlFlow<Self::Break> { |
| 460 | + ControlFlow::Continue(()) |
| 461 | + } |
| 462 | + |
| 463 | + /// Invoked for any GroupBy Expr that appear in the AST after visiting children |
| 464 | + fn post_visit_group_by_expr( |
| 465 | + &mut self, |
| 466 | + _group_by: &mut GroupByExpr, |
| 467 | + ) -> ControlFlow<Self::Break> { |
| 468 | + ControlFlow::Continue(()) |
| 469 | + } |
| 470 | + |
| 471 | + /// Invoked for any OrderBy Expr that appear in the AST before visiting children |
| 472 | + fn pre_visit_order_by(&mut self, _order_by: &mut OrderBy) -> ControlFlow<Self::Break> { |
| 473 | + ControlFlow::Continue(()) |
| 474 | + } |
| 475 | + |
| 476 | + /// Invoked for any OrderBy Expr that appear in the AST after visiting children |
| 477 | + fn post_visit_order_by(&mut self, _order_by: &mut OrderBy) -> ControlFlow<Self::Break> { |
| 478 | + ControlFlow::Continue(()) |
| 479 | + } |
360 | 480 | } |
361 | 481 |
|
362 | 482 | struct RelationVisitor<F>(F); |
|
0 commit comments