Skip to content

Commit 993b37b

Browse files
authored
parser: add more nodes for merge into (#687)
1 parent 0d0af59 commit 993b37b

File tree

9 files changed

+1469
-858
lines changed

9 files changed

+1469
-858
lines changed

crates/squawk_ide/src/expand_selection.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -547,19 +547,18 @@ $0
547547
SyntaxKind::WHEN_CLAUSE_LIST,
548548
];
549549

550-
let generated_list_kinds: Vec<SyntaxKind> = (0..SyntaxKind::__LAST as u16)
550+
let unhandled_list_kinds = (0..SyntaxKind::__LAST as u16)
551551
.map(SyntaxKind::from)
552552
.filter(|kind| {
553553
format!("{:?}", kind).ends_with("_LIST") && !delimited_ws_list_kinds.contains(kind)
554554
})
555-
.collect();
556-
557-
let diff: Vec<SyntaxKind> = generated_list_kinds
558-
.iter()
559555
.filter(|kind| !DELIMITED_LIST_KINDS.contains(kind))
560-
.copied()
561-
.collect();
556+
.collect::<Vec<_>>();
562557

563-
assert_eq!(diff, vec![], "We shouldn't have any unhandled list kinds")
558+
assert_eq!(
559+
unhandled_list_kinds,
560+
vec![],
561+
"We shouldn't have any unhandled list kinds"
562+
)
564563
}
565564
}

crates/squawk_parser/src/generated/syntax_kind.rs

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/squawk_parser/src/grammar.rs

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10261,39 +10261,60 @@ fn merge(p: &mut Parser<'_>, m: Option<Marker>) -> CompletedMarker {
1026110261
// and merge_delete is:
1026210262
// DELETE
1026310263
fn merge_when_clause(p: &mut Parser<'_>) {
10264+
let m = p.start();
1026410265
p.expect(WHEN_KW);
10265-
match p.current() {
10266+
let kind = match p.current() {
1026610267
MATCHED_KW => {
1026710268
p.bump(MATCHED_KW);
10269+
MERGE_WHEN_MATCHED
1026810270
}
1026910271
NOT_KW => {
1027010272
p.bump(NOT_KW);
1027110273
p.expect(MATCHED_KW);
10272-
// TODO: need a validation to check these
1027310274
// BY SOURCE | BY TARGET
1027410275
if p.eat(BY_KW) {
10275-
let _ = p.eat(SOURCE_KW) || p.eat(TARGET_KW);
10276+
if p.eat(SOURCE_KW) {
10277+
MERGE_WHEN_NOT_MATCHED_SOURCE
10278+
} else if p.eat(TARGET_KW) {
10279+
MERGE_WHEN_NOT_MATCHED_TARGET
10280+
} else {
10281+
p.error("expected SOURCE or TARGET");
10282+
MERGE_WHEN_NOT_MATCHED_TARGET
10283+
}
10284+
} else {
10285+
MERGE_WHEN_NOT_MATCHED_TARGET
1027610286
}
1027710287
}
10278-
_ => p.error("expected MATCHED, or NOT MATCHED"),
10279-
}
10288+
_ => {
10289+
p.error("expected MATCHED, or NOT MATCHED");
10290+
MERGE_WHEN_NOT_MATCHED_TARGET
10291+
}
10292+
};
1028010293
// [ AND condition ]
1028110294
if p.eat(AND_KW) {
1028210295
if expr(p).is_none() {
1028310296
p.error("expected condition");
1028410297
}
1028510298
}
1028610299
p.expect(THEN_KW);
10287-
// merge_update | merge_delete | merge_insert | DO NOTHING
10288-
match p.current() {
10300+
merge_action(p);
10301+
m.complete(p, kind);
10302+
}
10303+
10304+
// merge_update | merge_delete | merge_insert | DO NOTHING
10305+
fn merge_action(p: &mut Parser<'_>) {
10306+
let m = p.start();
10307+
let kind = match p.current() {
1028910308
// merge_delete
1029010309
DELETE_KW => {
1029110310
p.bump(DELETE_KW);
10311+
MERGE_DELETE
1029210312
}
1029310313
// merge_update
1029410314
UPDATE_KW => {
1029510315
p.bump(UPDATE_KW);
1029610316
set_clause(p);
10317+
MERGE_UPDATE
1029710318
}
1029810319
// merge_insert
1029910320
INSERT_KW => {
@@ -10315,14 +10336,20 @@ fn merge_when_clause(p: &mut Parser<'_>) {
1031510336
} else {
1031610337
p.error("expected VALUES or DEFAULT VALUES");
1031710338
}
10339+
MERGE_INSERT
1031810340
}
1031910341
// DO NOTHING
1032010342
DO_KW => {
1032110343
p.bump(DO_KW);
1032210344
p.expect(NOTHING_KW);
10345+
MERGE_DO_NOTHING
1032310346
}
10324-
_ => p.error("expected INSERT, UPDATE, DELETE, or DO NOTHING"),
10325-
}
10347+
_ => {
10348+
p.error("expected INSERT, UPDATE, DELETE, or DO NOTHING");
10349+
MERGE_DO_NOTHING
10350+
}
10351+
};
10352+
m.complete(p, kind);
1032610353
}
1032710354

1032810355
// REASSIGN OWNED BY { old_role | CURRENT_ROLE | CURRENT_USER | SESSION_USER } [, ...]

0 commit comments

Comments
 (0)