Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

naive statement splitter #142

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft

naive statement splitter #142

wants to merge 8 commits into from

Conversation

psteinroe
Copy link
Collaborator

@psteinroe psteinroe commented Oct 4, 2024

naive attempt at splitting statements.

implements the splitter as a simple Pratt Parser. The approach now is the opposite of what I tried before: Instead of assuming it works perfectly as long as we cover all possible edge cases, we assume it does not work at all. We want to make all important cases work (mostly DML, a few DDL statements), while asking the user to fallback to a double newline if they are seeing weird things coming from the lsp.

  • make it work well for all dml statements and all create (or replace) ddl statements

@psteinroe psteinroe changed the title fix: save naive statement splitter Oct 4, 2024
Copy link
Contributor

@juleswritescode juleswritescode left a comment

Choose a reason for hiding this comment

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

Wow, this is so much simpler than the previous implementation. I love it.

crates/pg_statement_splitter/src/lib.rs Outdated Show resolved Hide resolved
crates/pg_statement_splitter/src/lib.rs Show resolved Hide resolved
crates/pg_statement_splitter/src/parser.rs Outdated Show resolved Hide resolved
crates/pg_statement_splitter/src/parser/data.rs Outdated Show resolved Hide resolved
// delete(p);
}
t => {
panic!("stmt: Unknown token {:?}", t);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
panic!("stmt: Unknown token {:?}", t);
panic!("stmt: Unknown start token {:?}", t);

crates/pg_statement_splitter/src/parser.rs Outdated Show resolved Hide resolved
crates/pg_statement_splitter/src/parser.rs Outdated Show resolved Hide resolved
crates/pg_statement_splitter/src/parser.rs Outdated Show resolved Hide resolved
@psteinroe
Copy link
Collaborator Author

psteinroe commented Oct 18, 2024

@juleswritescode I refactored the parser to work with an index into the vector. this comes with a few benefits:

  • no cloning
  • no "save last token" anymore
  • just a single pass over tokens since we do not filter and clone on init
  • no impact for the user of the parser

edit: added a little test helper

fn advance(&mut self) -> &Token {
let mut first_relevant_token = None;
loop {
let token = self.tokens.get(self.next_pos).unwrap_or(&self.eof_token);
Copy link
Contributor

Choose a reason for hiding this comment

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

self.peek? 🤓

crates/pg_statement_splitter/src/lib.rs Show resolved Hide resolved
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