Skip to content

Commit 9022ea7

Browse files
committed
progress
1 parent 926b4fd commit 9022ea7

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

crates/pgt_statement_splitter/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ mod tests {
9292
assert_eq!(
9393
self.result.ranges.len(),
9494
expected.len(),
95-
"Expected {} statements for input {}, got {}: {:?}",
95+
"Expected {} statements for input\n{}\ngot {}:\n{:?}",
9696
expected.len(),
9797
self.input,
9898
self.result.ranges.len(),

crates/pgt_statement_splitter/src/splitter/common.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,17 @@ pub(crate) fn case(p: &mut Splitter) {
120120
}
121121

122122
pub(crate) fn unknown(p: &mut Splitter, exclude: &[SyntaxKind]) {
123+
let mut in_atomic = false;
123124
loop {
124125
match p.current() {
125126
SyntaxKind::SEMICOLON => {
127+
if in_atomic {
128+
// only end the statement if the next non-trivia token is not END
129+
// this is to handle cases like BEGIN ATOMIC SELECT ...; END;
130+
p.advance();
131+
break;
132+
}
126133
p.advance();
127-
break;
128134
}
129135
SyntaxKind::EOF => {
130136
break;
@@ -257,7 +263,6 @@ pub(crate) fn unknown(p: &mut Splitter, exclude: &[SyntaxKind]) {
257263
}
258264
p.advance();
259265
}
260-
261266
Some(SyntaxKind::CREATE_KW) => {
262267
let prev = p.look_back(true);
263268
if [
@@ -275,6 +280,17 @@ pub(crate) fn unknown(p: &mut Splitter, exclude: &[SyntaxKind]) {
275280

276281
p.advance();
277282
}
283+
Some(SyntaxKind::ATOMIC_KW) => {
284+
if p.look_back(true) == Some(SyntaxKind::BEGIN_KW) {
285+
// BEGIN ATOMIC ... END;
286+
in_atomic = true;
287+
}
288+
p.advance();
289+
}
290+
Some(SyntaxKind::END_KW) => {
291+
in_atomic = false;
292+
p.advance();
293+
}
278294
Some(_) => {
279295
break;
280296
}

0 commit comments

Comments
 (0)