Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/pgt_lexer/src/lexed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl Lexed<'_> {
}

pub(crate) fn text_range(&self, i: usize) -> TextRange {
assert!(i < self.len());
assert!(i < self.len() - 1);
let lo = self.start[i];
let hi = self.start[i + 1];
TextRange::new(lo.into(), hi.into())
Expand Down
8 changes: 8 additions & 0 deletions crates/pgt_statement_splitter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,4 +519,12 @@ values ('insert', new.id, now());",
"select\n email,\n\n\n from\n auth.users;",
]);
}

#[test]
fn does_not_panic_on_eof_expectation() {
Tester::from("insert").expect_errors(vec![SplitDiagnostic::new(
format!("Expected INTO_KW"),
TextRange::new(0.into(), 6.into()),
)]);
}
}
8 changes: 7 additions & 1 deletion crates/pgt_statement_splitter/src/splitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,15 @@ impl<'a> Splitter<'a> {
if self.current() == kind {
self.advance();
} else {
let token = if self.current() == SyntaxKind::EOF {
self.current_pos - 1
} else {
self.current_pos
};

self.errors.push(SplitError {
msg: format!("Expected {:#?}", kind),
token: self.current_pos,
token,
});
}
}
Expand Down
Loading