Skip to content

Commit 33979fb

Browse files
committed
Add documentation, use display_separated, rename Exception
1 parent f69e0d9 commit 33979fb

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

src/ast/mod.rs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2989,12 +2989,23 @@ impl From<Set> for Statement {
29892989
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
29902990
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
29912991
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2992-
pub struct Exception {
2992+
pub struct ExceptionClause {
2993+
/// When represents each `WHEN` case
29932994
pub when: Vec<ExceptionWhen>,
2995+
/// The exception that is being raised or the current exception being handled if `None`.
2996+
///
2997+
/// Example
2998+
/// RAISE;
2999+
/// RAISE MY_EXCEPTION;
3000+
/// RAISE USING MESSAGE = "Some error";
3001+
///
3002+
/// BigQuery: https://cloud.google.com/bigquery/docs/reference/standard-sql/procedural-language#raise
3003+
/// Snowflake: <https://docs.snowflake.com/en/sql-reference/snowflake-scripting/raise>
3004+
// pub raises: Option<Option<Ident>>,
29943005
pub raises: Option<Box<Statement>>,
29953006
}
29963007

2997-
impl Display for Exception {
3008+
impl Display for ExceptionClause {
29983009
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
29993010
write!(f, " EXCEPTION")?;
30003011
for w in &self.when {
@@ -3011,6 +3022,9 @@ impl Display for Exception {
30113022

30123023
/// A representation of a `WHEN` arm with all the identifiers catched and the statements to execute
30133024
/// for the arm.
3025+
///
3026+
/// Snowflake: <https://docs.snowflake.com/en/sql-reference/snowflake-scripting/exception>
3027+
/// BigQuery: <https://cloud.google.com/bigquery/docs/reference/standard-sql/procedural-language#beginexceptionend>
30143028
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
30153029
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
30163030
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
@@ -3021,14 +3035,11 @@ pub struct ExceptionWhen {
30213035

30223036
impl Display for ExceptionWhen {
30233037
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3024-
let idents = self
3025-
.idents
3026-
.iter()
3027-
.map(ToString::to_string)
3028-
.collect::<Vec<_>>()
3029-
.join(" OR ");
3030-
3031-
write!(f, " WHEN {idents} THEN", idents = idents)?;
3038+
write!(
3039+
f,
3040+
" WHEN {idents} THEN",
3041+
idents = display_separated(&self.idents, " OR ")
3042+
)?;
30323043

30333044
if !self.statements.is_empty() {
30343045
write!(f, " ")?;
@@ -3744,7 +3755,7 @@ pub enum Statement {
37443755
/// ```
37453756
/// <https://cloud.google.com/bigquery/docs/reference/standard-sql/procedural-language#beginexceptionend>
37463757
/// <https://docs.snowflake.com/en/sql-reference/snowflake-scripting/exception>
3747-
exception: Option<Exception>,
3758+
exception: Option<ExceptionClause>,
37483759
/// TRUE if the statement has an `END` keyword.
37493760
has_end_keyword: bool,
37503761
},

src/parser/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15177,7 +15177,7 @@ impl<'a> Parser<'a> {
1517715177
None
1517815178
};
1517915179

15180-
Some(Exception { when, raises })
15180+
Some(ExceptionClause { when, raises })
1518115181
} else {
1518215182
None
1518315183
};

0 commit comments

Comments
 (0)