Skip to content

Commit d04f690

Browse files
committed
Include location in error message
1 parent 56b8fe6 commit d04f690

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed

src/parser/mod.rs

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17229,20 +17229,24 @@ impl<'a> Parser<'a> {
1722917229

1723017230
self.expect_keyword_is(Keyword::THEN)?;
1723117231

17232+
macro_rules! not_allowed {
17233+
($action:literal, $not_allowed_in_clauses:pat) => {
17234+
if matches!(clause_kind, $not_allowed_in_clauses) {
17235+
return parser_err!(
17236+
format_args!(concat!($action, " is not allowed in a {} merge clause"), clause_kind),
17237+
self.get_current_token().span.start
17238+
);
17239+
}
17240+
};
17241+
}
1723217242
let merge_clause = match self.parse_one_of_keywords(&[
1723317243
Keyword::UPDATE,
1723417244
Keyword::INSERT,
1723517245
Keyword::DELETE,
1723617246
]) {
1723717247
Some(Keyword::UPDATE) => {
17238-
if matches!(
17239-
clause_kind,
17240-
MergeClauseKind::NotMatched | MergeClauseKind::NotMatchedByTarget
17241-
) {
17242-
return Err(ParserError::ParserError(format!(
17243-
"UPDATE is not allowed in a {clause_kind} merge clause"
17244-
)));
17245-
}
17248+
not_allowed!("UPDATE", MergeClauseKind::NotMatched | MergeClauseKind::NotMatchedByTarget);
17249+
1724617250
let update_token = self.get_current_token().clone();
1724717251
self.expect_keyword_is(Keyword::SET)?;
1724817252
MergeAction::Update {
@@ -17251,28 +17255,16 @@ impl<'a> Parser<'a> {
1725117255
}
1725217256
}
1725317257
Some(Keyword::DELETE) => {
17254-
if matches!(
17255-
clause_kind,
17256-
MergeClauseKind::NotMatched | MergeClauseKind::NotMatchedByTarget
17257-
) {
17258-
return Err(ParserError::ParserError(format!(
17259-
"DELETE is not allowed in a {clause_kind} merge clause"
17260-
)));
17261-
}
17258+
not_allowed!("DELETE", MergeClauseKind::NotMatched | MergeClauseKind::NotMatchedByTarget);
17259+
1726217260
let delete_token = self.get_current_token().clone();
1726317261
MergeAction::Delete {
1726417262
delete_token: delete_token.into(),
1726517263
}
1726617264
}
1726717265
Some(Keyword::INSERT) => {
17268-
if !matches!(
17269-
clause_kind,
17270-
MergeClauseKind::NotMatched | MergeClauseKind::NotMatchedByTarget
17271-
) {
17272-
return Err(ParserError::ParserError(format!(
17273-
"INSERT is not allowed in a {clause_kind} merge clause"
17274-
)));
17275-
}
17266+
not_allowed!("INSERT", MergeClauseKind::Matched | MergeClauseKind::NotMatchedBySource);
17267+
1727617268
let insert_token = self.get_current_token().clone();
1727717269
let is_mysql = dialect_of!(self is MySqlDialect);
1727817270

0 commit comments

Comments
 (0)