Skip to content

Parse visitor#18

Merged
antialize merged 3 commits intomainfrom
parse_visitor
Apr 28, 2026
Merged

Parse visitor#18
antialize merged 3 commits intomainfrom
parse_visitor

Conversation

@antialize
Copy link
Copy Markdown
Owner

No description provided.

Adds a `Visitor<'a>` trait with associated types `T: Default` and `E`,
with four `visit_*` methods that default to walking all children.
Public `walk_statement`, `walk_expression`, `walk_select`, and
`walk_table_reference` free functions are also exported so callers can
delegate back to the default traversal from within a custom visitor.
Store the closing ')' span in all AST structs where it was previously
parsed and discarded. This ensures that Spanned::span() for an expression
or definition covers the full source text including any trailing delimiter.

Affected structs:
- expression.rs: InExpression, MemberOfExpression, CastExpression,
  ConvertExpression, GroupConcatExpression, TrimExpression,
  ExtractExpression, TimestampAddExpression, TimestampDiffExpression,
  MatchAgainstExpression, ExistsExpression, QuantifierExpression
- function_expression.rs: WindowSpec
- alter_table.rs: AddIndex (cols_r_paren)
- create_table.rs: CreateDefinition index/foreign key variants
- insert_replace.rs: InsertReplace (columns span)
- operator.rs: CreateOperatorFamily (full span)
- select.rs: Select (locking clause span)
@antialize antialize requested a review from Copilot April 28, 2026 17:46
@antialize antialize merged commit 0e20319 into main Apr 28, 2026
10 checks passed
@antialize antialize deleted the parse_visitor branch April 28, 2026 17:53
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a reusable AST visitor/walker API to qusql-parse and improves Span accuracy across many AST nodes by capturing closing-paren spans, then bumps qusql-parse to 0.7.0 and updates downstream dependency.

Changes:

  • Introduce Visitor + walk_* traversal functions for Statement, Expression, Select, and TableReference (qusql-parse/src/visit.rs) and re-export them from lib.rs.
  • Improve Spanned accuracy by tracking closing ) spans across expressions/functions/window specs and several DDL/ALTER constructs.
  • Bump qusql-parse crate version to 0.7.0 and update qusql-type to depend on it.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
qusql-type/Cargo.toml Updates dependency on qusql-parse to 0.7.0.
qusql-parse/Cargo.toml Bumps crate version to 0.7.0.
qusql-parse/src/lib.rs Adds visit module + re-exports visitor/walk APIs.
qusql-parse/src/visit.rs New visitor/walker implementation for AST traversal.
qusql-parse/src/select.rs Ensures Select::span() includes locking clause span.
qusql-parse/src/operator.rs Expands CreateOperatorFamily::span() to include child spans.
qusql-parse/src/insert_replace.rs Ensures InsertReplace::span() includes column list span.
qusql-parse/src/function_expression.rs Adds r_paren_span to function/window nodes and updates parsing + spans.
qusql-parse/src/expression.rs Adds closing-paren spans to multiple expression nodes and updates parsing + spans.
qusql-parse/src/create_table.rs Adds closing-paren spans for column/definition lists and updates parsing + spans.
qusql-parse/src/alter_table.rs Returns closing-paren spans from column-list parsers and threads them into AST + spans.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread qusql-parse/src/visit.rs
Comment on lines +401 to +482
// -- Leaf statements (DDL, TCL, SHOW, ...) -------------------------------------
// These have no child expressions or statements to recurse into.
Statement::AlterSchema(_)
| Statement::AlterTable(_)
| Statement::AlterRole(_)
| Statement::AlterType(_)
| Statement::AlterOperator(_)
| Statement::AlterOperatorClass(_)
| Statement::AlterOperatorFamily(_)
| Statement::CreateIndex(_)
| Statement::CreateTable(_)
| Statement::CreateView(_)
| Statement::CreateTrigger(_)
| Statement::CreateFunction(_)
| Statement::CreateProcedure(_)
| Statement::CreateDatabase(_)
| Statement::CreateSchema(_)
| Statement::CreateSequence(_)
| Statement::CreateServer(_)
| Statement::CreateRole(_)
| Statement::CreateOperator(_)
| Statement::CreateTypeEnum(_)
| Statement::CreateOperatorClass(_)
| Statement::CreateOperatorFamily(_)
| Statement::CreateExtension(_)
| Statement::CreateDomain(_)
| Statement::CreateConstraintTrigger(_)
| Statement::CreateTablePartitionOf(_)
| Statement::DropIndex(_)
| Statement::DropTable(_)
| Statement::DropFunction(_)
| Statement::DropProcedure(_)
| Statement::DropSequence(_)
| Statement::DropEvent(_)
| Statement::DropDatabase(_)
| Statement::DropServer(_)
| Statement::DropTrigger(_)
| Statement::DropView(_)
| Statement::DropExtension(_)
| Statement::DropOperator(_)
| Statement::DropOperatorFamily(_)
| Statement::DropOperatorClass(_)
| Statement::DropDomain(_)
| Statement::DropType(_)
| Statement::RenameTable(_)
| Statement::TruncateTable(_)
| Statement::RefreshMaterializedView(_)
| Statement::CommentOn(_)
| Statement::Signal(_)
| Statement::Kill(_)
| Statement::ShowTables(_)
| Statement::ShowDatabases(_)
| Statement::ShowProcessList(_)
| Statement::ShowVariables(_)
| Statement::ShowStatus(_)
| Statement::ShowColumns(_)
| Statement::ShowCreateTable(_)
| Statement::ShowCreateDatabase(_)
| Statement::ShowCreateView(_)
| Statement::ShowCharacterSet(_)
| Statement::ShowCollation(_)
| Statement::ShowEngines(_)
| Statement::Flush(_)
| Statement::Unlock(_)
| Statement::Lock(_)
| Statement::Begin(_)
| Statement::End(_)
| Statement::Commit(_)
| Statement::StartTransaction(_)
| Statement::CopyFrom(_)
| Statement::CopyTo(_)
| Statement::Stdin(_)
| Statement::OpenCursor(_)
| Statement::CloseCursor(_)
| Statement::FetchCursor(_)
| Statement::Leave(_)
| Statement::Iterate(_)
| Statement::Grant(_)
| Statement::ExecuteFunction(_)
| Statement::Analyze(_)
| Statement::Invalid(_) => Ok(V::T::default()),
}
Comment thread qusql-parse/src/visit.rs
walk_table_reference(self, tr)
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants