Skip to content

naive statement splitter #142

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

Merged
merged 13 commits into from
Oct 21, 2024
Merged

naive statement splitter #142

merged 13 commits into from
Oct 21, 2024

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
Collaborator

@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.

// delete(p);
}
t => {
panic!("stmt: Unknown token {:?}", t);
Copy link
Collaborator

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);

@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

@psteinroe psteinroe marked this pull request as ready for review October 20, 2024 15:43
@psteinroe
Copy link
Collaborator Author

@juleswritescode I think this is ready now. dml statements should work good enough.

Copy link
Collaborator

@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.

amazing work 💪

@@ -1,12 +0,0 @@
brin
Copy link
Collaborator

Choose a reason for hiding this comment

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

YEAH ⛹️

r.start(),
r.end() + TextSize::from(self.diff_size()),
);
*r = TextRange::new(r.start(), r.end() + self.diff_size());
Copy link
Collaborator

Choose a reason for hiding this comment

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

hmm, strange that there's no method on the type for increasing the range 🤷

Comment on lines +49 to +51
statement_ranges: text.as_ref().map_or_else(Vec::new, |f| {
pg_statement_splitter::split(f).ranges.to_vec()
}),
Copy link
Collaborator

Choose a reason for hiding this comment

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

pretty cool changes here in the file!

Comment on lines +181 to +184
self.errors.push(SyntaxError::new(
format!("Expected {:#?}", kind),
self.peek().span,
));
Copy link
Collaborator

Choose a reason for hiding this comment

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

very nice! much cleaner.

@psteinroe psteinroe merged commit b930638 into main Oct 21, 2024
1 check passed
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