Skip to content

Commit 58c0374

Browse files
committed
fix: address pr feedback
1 parent 0d757f6 commit 58c0374

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

crates/pg_statement_splitter/src/parser.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ mod dml;
44

55
pub use common::source;
66

7-
use std::cmp::min;
8-
97
use pg_lexer::{lex, SyntaxKind, Token, WHITESPACE_TOKENS};
108
use text_size::{TextRange, TextSize};
119

1210
use crate::syntax_error::SyntaxError;
1311

1412
/// Main parser that exposes the `cstree` api, and collects errors and statements
13+
/// It is modelled after a Pratt Parser. For a gentle introduction to Pratt Parsing, see https://matklad.github.io/2020/04/13/simple-but-powerful-pratt-parsing.html
1514
pub struct Parser {
1615
/// The ranges of the statements
1716
ranges: Vec<TextRange>,
@@ -53,7 +52,12 @@ impl Parser {
5352

5453
Self {
5554
ranges: Vec::new(),
56-
eof_token: Token::eof(usize::from(tokens.first().unwrap().span.end())),
55+
eof_token: Token::eof(usize::from(
56+
tokens
57+
.first()
58+
.map(|t| t.span.start())
59+
.unwrap_or(TextSize::from(0)),
60+
)),
5761
errors: Vec::new(),
5862
current_stmt_start: None,
5963
tokens,

crates/pg_statement_splitter/src/parser/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub(crate) fn statement(p: &mut Parser) {
5050
// delete(p);
5151
}
5252
t => {
53-
panic!("stmt: Unknown token {:?}", t);
53+
panic!("stmt: Unknown start token {:?}", t);
5454
// unknown(p);
5555
}
5656
}

crates/pg_statement_splitter/src/parser/data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use pg_lexer::SyntaxKind;
22

3-
pub static STATEMENT_START_TOKENS: &[SyntaxKind] = &[
3+
static STATEMENT_START_TOKENS: &[SyntaxKind] = &[
44
SyntaxKind::With,
55
SyntaxKind::Select,
66
SyntaxKind::Insert,

0 commit comments

Comments
 (0)